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
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.9
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean
It contains children of the solution listener.private static final boolean
It specifies if the debugging information should be printed.protected int
SolutionListener
<? 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) boolean
int
It 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 TypeMethodDescriptionboolean
assignSolution
(Store store) It assigns the last found solution to the store.boolean
assignSolution
(Store store, int number) It imposes the constraints, so the last found solution is enforced.boolean
executeAfterSolution
(Search<T> search, SelectChoicePoint<T> select) It is executed by search after a solution is found.int
findSolutionMatchingParent
(int parentNo) For a given master solution finds any solution within that listener which matches the master solution.int
getParentSolution
(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.boolean
It specifies if the solution listener is recording solutions or not.void
It prints all the solutions.void
It records a solution.void
recordSolutions
(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.void
searchAll
(boolean status) It searches for all solutions, but they do not have to be recorded as this is decided by another parameter.void
setChildrenListeners
(SolutionListener<T> child) It sets the child listener for this solution listener.void
setChildrenListeners
(SolutionListener<T>[] children) It sets the children listeners for this solution listener.void
setParentSolutionListener
(SolutionListener<? extends Var> parent) It allows to inform sub-search of what is the current number of the solution in master search.void
setSolutionLimit
(int limit) It sets the solution limit.void
setSolutionsNo
(int no) void
setVariables
(T[] vs) boolean
It checks if the sufficient number of solutions was found.int
It 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:
getVariables
in interfaceSolutionListener<T extends Var>
- Returns:
- list of variables
-
solutionLimitReached
public boolean solutionLimitReached()Description copied from interface:SolutionListener
It checks if the sufficient number of solutions was found.- Specified by:
solutionLimitReached
in 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:SolutionListener
It sets the solution limit.- Specified by:
setSolutionLimit
in interfaceSolutionListener<T extends Var>
- Parameters:
limit
- the maximal number of solutions we are interested in.
-
setParentSolutionListener
Description copied from interface:SolutionListener
It allows to inform sub-search of what is the current number of the solution in master search.- Specified by:
setParentSolutionListener
in interfaceSolutionListener<T extends Var>
- Parameters:
parent
- solution listener used by a master search.
-
getSolutions
Description copied from interface:SolutionListener
It returns all solutions. Each solution is in a separate array.- Specified by:
getSolutions
in 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:
getSolution
in 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:
solutionsNo
in 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:
recordSolutions
in 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:
searchAll
in 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:SolutionListener
It is executed by search after a solution is found.- Specified by:
executeAfterSolution
in 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:SolutionListener
It imposes the constraints, so the last found solution is enforced.- Specified by:
assignSolution
in 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:SolutionListener
It returns the string representation of the last solution. -
returnSolution
Description copied from interface:SolutionListener
It returns a collection of constraints which represent the last found solution.- Specified by:
returnSolution
in 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:SolutionListener
For a given master solution finds any solution within that listener which matches the master solution.- Specified by:
findSolutionMatchingParent
in 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:SolutionListener
It sets the children listeners for this solution listener.- Specified by:
setChildrenListeners
in interfaceSolutionListener<T extends Var>
- Parameters:
children
- an array containing children listeners.
-
setChildrenListeners
Description copied from interface:SolutionListener
It sets the child listener for this solution listener.- Specified by:
setChildrenListeners
in interfaceSolutionListener<T extends Var>
- Parameters:
child
- the child listener.
-
isRecordingSolutions
public boolean isRecordingSolutions()Description copied from interface:SolutionListener
It specifies if the solution listener is recording solutions or not.- Specified by:
isRecordingSolutions
in 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:SolutionListener
It prints all the solutions.- Specified by:
printAllSolutions
in interfaceSolutionListener<T extends Var>
-
getParentSolution
public int getParentSolution(int childSolutionNo) - Specified by:
getParentSolution
in interfaceSolutionListener<T extends Var>
-