javax.constraints.impl.search.goal
Class SolverWithGoals

java.lang.Object
  extended by javax.constraints.impl.search.AbstractSolver
      extended by javax.constraints.impl.search.goal.SolverWithGoals
All Implemented Interfaces:
Solver

public abstract class SolverWithGoals
extends AbstractSolver


Constructor Summary
SolverWithGoals(Problem problem)
           
 
Method Summary
abstract  Goal and(Goal g1, Goal g2)
          Returns an "AND" Goal.
 boolean applySolution(Solution solution)
          This method tries to resolve the problem by applying the Solution "solution" to the problem, and returns true if "solution" satisfies all of the posted constraints, false otherwise.
abstract  void backtrack()
          This method forces a solver to "backtrack".
 Goal combineSearchStrategies()
           
 boolean execute(Goal goal)
          This methods is equivalent to execute(goal,ProblemState.DO_NOT_RESTORE);
abstract  boolean execute(Goal goal, ProblemState restoreOrNot)
           
 Solution[] findAllSolutions()
          This method attempts to find all solutions for the Problem.
 Solution findOptimalSolutionDichotomize(Objective objective, Var objectiveVar)
          The actual minimization algorithm executes a dichotomized search.
 Solution findSolution(ProblemState restoreOrNot)
          This method attempts to find a solution of the problem, for which the solver was defined.
abstract  java.lang.Object goalThis(Goal goal)
          To create a new goal on the javax.constraints level without necessity to go down to the underlying CP solver, one needs to use a goal that will serve as an implementation object.
 Goal goalVarEqValue(Var var, int value)
           
 Goal goalVarGeValue(Var var, int value)
           
 Goal goalVarLeValue(Var var, int value)
           
 Goal goalVarNeqValue(Var var, int value)
           
 Goal makeGoal(SearchStrategy strategy)
           
 SearchStrategy newSearchStrategy()
          This methods returns a new default search strategy
abstract  Goal or(Goal g1, Goal g2)
          Returns an "OR" Goal.
 void trace(Var var)
          This method forces to trace (to log) all modification events for the variable "var".
 void trace(Var[] vars)
          This method forces to trace (to log) all modification events for all variables "vars"
 void trace(Var[] vars, PropagationEvent event)
          This method forces solver to trace (to log) the modification "event" for all variables "var".
 void trace(Var var, PropagationEvent event)
          This method forces to trace (to log) the modification "event" for the variable "var".
 void trace(VarSet setVar)
          This method forces to trace (to log) all modification events for the variable "setVar".
 void trace(VarSet setVar, PropagationEvent event)
          This method forces to trace (to log) the modification "event" for the variable "setVar".
 
Methods inherited from class javax.constraints.impl.search.AbstractSolver
addReversibleAction, addSearchStrategy, addSearchStrategy, addSearchStrategy, addSearchStrategy, addSearchStrategy, addSearchStrategy, addSearchStrategy, addSearchStrategy, addSearchStrategy, addSolution, addStrategyLogVariables, applySolution, checkTimeLimit, clearSolutions, findOptimalSolution, findOptimalSolution, findOptimalSolution, findOptimalSolutionBasic, findOptimalSolutionDichotomize, findSolution, getMaxNumberOfSolutions, getNumberOfSolutions, getOptimizationTolerance, getProblem, getSearchStrategies, getSearchStrategy, getSolution, getSolution, getSolutions, getSolverStartTime, getStrategyLogVariables, getTimeLimit, getTimeLimitGlobal, getTimeLimitStart, isTimeLimitExceeded, isTraceExecution, isTraceSolutions, log, logStats, restoreProblem, saveProblem, setMaxNumberOfSolutions, setOptimizationTolerance, setProblem, setSearchStrategy, setSearchStrategy, setSearchStrategy, setSearchStrategy, setSearchStrategy, setSolverStartTime, setTimeLimit, setTimeLimitExceeded, setTimeLimitGlobal, setTimeLimitStart, solutionIterator, traceExecution, traceFailures, traceSolutions
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SolverWithGoals

public SolverWithGoals(Problem problem)
Method Detail

and

public abstract Goal and(Goal g1,
                         Goal g2)
Returns an "AND" Goal. The Goal "AND" succeeds if both of the Goals "g1" and "g2" succeed. The Goal "AND" fails if at least one of the Goals "g1" or "g2" fail. It is implementation specific.

Parameters:
g1 - the first Goal which is part of the new "AND" Goal.
g2 - the other Goal which is part of the new "AND" Goal.
Returns:
a Goal "AND" between the Goals "g1" and "g2".

applySolution

public boolean applySolution(Solution solution)
This method tries to resolve the problem by applying the Solution "solution" to the problem, and returns true if "solution" satisfies all of the posted constraints, false otherwise.

Specified by:
applySolution in class AbstractSolver
Parameters:
solution - the Solution object being tested on the problem.
Returns:
true if the Solution satisfies all posted constraints, false otherwise.

