jopt.csp.solution
Class SolverSolution

java.lang.Object
  extended byjopt.csp.solution.SolutionScope
      extended byjopt.csp.solution.SolverSolution

public class SolverSolution
extends SolutionScope

Implementation of a solution that is produced by a solver


Constructor Summary
SolverSolution()
          Creates a new solution with no variables defined within the scope.
SolverSolution(SolutionScope scope)
          Creates a new solution for the scope requested
 
Method Summary
 BooleanSolution add(CspBooleanVariable var)
          Adds a boolean variable solution
 DoubleSolution add(CspDoubleVariable var)
          Adds a double variable solution
 FloatSolution add(CspFloatVariable var)
          Adds a float variable solution
 IntSolution add(CspIntVariable var)
          Adds an integer variable solution
 LongSolution add(CspLongVariable var)
          Adds a long variable solution
 SetSolution add(CspSetVariable var)
          Adds a set variable solution
 void add(CspVariable var)
          Adds a variable to record in a solution
 void clear(CspBooleanVariable var)
          Clears the isTrue / isFalse flag and sets variable to an unbound state
 void copy(SolverSolution sol)
          Copies all data in one solution over the data in this solution.
static SolverSolution createNeighbor(SolverSolution initial, SolverSolution result)
          Creates a neighboring solution that will produce a resulting solution from an initial solution
 float getFloatObjectiveVal()
          Returns objective value as an integer type
 int getIntObjectiveVal()
          Returns objective value as an integer type
 long getLongObjectiveVal()
          Returns objective value as a long type
 double getMax(CspDoubleVariable var)
          Retrieves maximum value of solution for the specified variable
 float getMax(CspFloatVariable var)
          Retrieves maximum value of solution for the specified variable
 int getMax(CspIntVariable var)
          Retrieves maximum value of solution
 long getMax(CspLongVariable var)
          Retrieves maximum value of solution for the specified variable
 double getMin(CspDoubleVariable var)
          Retrieves minimum value of solution for the specified variable
 float getMin(CspFloatVariable var)
          Retrieves minimum value of solution for the specified variable
 int getMin(CspIntVariable var)
          Retrieves minimum value of solution
 long getMin(CspLongVariable var)
          Retrieves minimum value of solution for the specified variable
 double getObjectiveVal()
          Returns the value stored for this solution's objective expression
 java.util.Set getPossibleSet(CspSetVariable var)
          Returns the set of possible values for the variable
 java.util.Set getRequiredSet(CspSetVariable var)
          Returns the set of required values for the variable
 BooleanSolution getSolution(CspBooleanVariable var)
          Returns a stored solution for a boolean variable
 DoubleSolution getSolution(CspDoubleVariable var)
          Returns a stored solution for a double variable
 FloatSolution getSolution(CspFloatVariable var)
          Returns a stored solution for a float variable
 IntSolution getSolution(CspIntVariable var)
          Returns a stored solution for an integer variable
 LongSolution getSolution(CspLongVariable var)
          Returns a stored solution for a long variable
 SetSolution getSolution(CspSetVariable var)
          Returns a stored solution for a set variable
 VariableSolution getSolution(CspVariable var)
          Returns a stored solution for a variable
 double getValue(CspDoubleVariable var)
          Returns the value of the solution.
 float getValue(CspFloatVariable var)
          Returns the value of the solution.
 int getValue(CspIntVariable var)
          Returns the value of the solution for the specified variable.
 long getValue(CspLongVariable var)
          Returns the value of the solution.
 boolean isBound(CspIntVariable var)
          Returns true if variable is bound in this SolverSolution
 boolean isDifferent(SolverSolution neighbor)
          Returns true if any of the variables in the specified SolverSolution differ from those contained in this SolverSolution object
 boolean isFalse(CspBooleanVariable var)
          Returns true if boolean variable is NOT satisfied in solution
 boolean isRestorable(CspVariable var)
          Returns true if the state of a variable contained within this solution will be restored when the solution is restored
 boolean isTrue(CspBooleanVariable var)
          Returns true if boolean variable is satisfied in solution
 void recalcStatistics()
          Recalculates any internal stats that are stored with the solution
 void remove(CspVariable var)
          Removes a variable from the scope of a solution request
 void setFalse(CspBooleanVariable var)
          Sets the value of the specified variable to false
 void setMax(CspDoubleVariable var, double max)
          Sets maximum value of solution for the specified variable
 void setMax(CspFloatVariable var, float max)
          Sets maximum value of solution for the specified variable
 void setMax(CspIntVariable var, int max)
          Sets maximum value of solution for the specified variable
 void setMax(CspLongVariable var, long max)
          Sets maximum value of solution for the specified variable
 void setMaximizeObjective(CspNumExpr expr)
          Sets an objective to maximize the specified expression
 void setMin(CspDoubleVariable var, double min)
          Sets minimum value of solution for the specified variable
 void setMin(CspFloatVariable var, float min)
          Sets minimum value of solution for the specified variable
 void setMin(CspIntVariable var, int min)
          Sets minimum value of solution for the specified variable
 void setMin(CspLongVariable var, long min)
          Sets minimum value of solution for the specified variable
 void setMinimizeObjective(CspNumExpr expr)
          Sets an objective to minimize the specified expression
 void setObjectiveVal(double num)
          Sets the value stored for this solution's objective expression
 void setPossibleSet(CspSetVariable var, java.util.Set possibleSet)
          Sets the set of possible values for the variable
 void setRequiredSet(CspSetVariable var, java.util.Set requiredSet)
          Sets the set of required values for the variable
 void setRestorable(CspVariable var, boolean restore)
          True if a variable contained within this solution is to be restored when the solution is restored
 void setTrue(CspBooleanVariable var)
          Sets the value of the specified variable to true
 void setValue(CspDoubleVariable var, double val)
          Sets both the min / max value of solution to a single value
 void setValue(CspFloatVariable var, float val)
          Sets both the min / max value of solution to a single value
 void setValue(CspIntVariable var, int val)
          Sets both the min / max value of solution to a single value
 void setValue(CspLongVariable var, long val)
          Sets both the min / max value of solution to a single value
 java.lang.String toString()
           
 
