JaCoP.search
Class CreditCalculator<T extends Var>

java.lang.Object
  extended by 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 java.lang.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.

Author:
Radoslaw Szymanek and Krzysztof Kuchcinski

Constructor Summary
CreditCalculator(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
 boolean executeAfterConsistency(boolean consistent)
          It is executed right after consistency of the current search node.
 void executedAtTimeOut(int noSolutions)
          It is executed right after time out is determined.
 boolean leftChild(PrimitiveConstraint choice, boolean status)
          It is executed after exiting the left child.
 boolean leftChild(T var, int value, boolean status)
          It is executed after exiting the left child.
 void rightChild(PrimitiveConstraint choice, boolean status)
          It is executed after exiting the right child.
 void rightChild(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.
 void setChildrenListeners(ConsistencyListener child)
          Setting one child listener.
 void setChildrenListeners(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).
 void setChildrenListeners(ExitChildListener<T> child)
          It adds one child listener.
 void setChildrenListeners(ExitChildListener<T>[] children)
          It sets the children listeners for the current listener.
 void setChildrenListeners(TimeOutListener child)
          It sets child listener for this timeout listener.
 void setChildrenListeners(TimeOutListener[] children)
          It sets children listeners for this timeout listener.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

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 Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

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:
executeAfterConsistency in interface ConsistencyListener
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:
executedAtTimeOut in interface TimeOutListener
Parameters:
noSolutions - number of solutions found before the timeout occurred.

leftChild

public boolean leftChild(T var,
                         int value,
                         boolean status)
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:
leftChild in interface ExitChildListener<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

public boolean leftChild(PrimitiveConstraint choice,
                         boolean status)
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:
leftChild in interface ExitChildListener<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

public void rightChild(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.

Specified by:
rightChild in interface ExitChildListener<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

public void rightChild(PrimitiveConstraint choice,
                       boolean status)
Description copied from interface: ExitChildListener
It is executed after exiting the right child.

Specified by:
rightChild in interface ExitChildListener<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

public void setChildrenListeners(ConsistencyListener[] children)
Description copied from interface: ConsistencyListener
Each of the child listeners will be called and the return code from them will be combined (taken into account) by a parent).

Specified by:
setChildrenListeners in interface ConsistencyListener
Parameters:
children - the children listeners attached to this listener.

setChildrenListeners

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

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

setChildrenListeners

public void setChildrenListeners(TimeOutListener[] children)
Description copied from interface: TimeOutListener
It sets children listeners for this timeout listener.

Specified by:
setChildrenListeners in interface TimeOutListener
Parameters:
children - list of children listeners.

setChildrenListeners

public void setChildrenListeners(ConsistencyListener child)
Description copied from interface: ConsistencyListener
Setting one child listener.

Specified by:
setChildrenListeners in interface ConsistencyListener
Parameters:
child - the only child listener added to this consistency listener.

setChildrenListeners

public void setChildrenListeners(ExitChildListener<T> child)
Description copied from interface: ExitChildListener
It adds one child listener.

Specified by:
setChildrenListeners in interface ExitChildListener<T extends Var>
Parameters:
child - added child listener.

setChildrenListeners

public void setChildrenListeners(TimeOutListener child)
Description copied from interface: TimeOutListener
It sets child listener for this timeout listener.

Specified by:
setChildrenListeners in interface TimeOutListener
Parameters:
child - child listener for this timeout listener.