Class SetView<V extends Variable>

    • Field Detail

      • cardinality

        protected IntVar cardinality
    • Constructor Detail

      • SetView

        protected SetView​(java.lang.String name,
                          V... variables)
        Create a set view.
        Parameters:
        name - name of the variable
        variables - observed variables
    • Method Detail

      • doRemoveSetElement

        protected abstract boolean doRemoveSetElement​(int element)
                                               throws ContradictionException
        Action to execute on observed variables when this view requires to remove an element from its upper bound
        Parameters:
        element - element to remove from the set view
        Returns:
        true if at least one of the observed variables has been modified
        Throws:
        ContradictionException
      • doForceSetElement

        protected abstract boolean doForceSetElement​(int element)
                                              throws ContradictionException
        Action to execute on observed variables when this view requires to force an element to its lower bound
        Parameters:
        element - element to force to the set view
        Returns:
        true if at least one of the observed variables has been modified
        Throws:
        ContradictionException
      • force

        public boolean force​(int element,
                             ICause cause)
                      throws ContradictionException
        Description copied from interface: SetVar
        Adds element to the lower bound, i.e. every solution must include element
        Specified by:
        force in interface SetVar
        Parameters:
        element - value to add
        cause - cause of value addition
        Returns:
        true iff element has been added to the lower bound
        Throws:
        ContradictionException - if adding element fails
      • remove

        public boolean remove​(int element,
                              ICause cause)
                       throws ContradictionException
        Description copied from interface: SetVar
        Removes element from the upper bound, i.e. the set variable cannot contain element anymore
        Specified by:
        remove in interface SetVar
        Parameters:
        element - value to remove
        cause - cause of value removal
        Returns:
        true iff element has been removed from the upper bound
        Throws:
        ContradictionException - if removing element fails
      • createDelta

        public void createDelta()
        Description copied from interface: Variable
        Create a delta, if necessary, in order to observe removed values of a this. If the delta already exists, has no effect.
        Specified by:
        createDelta in interface Variable
      • getTypeAndKind

        public int getTypeAndKind()
        Description copied from interface: Variable
        Return a MASK composed of 2 main information: TYPE and KIND.
        TYPE is defined in the 3 first bits : VAR ( 1 << 0), CSTE (1 << 1) or VIEW (1 << 2)
        KIND is defined on the other bits : INT (1 << 3), BOOL (INT + 1 << 4), GRAPH (1 << 5) or META (1 << 6)

        To get the TYPE of a variable:

         int type = var.getTypeAndKind() & Variable.TYPE;
         

        To get the KIND of a variable:

         int kind = var.getTypeAndKind() & Variable.KIND;
         

        To check a specific type or kind of a variable:

             boolean isVar = (var.getTypeAndKind() & Variable.VAR) !=0;
             boolean isInt = (var.getTypeAndKind() & Variable.INT) !=0;
         
        Specified by:
        getTypeAndKind in interface Variable
        Returns:
        an int representing the type and kind of the variable
      • justifyEvent

        public void justifyEvent​(IntEventType mask,
                                 int one,
                                 int two,
                                 int three)
        Description copied from interface: IView
        This methods is related to explanations, it binds an event occurring on the observed variable to the view.
        Specified by:
        justifyEvent in interface IView<V extends Variable>
        Parameters:
        mask - type of modification
        one - an int
        two - an int
        three - an int
      • explain

        public void explain​(int p,
                            ExplanationForSignedClause clause)
        Description copied from interface: ICause
        Clausal explanation for this cause.

        This method must filled explanations with inferred literals. These literals are inferred from the analysis of (a subset of) conflicting nodes stored in front, the implication graph ig and the current node in conflict, not yet contained in front.

        Optionally, this method can update front by looking for a predecessor of any node that seems more relevant than the declared one.

        Specified by:
        explain in interface ICause
        Parameters:
        p - the pivot node out of front
        clause - explanation to compute
      • getCard

        public IntVar getCard()
        Description copied from interface: SetVar
        get the constrained cardinality variable of this set.
        • if no variable already has this role, creates a new variable, store and constraint it.
        • if a variable already has this role, return it.
        Specified by:
        getCard in interface SetVar
        Returns:
        a variable constrained to this set cardinality. Successive calls should return the same value
      • hasCard

        public boolean hasCard()
        Specified by:
        hasCard in interface SetVar
        Returns:
        true if a variable is constrained to this set's cardinality, false otherwise
      • setCard

        public void setCard​(IntVar card)
        Description copied from interface: SetVar
        ensure a variable is equal to the cardinality of this set.
        • If not call has been already performed to this set cardinality, post a constraint on the number of variables
        • if this set already has a variable constrained to the cardinality, post an equality
        Specified by:
        setCard in interface SetVar
        Parameters:
        card - a variable of the same model.