Class IntVar

  • All Implemented Interfaces:
    Backtrackable
    Direct Known Subclasses:
    BooleanVar

    public class IntVar
    extends Var
    Defines a Finite Domain Variable (FDV) and related operations on it.
    Version:
    4.7
    • Constructor Summary

      Constructors 
      Constructor Description
      IntVar()
      No parameter, explicit, empty constructor for subclasses.
      IntVar​(Store store)
      This constructor creates a variable with empty domain (standard IntervalDomain domain), automatically generated name, and empty attached constraint list.
      IntVar​(Store store, int min, int max)
      This constructor creates a variable with a domain between min..max, automatically generated name, and empty attached constraint list.
      IntVar​(Store store, java.lang.String name)
      This constructor creates a variable with an empty domain (standard IntervalDomain domain), the specified name, and an empty attached constraint list.
      IntVar​(Store store, java.lang.String name, int min, int max)
      This constructor creates a variable in a given store, with the domain specified by min..max and with the given name.
      IntVar​(Store store, java.lang.String name, IntDomain dom)
      It creates a variable in a given store, with a given name and a given domain.
      IntVar​(Store store, IntDomain dom)
      It creates a variable in a given store, with a given name and a given domain.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addDom​(int min, int max)
      It is possible to add the domain of variable.
      void addDom​(IntDomain dom)
      It is possible to add the domain of variable.
      private void commonInitialization​(Store store, java.lang.String name, IntDomain dom)  
      IntDomain dom()
      This function returns current domain of the variable.
      void domainHasChanged​(int event)
      It informs the variable that its variable has changed according to the specified event.
      boolean eq​(IntVar var)
      It checks if the domains of variables are equal.
      int getSize()
      It returns the size of the current domain.
      double getSizeFloat()
      It returns the size of the current domain.
      boolean isEmpty()
      It checks if the domain is empty.
      int level()
      This function returns stamp of the current domain of variable.
      int max()
      This function returns current maximal value in the domain of the variable.
      int min()
      This function returns current minimal value in the domain of the variable.
      void putConstraint​(Constraint c)
      It registers constraint with current variable, so anytime this variable is changed the constraint is reevaluated.
      void putModelConstraint​(Constraint c, int pruningEvent)
      It registers constraint with current variable, so anytime this variable is changed the constraint is reevaluated.
      void putSearchConstraint​(Constraint c)
      It registers constraint with current variable, so always when this variable is changed the constraint is reevaluated.
      IntDomain recentDomainPruning()
      It returns the values which have been removed at current store level.
      void remove​(int removedLevel)
      It specifies the function being called by the manager upon backtracking.
      void removeConstraint​(Constraint c)
      It detaches constraint from the current variable, so change in variable will not cause constraint reevaluation.
      void setDomain​(int min, int max)
      It is possible to set the domain of variable.
      void setDomain​(IntDomain dom)
      It is possible to set the domain of variable.
      boolean singleton()
      It checks if the domain contains only one value.
      boolean singleton​(int val)
      It checks if the domain contains only one value equal to c.
      int sizeConstraints()
      It returns current number of constraints which are associated with variable and are not yet satisfied.
      int sizeConstraintsOriginal()
      It returns all constraints which are associated with variable, even the ones which are already satisfied.
      int sizeSearchConstraints()
      It returns current number of constraints which are associated with variable and are not yet satisfied.
      java.lang.String toString()  
      java.lang.String toStringFull()
      It returns the string representation of the variable using the full representation of the domain.
      int value()
      This function returns current value in the domain of the variable.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • domain

        public IntDomain domain
        It stores pointer to a current domain, which has stamp equal to store stamp.
      • satBridge

        public SatCPBridge satBridge
        It stores information about the variable in SAT domain.
    • Constructor Detail

      • IntVar

        public IntVar​(Store store,
                      java.lang.String name,
                      IntDomain dom)
        It creates a variable in a given store, with a given name and a given domain.
        Parameters:
        store - store in which the variable is created.
        name - the name for the variable being created.
        dom - the domain of the variable being created.
      • IntVar

        public IntVar​(Store store,
                      IntDomain dom)
        It creates a variable in a given store, with a given name and a given domain.
        Parameters:
        store - store in which the variable is created.
        dom - the domain of the variable being created.
      • IntVar

        public IntVar()
        No parameter, explicit, empty constructor for subclasses.
      • IntVar

        public IntVar​(Store store)
        This constructor creates a variable with empty domain (standard IntervalDomain domain), automatically generated name, and empty attached constraint list.
        Parameters:
        store - store in which the variable is created.
      • IntVar

        public IntVar​(Store store,
                      int min,
                      int max)
        This constructor creates a variable with a domain between min..max, automatically generated name, and empty attached constraint list.
        Parameters:
        store - store in which the variable is created.
        min - the minimum value of the domain.
        max - the maximum value of the domain.
      • IntVar

        public IntVar​(Store store,
                      java.lang.String name)
        This constructor creates a variable with an empty domain (standard IntervalDomain domain), the specified name, and an empty attached constraint list.
        Parameters:
        store - store in which the variable is created.
        name - the name for the variable being created.
      • IntVar

        public IntVar​(Store store,
                      java.lang.String name,
                      int min,
                      int max)
        This constructor creates a variable in a given store, with the domain specified by min..max and with the given name.
        Parameters:
        store - the store in which the variable is created.
        name - the name of the variable being created.
        min - the minimum value of the variables domain.
        max - the maximum value of the variables domain.
    • Method Detail

      • commonInitialization

        private void commonInitialization​(Store store,
                                          java.lang.String name,
                                          IntDomain dom)
      • addDom

        public void addDom​(int min,
                           int max)
        It is possible to add the domain of variable. It should be used with care, only right after variable was created and before it is used in constraints or search. Current implementation requires domains being added in the increasing order (e.g. 1..5 before 9..10).
        Parameters:
        min - the left bound of the interval being added.
        max - the right bound of the interval being added.
      • setDomain

        public void setDomain​(int min,
                              int max)
        It is possible to set the domain of variable. It should be used with care, only right after variable was created and before it is used in constraints or search.
        Parameters:
        min - the left bound of the interval used to set this variable domain to.
        max - the right bound of the interval used to set this variable domain to.
      • value

        public int value()
        This function returns current value in the domain of the variable. If current domain of variable is not singleton then warning is printed and minimal value is returned.
        Returns:
        the value to which the variable has been grounded to.
      • singleton

        public boolean singleton​(int val)
        It checks if the domain contains only one value equal to c.
        Parameters:
        val - value to which we compare the singleton of the variable.
        Returns:
        true if a variable domain is singleton and it is equal to the specified value.
      • max

        public int max()
        This function returns current maximal value in the domain of the variable.
        Returns:
        the maximum value belonging to the domain.
      • min

        public int min()
        This function returns current minimal value in the domain of the variable.
        Returns:
        the minimum value beloning to the domain.
      • setDomain

        public void setDomain​(IntDomain dom)
        It is possible to set the domain of variable. It should be used with care, only right after variable was created and before it is used in constraints or search.
        Parameters:
        dom - domain to which the current variable domain is set to.
      • addDom

        public void addDom​(IntDomain dom)
        It is possible to add the domain of variable. It should be used with care, only right after variable was created and before it is used in constraints or search.
        Parameters:
        dom - the added domain.
      • dom

        public IntDomain dom()
        This function returns current domain of the variable.
        Specified by:
        dom in class Var
        Returns:
        the domain of the variable.
      • eq

        public boolean eq​(IntVar var)
        It checks if the domains of variables are equal.
        Parameters:
        var - the variable to which current variable is compared to.
        Returns:
        true if both variables have the same domain.
      • getSize

        public int getSize()
        It returns the size of the current domain.
        Specified by:
        getSize in class Var
        Returns:
        the size of the variables domain.
      • getSizeFloat

        public double getSizeFloat()
        It returns the size of the current domain.
        Specified by:
        getSizeFloat in class Var
        Returns:
        the size of the variables domain.
      • isEmpty

        public boolean isEmpty()
        It checks if the domain is empty.
        Specified by:
        isEmpty in class Var
        Returns:
        true if variable domain is empty.
      • putModelConstraint

        public void putModelConstraint​(Constraint c,
                                       int pruningEvent)
        It registers constraint with current variable, so anytime this variable is changed the constraint is reevaluated. Pruning events constants from 0 to n, where n is the strongest pruning event.
        Specified by:
        putModelConstraint in class Var
        Parameters:
        c - the constraint which is being attached to the variable.
        pruningEvent - type of the event which must occur to trigger the execution of the consistency function.
      • putSearchConstraint

        public void putSearchConstraint​(Constraint c)
        It registers constraint with current variable, so always when this variable is changed the constraint is reevaluated.
        Specified by:
        putSearchConstraint in class Var
        Parameters:
        c - the constraint which is added as a search constraint.
      • recentDomainPruning

        public IntDomain recentDomainPruning()
        It returns the values which have been removed at current store level. It does _not_ return the recent pruning in between the calls to that function.
        Returns:
        difference between the current level and the one before it.
      • removeConstraint

        public void removeConstraint​(Constraint c)
        It detaches constraint from the current variable, so change in variable will not cause constraint reevaluation. It is only removed from the current level onwards. Removing current level at later stage will automatically re-attached the constraint to the variable.
        Specified by:
        removeConstraint in class Var
        Parameters:
        c - the constraint being detached from the variable.
      • singleton

        public boolean singleton()
        It checks if the domain contains only one value.
        Specified by:
        singleton in class Var
        Returns:
        true if the variable domain is a singleton, false otherwise.
      • sizeConstraints

        public int sizeConstraints()
        It returns current number of constraints which are associated with variable and are not yet satisfied.
        Specified by:
        sizeConstraints in class Var
        Returns:
        number of constraints attached to the variable.
      • sizeConstraintsOriginal

        public int sizeConstraintsOriginal()
        It returns all constraints which are associated with variable, even the ones which are already satisfied.
        Specified by:
        sizeConstraintsOriginal in class Var
        Returns:
        number of constraints attached at the earliest level of the variable.
      • sizeSearchConstraints

        public int sizeSearchConstraints()
        It returns current number of constraints which are associated with variable and are not yet satisfied.
        Specified by:
        sizeSearchConstraints in class Var
        Returns:
        number of attached search constraints.
      • level

        public int level()
        This function returns stamp of the current domain of variable. It is equal or smaller to the stamp of store. Larger difference indicates that variable has been changed for a longer time.
        Specified by:
        level in interface Backtrackable
        Specified by:
        level in class Var
        Returns:
        level for which the most recent changes have been applied to.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toStringFull

        public java.lang.String toStringFull()
        It returns the string representation of the variable using the full representation of the domain.
        Specified by:
        toStringFull in class Var
        Returns:
        string representation.
      • remove

        public void remove​(int removedLevel)
        Description copied from interface: Backtrackable
        It specifies the function being called by the manager upon backtracking. The manager may call this function for the objects which have not changed but it must call this function for all objects that have changed.
        Parameters:
        removedLevel - level that is being removed.
      • domainHasChanged

        public void domainHasChanged​(int event)
        It informs the variable that its variable has changed according to the specified event.
        Specified by:
        domainHasChanged in class Var
        Parameters:
        event - the type of the change (GROUND, BOUND, ANY).
      • putConstraint

        public void putConstraint​(Constraint c)
        Description copied from class: Var
        It registers constraint with current variable, so anytime this variable is changed the constraint is reevaluated.
        Specified by:
        putConstraint in class Var
        Parameters:
        c - the constraint being attached to this variable.