Class SetVarImpl

    • Constructor Detail

      • SetVarImpl

        public SetVarImpl​(String name,
                          int[] ker,
                          SetType kerType,
                          int[] env,
                          SetType envType,
                          Model model)
        Creates a Set variable
        Parameters:
        name - name of the variable
        ker - initial kernel domain
        kerType - data structure of the kernel
        env - initial envelope domain
        envType - data structure of the envelope
        model - solver of the variable.
      • SetVarImpl

        public SetVarImpl​(String name,
                          ISet lb,
                          ISet ub,
                          Model model)
        Creates a set variable, of domain [lb, ub] Beware : Use this constructor with caution (domain is directly accessible) lb and ub should be created properly (e.g. lb subset of ub) and should not be modified externally Both lb and ub should be backtrackable sets (stored sets): use SetFactory.makeStoredSet to build them
        Parameters:
        name - name of the variable
        lb - lower bound of the set variable (mandatory elements)
        ub - upper bound of the set variable (potential elements)
        model - solver of the variable.
      • SetVarImpl

        public SetVarImpl​(String name,
                          ISet value,
                          Model model)
        Creates a fixed Set variable, equal to value Beware : Use this constructor with caution (domain is directly accessible) value should be created properly and should not be modified afterward
        Parameters:
        name - name of the variable
        value - value of the set variable
        model - solver of the variable.
      • SetVarImpl

        public SetVarImpl​(String name,
                          int[] value,
                          Model model)
        Creates a fixed Set variable, equal to value
        Parameters:
        name - name of the variable
        value - value of the set variable
        model - solver of the variable.
    • Method Detail

      • isInstantiated

        public boolean isInstantiated()
        Description copied from interface: Variable
        Indicates whether this is instantiated (see implemtations to know what instantiation means).
        Specified by:
        isInstantiated in interface Variable
        Returns:
        true if this is instantiated
      • getLB

        public ISet getLB()
        Description copied from interface: SetVar
        Get SetVar Lower Bound : the set of integers that must belong to every solution (i.e. a subset of all solutions) To iterate over this set, use the following loop: ISet lbSet = getLB(); for(int i : lbSet){ ... } This object is read-only. Use variable methods force to update the domain
        Specified by:
        getLB in interface SetVar
        Returns:
        the lower bound of this SetVar.
      • getUB

        public ISet getUB()
        Description copied from interface: SetVar
        Get SetVar Upper Bound : the set of integers that may belong to a solution (i.e. a superset of all solutions) To iterate over this set, use the following loop: ISet ubSet = getUB(); for(int i : ubSet){ ... } This object is read-only. Use variable methods remove to update the domain
        Specified by:
        getUB in interface SetVar
        Returns:
        the lower bound of this SetVar.
      • 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.
      • 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
      • 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
      • instantiateTo

        public boolean instantiateTo​(int[] value,
                                     ICause cause)
                              throws ContradictionException
        Description copied from interface: SetVar
        Enforces the set variable to contain exactly the set of integers given in parameter
        Specified by:
        instantiateTo in interface SetVar
        Parameters:
        value - a set of integers
        cause - cause of instantiation
        Returns:
        true iff a domain modification occurred
        Throws:
        ContradictionException
      • getDelta

        public SetDelta getDelta()
        Description copied from interface: Variable
        Return the delta domain of this
        Specified by:
        getDelta in interface Variable
        Returns:
        the delta domain of the 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
      • 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
      • monitorDelta

        public SetDeltaMonitor monitorDelta​(ICause propagator)
        Description copied from interface: SetVar
        Allow propagator to monitor element removal/enforcing of this
        Specified by:
        monitorDelta in interface SetVar
        Parameters:
        propagator - observer
        Returns:
        a new SetDeltaMonitor