Class RuleStore
- java.lang.Object
-
- org.chocosolver.solver.explanations.RuleStore
-
public class RuleStore extends Object
A RuleStore is a central object in the Asynchronous, Reverse, Low-Intrusive and Lazy explanation engine. It stores a set of rules which enables to compute the explanation of a situation (for instance a conflict) by scanning the events generated on the current branch. The set of rules is dynamically maintained.Created by cprudhom on 09/12/14. Project: choco.
- Since:
- 09/12/14
- Author:
- Charles Prud'homme
-
-
Field Summary
Fields Modifier and Type Field Description protected static intBDMask for integer variable bounds modificationprotected static intDMMask for integer variable modificationprotected static intLBMask for integer variable lower bound modificationprotected static intRMMask for integer variable value removalprotected static intUBMask for integer variable upper bound modification
-
Constructor Summary
Constructors Constructor Description RuleStore(boolean saveCauses, boolean enablePartialExplanation)Instantiate a rule store to compute explanations
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddBoundsRule(IntVar var)Add an upper bound rule and a lower bound rule, that is, any event on the upper bound or the lower bound of the variable needs to be retainedbooleanaddFullDomainRule(IntVar var)Add a full domain rule, that is, any events involving the variable needs to be retained.booleanaddLowerBoundRule(IntVar var)Add a lower bound rule, that is, any event on the lower bound of the variable needs to be retainedbooleanaddPropagatorActivationRule(Propagator propagator)Add a propagator activation rulebooleanaddRemovalRule(IntVar var, int value)Add a value removal rule, that is, the event which remove the value needs to be retained.booleanaddUpperBoundRule(IntVar var)Add a upper bound rule, that is, any event on the upper bound of the variable needs to be retainedvoidfreeDecisionExplanation(Decision decision)Free the explanation related to the decision (for efficiency purpose only)ExplanationgetDecisionRefutation(Decision decision)Get the explanation associated with a decision refutationintgetMask(Variable var)Return the current rule mask associated to the variable vidvoidinit(Explanation expl)Initialize the rulestore for a new explanationbooleanisPreemptedStop()when conditions are favorable, a preempted stop can be considered: not all events have to be analyzed.booleanmatch(int idx, ArrayEventStore eventStore)Return true if the event represented by matches one of the active rules.booleanmatchDomain(int ruleMask, IntVar ivar, IntEventType evt, int i1, int i2, int i3)Check whether a variable domain matches a rulevoidmoveDecisionRefutation(Decision decision, int to)Move a decision refutation to the 'to' indexvoidstoreDecisionRefutation(Decision decision, Explanation explanation)Store a decision refutation, for future reasoning.voidupdate(int idx, ArrayEventStore eventStore, Explanation explanation)Update the rule store, and the explanation, wrt a given event
-
-
-
Field Detail
-
DM
protected static final int DM
Mask for integer variable modification- See Also:
- Constant Field Values
-
BD
protected static final int BD
Mask for integer variable bounds modification- See Also:
- Constant Field Values
-
UB
protected static final int UB
Mask for integer variable upper bound modification- See Also:
- Constant Field Values
-
LB
protected static final int LB
Mask for integer variable lower bound modification- See Also:
- Constant Field Values
-
RM
protected static final int RM
Mask for integer variable value removal- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RuleStore
public RuleStore(boolean saveCauses, boolean enablePartialExplanation)Instantiate a rule store to compute explanations- Parameters:
saveCauses- does it keep trace of the constraints in conflict ?enablePartialExplanation- do explanations need to be complete (for DBT or nogood extraction) ?
-
-
Method Detail
-
init
public void init(Explanation expl)
Initialize the rulestore for a new explanation- Parameters:
expl- an explanation
-
isPreemptedStop
public boolean isPreemptedStop()
when conditions are favorable, a preempted stop can be considered: not all events have to be analyzed.- Returns:
- return true if early stop occurs.
-
match
public boolean match(int idx, ArrayEventStore eventStore)Return true if the event represented by matches one of the active rules.- Parameters:
idx- index ineventStoreof the event to evaluateeventStore- set of events- Returns:
- true if the event in position
idxineventStorematches a rule - Throws:
SolverException- when the type of the variable is neitherVariable.BOOLorVariable.INT.
-
matchDomain
public boolean matchDomain(int ruleMask, IntVar ivar, IntEventType evt, int i1, int i2, int i3)Check whether a variable domain matches a rule- Parameters:
ruleMask- the current rule maskivar- the integer variableevt- the eventi1- either instantiated value (IN) or new lb (LB) or new ub (UB) or removed value (RM)i2- either old lb (IN, LB) or old ub (UB) or -1 (RM)i3- either old ub (IN), or -1 (LB, UB, RM)- Returns:
- true the variable state matches a rule
-
update
public void update(int idx, ArrayEventStore eventStore, Explanation explanation)Update the rule store, and the explanation, wrt a given event- Parameters:
idx- index of the eventeventStore- the event storeexplanation- the explanation to compute
-
addRemovalRule
public boolean addRemovalRule(IntVar var, int value)
Add a value removal rule, that is, the event which remove the value needs to be retained.- Parameters:
var- the variable to add rule onvalue- the removed value- Returns:
- true if a new rule has been added (false = already existing rule)
- Throws:
SolverException- when the domain is not enumerated
-
addFullDomainRule
public boolean addFullDomainRule(IntVar var)
Add a full domain rule, that is, any events involving the variable needs to be retained.- Parameters:
var- the variable to add rule on- Returns:
- true if a new rule has been added (false = already existing rule)
-
addLowerBoundRule
public boolean addLowerBoundRule(IntVar var)
Add a lower bound rule, that is, any event on the lower bound of the variable needs to be retained- Parameters:
var- the variable to add rule on- Returns:
- true if a new rule has been added (false = already existing rule)
-
addUpperBoundRule
public boolean addUpperBoundRule(IntVar var)
Add a upper bound rule, that is, any event on the upper bound of the variable needs to be retained- Parameters:
var- the variable to add rule on- Returns:
- true if a new rule has been added (false = already existing rule)
-
addBoundsRule
public boolean addBoundsRule(IntVar var)
Add an upper bound rule and a lower bound rule, that is, any event on the upper bound or the lower bound of the variable needs to be retained- Parameters:
var- the variable to add rule on- Returns:
- true if a new rule has been added (false = already existing rule)
-
getMask
public int getMask(Variable var)
Return the current rule mask associated to the variable vid- Parameters:
var- a variable- Returns:
- the current mask or NO_ENTRY
-
addPropagatorActivationRule
public boolean addPropagatorActivationRule(Propagator propagator)
Add a propagator activation rule- Parameters:
propagator- activated propagator- Returns:
- true if a new rule has been adde
-
storeDecisionRefutation
public void storeDecisionRefutation(Decision decision, Explanation explanation)
Store a decision refutation, for future reasoning.- Parameters:
decision- refuted decisionexplanation- the explanation of the refutation
-
moveDecisionRefutation
public void moveDecisionRefutation(Decision decision, int to)
Move a decision refutation to the 'to' index- Parameters:
decision- a refuted decisionto- the new index
-
freeDecisionExplanation
public void freeDecisionExplanation(Decision decision)
Free the explanation related to the decision (for efficiency purpose only)- Parameters:
decision- the decision which is going to be forgotten
-
getDecisionRefutation
public Explanation getDecisionRefutation(Decision decision)
Get the explanation associated with a decision refutation- Parameters:
decision- a RIGHT branch decision- Returns:
- an explanation
-
-