Class 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 int BD
      Mask for integer variable bounds modification
      protected static int DM
      Mask for integer variable modification
      protected static int LB
      Mask for integer variable lower bound modification
      protected static int RM
      Mask for integer variable value removal
      protected static int UB
      Mask for integer variable upper bound modification
    • Constructor Summary

      Constructors 
      Constructor Description
      RuleStore​(boolean saveCauses, boolean enablePartialExplanation)
      Instantiate a rule store to compute explanations
    • 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 in eventStore of the event to evaluate
        eventStore - set of events
        Returns:
        true if the event in position idx in eventStore matches a rule
        Throws:
        SolverException - when the type of the variable is neither Variable.BOOL or Variable.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 mask
        ivar - the integer variable
        evt - the event
        i1 - 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 event
        eventStore - the event store
        explanation - 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 on
        value - 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 decision
        explanation - 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 decision
        to - 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