Package org.jacop.search
Class CreditCalculator<T extends Var>
java.lang.Object
org.jacop.search.CreditCalculator<T>
- Type Parameters:
T- type of variable being used in the search.
- All Implemented Interfaces:
ConsistencyListener,ExitChildListener<T>,TimeOutListener
public class CreditCalculator<T extends Var>
extends Object
implements ExitChildListener<T>, TimeOutListener, ConsistencyListener
Defines functionality of credit search. Plugin in this object into search to
change your depth first search into credit search. It has to be plugin as
ExitChildListener, TimeOutListener, and Consistency Listener.
- Version:
- 4.10
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) int(package private) ConsistencyListener[](package private) int[](package private) int[](package private) int(package private) int(package private) ExitChildListener<T>[](package private) boolean(package private) boolean(package private) TimeOutListener[] -
Constructor Summary
ConstructorsConstructorDescriptionCreditCalculator(int credit, int backtracks) The constructor allows to specify number of credits.CreditCalculator(int credit, int backtracks, int maxDepth) The constructor allows to specify number of credits. -
Method Summary
Modifier and TypeMethodDescriptionbooleanexecuteAfterConsistency(boolean consistent) It is executed right after consistency of the current search node.voidexecutedAtTimeOut(int noSolutions) It is executed right after time out is determined.booleanleftChild(PrimitiveConstraint choice, boolean status) It is executed after exiting the left child.booleanIt is executed after exiting the left child.voidrightChild(PrimitiveConstraint choice, boolean status) It is executed after exiting the right child.voidrightChild(T var, int value, boolean status) Exiting the right children if no credits have been distributed to a right child involves increasing the number of backtracks occurred.voidSetting one child listener.voidsetChildrenListeners(ConsistencyListener[] children) Each of the child listeners will be called and the return code from them will be combined (taken into account) by a parent).voidsetChildrenListeners(ExitChildListener<T> child) It adds one child listener.voidsetChildrenListeners(ExitChildListener<T>[] children) It sets the children listeners for the current listener.voidIt sets child listener for this timeout listener.voidsetChildrenListeners(TimeOutListener[] children) It sets children listeners for this timeout listener.toString()
-
Field Details
-
timeOut
boolean timeOut -
backtracks
int backtracks -
currentLevel
int currentLevel -
currentBacktracks
int currentBacktracks -
creditsLeft
int[] creditsLeft -
creditsRight
int[] creditsRight -
leftChild
boolean leftChild -
consistencyListeners
ConsistencyListener[] consistencyListeners -
exitChildListeners
ExitChildListener<T extends Var>[] exitChildListeners -
timeOutListeners
TimeOutListener[] timeOutListeners
-
-
Constructor Details
-
CreditCalculator
public CreditCalculator(int credit, int backtracks, int maxDepth) The constructor allows to specify number of credits. Credits of the parent are divided equally among children. As soon a node has only one credit, there is a restriction how many backtracks can be performed in search in the left and right child altogether. If nodes are at maxDepth then the credits are not splitted among children but sent back to the parent for use in other parts of the tree. In a nutshell, there are maximally credit number of search subtrees attached at depth no lower than max depth with a maximumally number of backtracks performed in those subtrees. This approach allows to limit detrimental effect of early mistake which can not be proven easily by a backtrack search.- Parameters:
credit- the number of credits given to a search.backtracks- the maximum number of allowed backtracks from the node which has no remaining credits.maxDepth- the maximum depth at which it is still alowed to distribute credits.
-
CreditCalculator
public CreditCalculator(int credit, int backtracks) The constructor allows to specify number of credits. Credits of the parent are divided equally among children. As soon a node has only one credit, there is a restriction how many backtracks can be performed in search in the left and right child altogether. This approach allows to limit detrimental effect of early mistake which can not be proven easily by a backtrack search.- Parameters:
credit- the number of credits given to a search.backtracks- the maximum number of allowed backtracks from the node which has no remaining credits.
-
-
Method Details
-
toString
-
executeAfterConsistency
public boolean executeAfterConsistency(boolean consistent) It is executed right after consistency of the current search node. The return code specifies if the search should continue with or exit the current search node.- Specified by:
executeAfterConsistencyin interfaceConsistencyListener- Parameters:
consistent- specifies if the consistency call returned true or false.- Returns:
- true if the search should continue, false if the search should act as the consistency returned false.
-
executedAtTimeOut
public void executedAtTimeOut(int noSolutions) It is executed right after time out is determined.- Specified by:
executedAtTimeOutin interfaceTimeOutListener- Parameters:
noSolutions- number of solutions found before the timeout occurred.
-
leftChild
It is executed after exiting the left child. The parameters specify the variable and value used in the choice point. The parameter status specifies the return code from the child. The return parameter of this function specifies if the search should continue undisturbed or exit the current search node with false.- Specified by:
leftChildin interfaceExitChildListener<T extends Var>- Parameters:
var- variable used in the choice point.value- value used in the choice point.status- true if the solution was found in the child subtree, false otherwise.- Returns:
- true if the search should continue undisturbed, false if it should exit the current node with false
-
leftChild
It is executed after exiting the left child. The parameters specify the choice point. The parameter status specifies the return code from the child. The return parameter of this function specifies if the search should continue undisturbed or exit the current search node. If the left child has exhausted backtracks allowance then this function will return false so the right child will not be explored.- Specified by:
leftChildin interfaceExitChildListener<T extends Var>- Parameters:
choice- primitive constraint used as the base of the choice point.status- true if the solution was found in the child subtree, false otherwise.- Returns:
- true if the search should continue undisturbed to the right node, false if it should exit the current node with false
-
rightChild
Exiting the right children if no credits have been distributed to a right child involves increasing the number of backtracks occurred.- Specified by:
rightChildin interfaceExitChildListener<T extends Var>- Parameters:
var- variable used in the choice point.value- value used in the choice point.status- true if the solution was found in the child subtree, false otherwise. exit the current node with false
-
rightChild
Description copied from interface:ExitChildListenerIt is executed after exiting the right child.- Specified by:
rightChildin interfaceExitChildListener<T extends Var>- Parameters:
choice- primitive constraint used as the base of the choice point.status- true if the solution was found in the child subtree, false otherwise. exit the current node with false
-
setChildrenListeners
Description copied from interface:ConsistencyListenerEach of the child listeners will be called and the return code from them will be combined (taken into account) by a parent).- Specified by:
setChildrenListenersin interfaceConsistencyListener- Parameters:
children- the children listeners attached to this listener.
-
setChildrenListeners
Description copied from interface:ExitChildListenerIt sets the children listeners for the current listener.- Specified by:
setChildrenListenersin interfaceExitChildListener<T extends Var>- Parameters:
children- array containing children listeners.
-
setChildrenListeners
Description copied from interface:TimeOutListenerIt sets children listeners for this timeout listener.- Specified by:
setChildrenListenersin interfaceTimeOutListener- Parameters:
children- list of children listeners.
-
setChildrenListeners
Description copied from interface:ConsistencyListenerSetting one child listener.- Specified by:
setChildrenListenersin interfaceConsistencyListener- Parameters:
child- the only child listener added to this consistency listener.
-
setChildrenListeners
Description copied from interface:ExitChildListenerIt adds one child listener.- Specified by:
setChildrenListenersin interfaceExitChildListener<T extends Var>- Parameters:
child- added child listener.
-
setChildrenListeners
Description copied from interface:TimeOutListenerIt sets child listener for this timeout listener.- Specified by:
setChildrenListenersin interfaceTimeOutListener- Parameters:
child- child listener for this timeout listener.
-