Package org.jacop.search
Class SimpleSolutionListener<T extends Var>
java.lang.Object
org.jacop.search.SimpleSolutionListener<T>
- Type Parameters:
T- type of variable being used in search.
- All Implemented Interfaces:
SolutionListener<T>
- Direct Known Subclasses:
CPvizNetworkFlow.NetListener,CrossWord.PrintListener,OneSolution,Optimize.ResultListener,PrintOutListener,RestartSearch.CostListener,SimpleImprovementSearch.CostListener,Solve.CostListener,WordGame.PrintListener
It defines a simple solution listener which should be used if some basic
functionality of search when a solution is encountered are required.
- Version:
- 4.10
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) booleanIt contains children of the solution listener.private static final booleanIt specifies if the debugging information should be printed.protected intSolutionListener<? extends Var> If this search is a slave search than each solution within this search must be connected to a solution of the master search.int[]If this search is a slave search than each solution within this search must be connected to a solution of the master search.(package private) booleanintIt specifies the number of solutions we want to find.Domain[][]T[]It is executed right after consistency of the current search node. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanassignSolution(Store store) It assigns the last found solution to the store.booleanassignSolution(Store store, int number) It imposes the constraints, so the last found solution is enforced.booleanexecuteAfterSolution(Search<T> search, SelectChoicePoint<T> select) It is executed by search after a solution is found.intfindSolutionMatchingParent(int parentNo) For a given master solution finds any solution within that listener which matches the master solution.intgetParentSolution(int childSolutionNo) Domain[]getSolution(int no) It returns the solution number no.Domain[][]It returns all solutions.T[]It returns null if no solution was recorded, or the variables for which the solution(s) was recorded.booleanIt specifies if the solution listener is recording solutions or not.voidIt prints all the solutions.voidIt records a solution.voidrecordSolutions(boolean status) It records all solutions so they can be later retrieved and used.It returns a collection of constraints which represent the last found solution.returnSolution(int number) It returns the solution with the given number (value 0 denotes the first solution) as a set of primitive constraints.voidsearchAll(boolean status) It searches for all solutions, but they do not have to be recorded as this is decided by another parameter.voidsetChildrenListeners(SolutionListener<T> child) It sets the child listener for this solution listener.voidsetChildrenListeners(SolutionListener<T>[] children) It sets the children listeners for this solution listener.voidsetParentSolutionListener(SolutionListener<? extends Var> parent) It allows to inform sub-search of what is the current number of the solution in master search.voidsetSolutionLimit(int limit) It sets the solution limit.voidsetSolutionsNo(int no) voidsetVariables(T[] vs) booleanIt checks if the sufficient number of solutions was found.intIt returns number of solutions found while using this choice point selector.toString()It returns the string representation of the last solution.
-
Field Details
-
debug
private static final boolean debugIt specifies if the debugging information should be printed.- See Also:
-
vars
It is executed right after consistency of the current search node. The return code specifies if the search should continue or exit. -
alwaysUpdateToMostRecentSolution
boolean alwaysUpdateToMostRecentSolution -
solutionLimit
public int solutionLimitIt specifies the number of solutions we want to find. -
noSolutions
protected int noSolutions -
recordSolutions
boolean recordSolutions -
solutions
-
parentSolutionListener
If this search is a slave search than each solution within this search must be connected to a solution of the master search. The parentSolutionListener is a solution listener of the master search. -
parentSolutionNo
public int[] parentSolutionNoIf this search is a slave search than each solution within this search must be connected to a solution of the master search. This array stores for each solution recorded by this solution listener the solution number of the master slave. -
childrenSolutionListeners
It contains children of the solution listener.
-
-
Constructor Details
-
SimpleSolutionListener
public SimpleSolutionListener()
-
-
Method Details
-
getVariables
It returns null if no solution was recorded, or the variables for which the solution(s) was recorded.- Specified by:
getVariablesin interfaceSolutionListener<T extends Var>- Returns:
- list of variables
-
solutionLimitReached
public boolean solutionLimitReached()Description copied from interface:SolutionListenerIt checks if the sufficient number of solutions was found.- Specified by:
solutionLimitReachedin interfaceSolutionListener<T extends Var>- Returns:
- true if the limit of found solutions has been reached.
-
setSolutionLimit
public void setSolutionLimit(int limit) Description copied from interface:SolutionListenerIt sets the solution limit.- Specified by:
setSolutionLimitin interfaceSolutionListener<T extends Var>- Parameters:
limit- the maximal number of solutions we are interested in.
-
setParentSolutionListener
Description copied from interface:SolutionListenerIt allows to inform sub-search of what is the current number of the solution in master search.- Specified by:
setParentSolutionListenerin interfaceSolutionListener<T extends Var>- Parameters:
parent- solution listener used by a master search.
-
getSolutions
Description copied from interface:SolutionListenerIt returns all solutions. Each solution is in a separate array.- Specified by:
getSolutionsin interfaceSolutionListener<T extends Var>- Returns:
- first dimension is indexed by solution, second dimension is indexed by a variable.
-
getSolution
It returns the solution number no. The first solution has an index 1.- Specified by:
getSolutionin interfaceSolutionListener<T extends Var>- Parameters:
no- it obtains the solution with a given index.- Returns:
- array containing assignments to search variables.
-
solutionsNo
public int solutionsNo()It returns number of solutions found while using this choice point selector.- Specified by:
solutionsNoin interfaceSolutionListener<T extends Var>- Returns:
- the number of solutions.
-
setSolutionsNo
public void setSolutionsNo(int no) -
recordSolutions
public void recordSolutions(boolean status) It records all solutions so they can be later retrieved and used.- Specified by:
recordSolutionsin interfaceSolutionListener<T extends Var>- Parameters:
status- true if we are interested in recording all solutions, false otherwise.
-
searchAll
public void searchAll(boolean status) It searches for all solutions, but they do not have to be recorded as this is decided by another parameter.- Specified by:
searchAllin interfaceSolutionListener<T extends Var>- Parameters:
status- true if we are interested in search for all solutions, false otherwise.
-
recordSolution
public void recordSolution()It records a solution. It uses the current value of the search variables (they must be all grounded) as well as the current number of the solution in master search (if there is one). -
executeAfterSolution
Description copied from interface:SolutionListenerIt is executed by search after a solution is found.- Specified by:
executeAfterSolutionin interfaceSolutionListener<T extends Var>- Parameters:
search- the search which have found a solution.select- the select choice point heuristic- Returns:
- false forces the search to keep looking for a solution, true then the search will accept a solution.
-
assignSolution
It assigns the last found solution to the store. If the function returns false that means that for some reason the solution which was supposed to be a solution is not. It can be caused by a number of issues, starting with wrongly implemented plugins, wrongly implemented consistency or satisfied function of the constraint.- Parameters:
store- the store in the context of which the search took place.- Returns:
- true if the store is consistent after assigning a solution, false otherwise.
-
assignSolution
Description copied from interface:SolutionListenerIt imposes the constraints, so the last found solution is enforced.- Specified by:
assignSolutionin interfaceSolutionListener<T extends Var>- Parameters:
store- store in which the solution is enforced.number- the number of the solution to be enforced.- Returns:
- true if the store is consistent after enforcing a solution, false otherwise.
-
setVariables
-
toString
Description copied from interface:SolutionListenerIt returns the string representation of the last solution. -
returnSolution
Description copied from interface:SolutionListenerIt returns a collection of constraints which represent the last found solution.- Specified by:
returnSolutionin interfaceSolutionListener<T extends Var>- Returns:
- the set of constraints which imposed enforce the last found solution.
-
returnSolution
It returns the solution with the given number (value 0 denotes the first solution) as a set of primitive constraints.- Parameters:
number- the solution number (0 denotes the first solution).- Returns:
- set of primitive constraint which if imposed will enforce given solution.
-
findSolutionMatchingParent
public int findSolutionMatchingParent(int parentNo) Description copied from interface:SolutionListenerFor a given master solution finds any solution within that listener which matches the master solution.- Specified by:
findSolutionMatchingParentin interfaceSolutionListener<T extends Var>- Parameters:
parentNo- solution number of the parent for which we search matching solution.- Returns:
- -1 if no solution was found, otherwise the index of the solution.
-
setChildrenListeners
Description copied from interface:SolutionListenerIt sets the children listeners for this solution listener.- Specified by:
setChildrenListenersin interfaceSolutionListener<T extends Var>- Parameters:
children- an array containing children listeners.
-
setChildrenListeners
Description copied from interface:SolutionListenerIt sets the child listener for this solution listener.- Specified by:
setChildrenListenersin interfaceSolutionListener<T extends Var>- Parameters:
child- the child listener.
-
isRecordingSolutions
public boolean isRecordingSolutions()Description copied from interface:SolutionListenerIt specifies if the solution listener is recording solutions or not.- Specified by:
isRecordingSolutionsin interfaceSolutionListener<T extends Var>- Returns:
- true if all solutions are recorded, false if only the last one is recorded.
-
printAllSolutions
public void printAllSolutions()Description copied from interface:SolutionListenerIt prints all the solutions.- Specified by:
printAllSolutionsin interfaceSolutionListener<T extends Var>
-
getParentSolution
public int getParentSolution(int childSolutionNo) - Specified by:
getParentSolutionin interfaceSolutionListener<T extends Var>
-