Methods inherited from class jopt.csp.solution.SolutionScope
add, clearObjective, contains, getDoubleObjectiveExpression, getFloatObjectiveExpression, getIntObjectiveExpression, getLongObjectiveExpression, getObjectiveExpression, isMaximizeObjective, isMinimizeObjective, variables
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SolverSolution

public SolverSolution(SolutionScope scope)
Creates a new solution for the scope requested

Parameters:
scope - Scope of variables to include within solution

SolverSolution

public SolverSolution()
Creates a new solution with no variables defined within the scope. Variables will need to be added with the add method.

Method Detail

copy

public void copy(SolverSolution sol)
Copies all data in one solution over the data in this solution. This data includes both variable- and objective-based information.


add

public void add(CspVariable var)
Description copied from class: SolutionScope
Adds a variable to record in a solution

Overrides:
add in class SolutionScope

add

public IntSolution add(CspIntVariable var)
Adds an integer variable solution

Returns:
Solution stored for variable

add

public LongSolution add(CspLongVariable var)
Adds a long variable solution

Returns:
Solution stored for variable

add

public FloatSolution add(CspFloatVariable var)
Adds a float variable solution

Returns:
Solution stored for variable

add

public DoubleSolution add(CspDoubleVariable var)
Adds a double variable solution

Returns:
Solution stored for variable

add

public BooleanSolution add(CspBooleanVariable var)
Adds a boolean variable solution

Returns:
Solution stored for variable

add

public SetSolution add(CspSetVariable var)
Adds a set variable solution

Returns:
Solution stored for variable

remove

public void remove(CspVariable var)
Description copied from class: SolutionScope
Removes a variable from the scope of a solution request

Overrides:
remove in class SolutionScope

getSolution

public IntSolution getSolution(CspIntVariable var)
Returns a stored solution for an integer variable


getSolution

public LongSolution getSolution(CspLongVariable var)
Returns a stored solution for a long variable


getSolution

public FloatSolution getSolution(CspFloatVariable var)
Returns a stored solution for a float variable


getSolution

public DoubleSolution getSolution(CspDoubleVariable var)
Returns a stored solution for a double variable


getSolution

public SetSolution getSolution(CspSetVariable var)
Returns a stored solution for a set variable


getSolution

public BooleanSolution getSolution(CspBooleanVariable var)
Returns a stored solution for a boolean variable


getSolution

public VariableSolution getSolution(CspVariable var)
Returns a stored solution for a variable


isRestorable

public boolean isRestorable(CspVariable var)
Returns true if the state of a variable contained within this solution will be restored when the solution is restored


setRestorable

public void setRestorable(CspVariable var,
                          boolean restore)
True if a variable contained within this solution is to be restored when the solution is restored


toString

public java.lang.String toString()

isBound

public boolean isBound(CspIntVariable var)
Returns true if variable is bound in this SolverSolution


getMin

public int getMin(CspIntVariable var)
Retrieves minimum value of solution


getMax

public int getMax(CspIntVariable var)
Retrieves maximum value of solution


getValue

public int getValue(CspIntVariable var)
Returns the value of the solution for the specified variable. This function will throw an exception if the variable is not already bound.


setMin

public void setMin(CspIntVariable var,
                   int min)
Sets minimum value of solution for the specified variable


setMax

public void setMax(CspIntVariable var,
                   int max)
Sets maximum value of solution for the specified variable


setValue