backtrack

public abstract void backtrack()
                        throws java.lang.Exception
This method forces a solver to "backtrack". It is used to emulate a failure, e.g. to produce all solutions.

Throws:
java.lang.Exception

combineSearchStrategies

public Goal combineSearchStrategies()

execute

public boolean execute(Goal goal)
This methods is equivalent to execute(goal,ProblemState.DO_NOT_RESTORE);

Parameters:
goal -
Returns:
true if the goal execution succeeds or false if it fails.

execute

public abstract boolean execute(Goal goal,
                                ProblemState restoreOrNot)

findAllSolutions

public Solution[] findAllSolutions()
This method attempts to find all solutions for the Problem. It uses the default search strategy or the strategy defined by the latest method setSearchStrategy(). It returns an array of found solutions or null if there are no solutions. A user has to be careful not to overload the available memory because the number of found solutions could be huge. The process of finding all solutions can be also controlled by: The common implementation is based on the SolutionIterator.

Specified by:
findAllSolutions in interface Solver
Overrides:
findAllSolutions in class AbstractSolver
Returns:
Solution[]

findOptimalSolutionDichotomize

public Solution findOptimalSolutionDichotomize(Objective objective,
                                               Var objectiveVar)
The actual minimization algorithm executes a dichotomized search. During the search it modifies an interval [objectiveMin; objectiveMax]. First it is trying to find a solution in the [objectiveMin; objectiveMid]. If it fails, it is looking at [objectiveMid+1; objectiveMax]. During this process it switches the search target: one time in looks at in the upper half of the selected interval, another time - to the lower half. Successful search stops when objectiveMax - objectiveMin <= tolerance.

Overrides:
findOptimalSolutionDichotomize in class AbstractSolver

findSolution

public Solution findSolution(ProblemState restoreOrNot)
This method attempts to find a solution of the problem, for which the solver was defined. It uses the search strategy defined by the method setSearchStrategy(). It returns the found solution (if any) or null. It also saves the solution and makes it available through the method getSolution(). If a solution is not found, the problem state is restored to that of before the invocation of this method. If a solution is found, the problem state will be restored only if the parameter "restore" is true. Otherwise all problem variables will be instantiated with the solution values. The search can be limited by time, number of failed attempts, etc.

Specified by:
findSolution in interface Solver
Specified by:
findSolution in class AbstractSolver
Parameters:
restoreOrNot - defines if the problem state should be restored after a solution is found
Returns:
a Solution if the search is successful or null

goalThis

public abstract java.lang.Object goalThis(Goal goal)
To create a new goal on the javax.constraints level without necessity to go down to the underlying CP solver, one needs to use a goal that will serve as an implementation object. "goalThis" serves exactly these purposes and actually executes the method execute() from the Goal passed as a parameter.

Parameters:
goal -

goalVarEqValue

public Goal goalVarEqValue(Var var,
                           int value)

goalVarGeValue

public Goal goalVarGeValue(Var var,
                           int value)

goalVarLeValue

public Goal goalVarLeValue(Var var,
                           int value)

goalVarNeqValue

public Goal goalVarNeqValue(Var var,
                            int value)

makeGoal

public Goal makeGoal(SearchStrategy strategy)

newSearchStrategy

public SearchStrategy newSearchStrategy()
This methods returns a new default search strategy

Specified by:
newSearchStrategy in interface Solver
Specified by:
newSearchStrategy in class AbstractSolver
Returns:
a new default search strategy

or

public abstract Goal or(Goal g1,
                        Goal g2)
Returns an "OR" Goal. The goal "OR" succeeds if at least one of the Goals "g1" or "g2" succeeds. The Goal "OR" fails if both Goals "g1" and "g2" fail. It is implementation specific.

Parameters:
g1 - the first Goal which is part of the new "OR" Goal.
g2 - the second Goal which is part of the new "OR" Goal.
Returns:
a Goal "OR" between the Goals "g1" and "g2".

trace

public void trace(Var var)
This method forces to trace (to log) all modification events for the variable "var". All modification events are described at the interface Problem

Parameters:
var -

trace

public void trace(Var[] vars)
This method forces to trace (to log) all modification events for all variables "vars"

Parameters:
vars -

trace

public void trace(Var[] vars,
                  PropagationEvent event)
This method forces solver to trace (to log) the modification "event" for all variables "var". All modification events are described at the interface Problem

Parameters:
vars -
event -

trace

public void trace(Var var,
                  PropagationEvent event)
This method forces to trace (to log) the modification "event" for the variable "var". All modification events are described at the interface Problem

Parameters:
var -

trace

public void trace(VarSet setVar)
This method forces to trace (to log) all modification events for the variable "setVar".

Parameters:
setVar -

trace

public void trace(VarSet setVar,
                  PropagationEvent event)
This method forces to trace (to log) the modification "event" for the variable "setVar". All modification events are described at the interface Problem

Parameters:
setVar -
event -