Class Shaving<T extends IntVar>
- All Implemented Interfaces:
ConsistencyListener
,ExitChildListener<T>
Shaving
Each search level stores the variable value pairs which were shaved at a given level.
Shaving speculation.
The right child is using all the shavable pairs from the subtree rooted at the sibling of the current search node. If shaving fails then it is recorded in non shavable.
Not-shavable speculation
Every time a variable value pair is being schedule for shavability check then it is checked if that pair was not already checked for shavability before with a negative results. If so, then check is not performed but also entry in not-shavable is removed.
If variable value pair proofs to be not shavable then this variable value pair is recorded into Not-shavable speculation.
Quick shave - upon exiting any subtree the variable value pair which was choosen at the root of that subtree is recorded as shavable variable value pair.
- Version:
- 4.9
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ConsistencyListener[]
private int
private ExitChildListener[]
int
It stores number of failed shaving attempts.(package private) boolean
It specifies if the search is in the left child.(package private) boolean
private boolean
(package private) Map
<IntVar, LinkedHashSet<Integer>> boolean
It specifies if only the last failed constraint is allowed to suggest shaving values.boolean
It specifies if only variables in the scope of the last failed constraint are allowed to be used in shaving attempts.boolean
It specifies if the quickShave approach should be also used.(package private) Constraint
(package private) boolean
(package private) List
<Map<IntVar, LinkedHashSet<Integer>>> (package private) List
<Constraint> It contains list of constraints which suggest shaving explorations.(package private) Store
It specifies current store, so shaving can obtained information about recent failed constraint.int
It stores number of successful shaving attempts.It stores the variables of the last failed constraints.(package private) boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
It adds shaving constraint to the list of constraints guiding shaving.(package private) boolean
checkIfShavable
(IntVar var, Integer val) boolean
executeAfterConsistency
(boolean consistent) It is executed right after consistency of the current search node.boolean
leftChild
(PrimitiveConstraint choice, boolean status) It is executed after exiting the left child.boolean
It is executed after exiting the left child.void
rightChild
(PrimitiveConstraint choice, boolean status) It is executed after exiting the right child.void
rightChild
(IntVar var, int value, boolean status) It is executed after exiting the right child.void
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
It adds one child listener.void
setChildrenListeners
(ExitChildListener[] children) It sets the children listeners for the current listener.void
It specifies the constraint store in which context the shaving will take place.
-
Field Details
-
shavingConstraints
List<Constraint> shavingConstraintsIt contains list of constraints which suggest shaving explorations. -
leftChild
boolean leftChildIt specifies if the search is in the left child. -
store
Store storeIt specifies current store, so shaving can obtained information about recent failed constraint. -
recentlyFailedConstraint
Constraint recentlyFailedConstraint -
leftChildShaving
boolean leftChildShaving -
onlyFailedConstraint
public boolean onlyFailedConstraintIt specifies if only the last failed constraint is allowed to suggest shaving values. -
rightChild
boolean rightChild -
onlyIntVarsOfFailedConstraint
public boolean onlyIntVarsOfFailedConstraintIt specifies if only variables in the scope of the last failed constraint are allowed to be used in shaving attempts. -
varsOfFailedConstraint
It stores the variables of the last failed constraints. -
wrongDecisionEncountered
boolean wrongDecisionEncountered -
exitChildListeners
-
consistencyListeners
-
quickShave
public boolean quickShaveIt specifies if the quickShave approach should be also used. Quickshave uses variable-value pairs which lead to wrong decisions as shaving values higher in the search tree (until the first time shaving attempt for this value fails). -
leftChildWrongDecision
private boolean leftChildWrongDecision -
depth
private int depth -
shavable
List<Map<IntVar,LinkedHashSet<Integer>>> shavable -
notShavable
Map<IntVar,LinkedHashSet<Integer>> notShavable -
successes
public int successesIt stores number of successful shaving attempts. -
failures
public int failuresIt stores number of failed shaving attempts.
-
-
Constructor Details
-
Shaving
public Shaving()
-
-
Method Details
-
leftChild
Description copied from interface:ExitChildListener
It is executed after exiting the left child.- Specified by:
leftChild
in interfaceExitChildListener<T extends IntVar>
- 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
Description copied from interface:ExitChildListener
It is executed after exiting the left child.- Specified by:
leftChild
in interfaceExitChildListener<T extends IntVar>
- 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
Description copied from interface:ExitChildListener
It is executed after exiting the right child.- Specified by:
rightChild
in interfaceExitChildListener<T extends IntVar>
- 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:ExitChildListener
It is executed after exiting the right child.- Specified by:
rightChild
in interfaceExitChildListener<T extends IntVar>
- 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: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 interfaceConsistencyListener
- Parameters:
children
- the children listeners attached to this listener.
-
setChildrenListeners
Description copied from interface:ExitChildListener
It sets the children listeners for the current listener.- Specified by:
setChildrenListeners
in interfaceExitChildListener<T extends IntVar>
- Parameters:
children
- array containing children listeners.
-
setChildrenListeners
Description copied from interface:ConsistencyListener
Setting one child listener.- Specified by:
setChildrenListeners
in interfaceConsistencyListener
- Parameters:
child
- the only child listener added to this consistency listener.
-
setChildrenListeners
Description copied from interface:ExitChildListener
It adds one child listener.- Specified by:
setChildrenListeners
in interfaceExitChildListener<T extends IntVar>
- Parameters:
child
- added child listener.
-
executeAfterConsistency
public boolean executeAfterConsistency(boolean consistent) Description copied from interface:ConsistencyListener
It is executed right after consistency of the current search node. Returning true when the parameter was false is not advised as things like invalid solutions can be found.- Specified by:
executeAfterConsistency
in 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.
-
checkIfShavable
-
addShavingConstraint
It adds shaving constraint to the list of constraints guiding shaving.- Parameters:
c
- constraint which is added to the list of guiding constraints.
-
setStore
It specifies the constraint store in which context the shaving will take place.- Parameters:
store
- constraint store.
-