public void setValue(CspIntVariable var,
                     int val)
Sets both the min / max value of solution to a single value


getMin

public long getMin(CspLongVariable var)
Retrieves minimum value of solution for the specified variable


getMax

public long getMax(CspLongVariable var)
Retrieves maximum value of solution for the specified variable


getValue

public long getValue(CspLongVariable var)
Returns the value of the solution. This function will throw an exception if the variable is not already bound.


setMin

public void setMin(CspLongVariable var,
                   long min)
Sets minimum value of solution for the specified variable


setMax

public void setMax(CspLongVariable var,
                   long max)
Sets maximum value of solution for the specified variable


setValue

public void setValue(CspLongVariable var,
                     long val)
Sets both the min / max value of solution to a single value


getMin

public float getMin(CspFloatVariable var)
Retrieves minimum value of solution for the specified variable


getMax

public float getMax(CspFloatVariable var)
Retrieves maximum value of solution for the specified variable


getValue

public float getValue(CspFloatVariable var)
Returns the value of the solution. This function will throw an exception if the variable is not already bound.


setMin

public void setMin(CspFloatVariable var,
                   float min)
Sets minimum value of solution for the specified variable


setMax

public void setMax(CspFloatVariable var,
                   float max)
Sets maximum value of solution for the specified variable


setValue

public void setValue(CspFloatVariable var,
                     float val)
Sets both the min / max value of solution to a single value


getMin

public double getMin(CspDoubleVariable var)
Retrieves minimum value of solution for the specified variable


getMax

public double getMax(CspDoubleVariable var)
Retrieves maximum value of solution for the specified variable


getValue

public double getValue(CspDoubleVariable var)
Returns the value of the solution. This function will throw an exception if the variable is not already bound.


setMin

public void setMin(CspDoubleVariable var,
                   double min)
Sets minimum value of solution for the specified variable


setMax

public void setMax(CspDoubleVariable var,
                   double max)
Sets maximum value of solution for the specified variable


setValue

public void setValue(CspDoubleVariable var,
                     double val)
Sets both the min / max value of solution to a single value


isFalse

public boolean isFalse(CspBooleanVariable var)
Returns true if boolean variable is NOT satisfied in solution


isTrue

public boolean isTrue(CspBooleanVariable var)
Returns true if boolean variable is satisfied in solution


setTrue

public void setTrue(CspBooleanVariable var)
Sets the value of the specified variable to true


setFalse

public void setFalse(CspBooleanVariable var)
Sets the value of the specified variable to false


clear

public void clear(CspBooleanVariable var)
Clears the isTrue / isFalse flag and sets variable to an unbound state


getPossibleSet

public java.util.Set getPossibleSet(CspSetVariable var)
Returns the set of possible values for the variable


getRequiredSet

public java.util.Set getRequiredSet(CspSetVariable var)
Returns the set of required values for the variable


setPossibleSet

public void setPossibleSet(CspSetVariable var,
                           java.util.Set possibleSet)
Sets the set of possible values for the variable


setRequiredSet

public void setRequiredSet(CspSetVariable var,
                           java.util.Set requiredSet)
Sets the set of required values for the variable


getObjectiveVal

public double getObjectiveVal()
Returns the value stored for this solution's objective expression


setObjectiveVal

public void setObjectiveVal(double num)
Sets the value stored for this solution's objective expression


getIntObjectiveVal

public int getIntObjectiveVal()
Returns objective value as an integer type


getLongObjectiveVal

public long getLongObjectiveVal()
Returns objective value as a long type


getFloatObjectiveVal

public float getFloatObjectiveVal()
Returns objective value as an integer type


setMinimizeObjective

public void setMinimizeObjective(CspNumExpr expr)
Sets an objective to minimize the specified expression

Overrides:
setMinimizeObjective in class SolutionScope
Parameters:
expr - Expression that is to be minimized

setMaximizeObjective

public void setMaximizeObjective(CspNumExpr expr)
Sets an objective to maximize the specified expression

Overrides:
setMaximizeObjective in class SolutionScope
Parameters:
expr - Expression that is to be maximized

isDifferent

public boolean isDifferent(SolverSolution neighbor)
Returns true if any of the variables in the specified SolverSolution differ from those contained in this SolverSolution object

Parameters:
neighbor - The SolverSolution to which this solution is compared
Returns:
A boolean indicating whether or not the specified solution is different from this one

createNeighbor

public static SolverSolution createNeighbor(SolverSolution initial,
                                            SolverSolution result)
Creates a neighboring solution that will produce a resulting solution from an initial solution

Parameters:
initial - Solution neighbor will be relative to
result - Solution that will be produced when neighbor is applied to initial solution
Returns:
Neighboring solution that will convert initial to result

recalcStatistics

public void recalcStatistics()
Recalculates any internal stats that are stored with the solution