JaCoP.search
Class SimpleSolutionListener<T extends Var>

java.lang.Object
  extended by JaCoP.search.SimpleSolutionListener<T>
Type Parameters:
T - type of variable being used in search.
All Implemented Interfaces:
SolutionListener<T>
Direct Known Subclasses:
CrossWord.PrintListener, PrintOutListener, Solve.CostListener, Solve.EmptyListener

public class SimpleSolutionListener<T extends Var>
extends java.lang.Object
implements SolutionListener<T>

It defines a simple solution listener which should be used if some basic functionality of search when a solution is encounterred are required.

Version:
3.1
Author:
Radoslaw Szymanek and Krzysztof Kuchcinski

Field Summary
 SolutionListener<T>[] childrenSolutionListeners
          It contains children of the solution listener.
 SolutionListener<? extends Var> parentSolutionListener
          If this search is a slave search than each solution within this search must be connected to a solution of the master search.
 int[] parentSolutionNo
          If this search is a slave search than each solution within this search must be connected to a solution of the master search.
 int solutionLimit
          It specifies the number of solutions we want to find.
 
Constructor Summary
SimpleSolutionListener()
           
 
Method Summary
 boolean 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[][] getSolutions()
          It returns all solutions.
 T[] getVariables()
          It returns null if no solution was recorded, or the variables for which the solution(s) was recorded.
 boolean isRecordingSolutions()
          It specifies if the solution listener is recording solutions or not.
 void printAllSolutions()
          It prints all the solutions.
 void recordSolution()
          It records a solution.
 void recordSolutions(boolean status)
          It records all solutions so they can be later retrieved and used.
 PrimitiveConstraint[] returnSolution()
          It returns a collection of constraints which represent the last found solution.
 PrimitiveConstraint[] 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.
 boolean solutionLimitReached()
          It checks if the sufficient number of solutions was found.
 int solutionsNo()
          It returns number of solutions found while using this choice point selector.
 java.lang.String toString()
          It returns the string representation of the last solution.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

solutionLimit

public int solutionLimit
It specifies the number of solutions we want to find.


parentSolutionListener

public SolutionListener<? extends Var> 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[] parentSolutionNo
If 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

public SolutionListener<T extends Var>[] childrenSolutionListeners
It contains children of the solution listener.

Constructor Detail

SimpleSolutionListener

public SimpleSolutionListener()
Method Detail

getVariables

public T[] getVariables()
It returns null if no solution was recorded, or the variables for which the solution(s) was recorded.

Specified by:
getVariables in interface SolutionListener<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 interface SolutionListener<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 interface SolutionListener<T extends Var>
Parameters:
limit - the maximal number of solutions we are interested in.

setParentSolutionListener

public void setParentSolutionListener(SolutionListener<? extends Var> parent)
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 interface SolutionListener<T extends Var>
Parameters:
parent - solution listener used by a master search.

getSolutions

public Domain[][] getSolutions()
Description copied from interface: SolutionListener
It returns all solutions. Each solution is in a separate array.

Specified by:
getSolutions in interface SolutionListener<T extends Var>
Returns:
first dimension is indexed by solution, second dimension is indexed by a variable.

getSolution

public Domain[] getSolution(int no)
It returns the solution number no. The first solution has an index 1.

Specified by:
getSolution in interface SolutionListener<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 interface SolutionListener<T extends Var>
Returns:
the number of solutions.

recordSolutions

public void recordSolutions(boolean status)
It records all solutions so they can be later retrieved and used.

Specified by:
recordSolutions in interface SolutionListener<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 interface SolutionListener<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

public boolean executeAfterSolution(Search<T> search,
                                    SelectChoicePoint<T> select)
Description copied from interface: SolutionListener
It is executed by search after a solution is found.

Specified by:
executeAfterSolution in interface SolutionListener<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

public boolean assignSolution(Store store)
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

public boolean assignSolution(Store store,
                              int number)
Description copied from interface: SolutionListener
It imposes the constraints, so the last found solution is enforced.

Specified by:
assignSolution in interface SolutionListener<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.

toString

public java.lang.String toString()
Description copied from interface: SolutionListener
It returns the string representation of the last solution.

Specified by:
toString in interface SolutionListener<T extends Var>
Overrides:
toString in class java.lang.Object

returnSolution

public PrimitiveConstraint[] returnSolution()
Description copied from interface: SolutionListener
It returns a collection of constraints which represent the last found solution.

Specified by:
returnSolution in interface SolutionListener<T extends Var>
Returns:
the set of constraints which imposed enforce the last found solution.

returnSolution

public PrimitiveConstraint[] returnSolution(int number)
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 interface SolutionListener<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

public void setChildrenListeners(SolutionListener<T>[] children)
Description copied from interface: SolutionListener
It sets the children listeners for this solution listener.

Specified by:
setChildrenListeners in interface SolutionListener<T extends Var>
Parameters:
children - an array containing children listeners.

setChildrenListeners

public void setChildrenListeners(SolutionListener<T> child)
Description copied from interface: SolutionListener
It sets the child listener for this solution listener.

Specified by:
setChildrenListeners in interface SolutionListener<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 interface SolutionListener<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 interface SolutionListener<T extends Var>

getParentSolution

public int getParentSolution(int childSolutionNo)
Specified by:
getParentSolution in interface SolutionListener<T extends Var>