Module org.maxicp

Class StateTriPartition

java.lang.Object
org.maxicp.state.datastructures.StateTriPartition

public class StateTriPartition extends Object
Tri-partition sparse-set data structure that can be saved and restored through the StateManager.saveState() / StateManager.restoreState() methods. The three partitions are the included (I), possible (P) and excluded (E) values. Initially all the elements are in the possible set and those can only be moved to the possible and excluded partitions.
  • Field Details

    • elems

      protected int[] elems
    • elemPos

      protected int[] elemPos
    • i

      protected StateInt i
    • p

      protected StateInt p
    • n

      protected int n
    • ofs

      protected int ofs
    • nOmitted

      protected int nOmitted
  • Constructor Details

    • StateTriPartition

      public StateTriPartition(StateManager sm, int n)
      Creates a tri-partition with the elements {I : {}, P: {0,...,n-1}, E: {}}.
      Parameters:
      sm - the state manager that will save and restore the set when StateManager.saveState() / StateManager.restoreState() methods are called.
      n - number of elements within the set.
    • StateTriPartition

      public StateTriPartition(StateManager sm, int minInclusive, int maxInclusive)
      Creates a tri-partition with the elements {I : {}, P: {min,...,max}, E: {}}.
      Parameters:
      sm - the state manager that will save and restore the set when StateManager.saveState() / StateManager.restoreState() methods are called.
      minInclusive - minimum value of the partition
      maxInclusive - maximum value of the partition with maxInclusive >= minInclusive
    • StateTriPartition

      public StateTriPartition(StateManager sm, Set<Integer> values)
      Creates a tri-partition with the elements {R : {}, P: values, E: {}}
      Parameters:
      sm - the state manager that will save and restore the set when StateManager.saveState() / StateManager.restoreState() methods are called.
      values - the initial values for the possible partition P
  • Method Details

    • exclude

      public boolean exclude(int val)
      Moves a value from the set of possible values P to the set of excluded values E.
      Parameters:
      val - the value to move to the excluded set E
      Returns:
      true if the value has been moved from the set of possible P to the set of excluded, false otherwise and the method has no effect in this case.
    • include

      public boolean include(int val)
      Moves a value from the possible partition P to the included partition I.
      Parameters:
      val - the value to mark as included
      Returns:
      true if the value has been moved from the set of possible P to the set of included I, false otherwise and the method has no effect in this case.
    • includeAndExcludeOthers

      public boolean includeAndExcludeOthers(int v)
      Sets the specified value as the only included one and move all others into the exclusion partition.
      Parameters:
      v - unique value that will be contained in the included partition.
      Returns:
      true if the included partition was empty and the value was possible, false otherwise and the method has no effect.
    • excludeAllPossible

      public boolean excludeAllPossible()
      Moves all possible values into the set of excluded values.
      Returns:
      true if the partition of possible values has been reduced
    • excludeAll

      public void excludeAll()
      Moves all values, also the included ones into the set of excluded values.
    • includeAllPossible

      public boolean includeAllPossible()
      Moves all possible values into the set of included values.
      Returns:
      true if the partition of possible values has been reduced
    • isIncluded

      public boolean isIncluded(int val)
      Tells if the specified value belongs to the included partition I.
      Parameters:
      val - the value to test.
      Returns:
      true if val belongs to the included partition I.
    • isExcluded

      public boolean isExcluded(int val)
      Tells if the specified value belongs to the excluded partition E.
      Parameters:
      val - the value to test.
      Returns:
      true if val belongs to the included partition I.
    • isPossible

      public boolean isPossible(int val)
    • contains

      public boolean contains(int val)
      tell if a value belongs to the domain
      Parameters:
      val - value to train1
      Returns:
      true if the value is either included, possible or excluded
    • nPossible

      public int nPossible()
    • nExcluded

      public int nExcluded()
    • nIncluded

      public int nIncluded()
    • size

      public int size()
    • fillIncluded

      public int fillIncluded(int[] dest)
    • fillIncluded

      public int fillIncluded(int[] dest, Predicate<Integer> filterPredicate)
      Sets the first values of dest to the included ones that also satisfy the given filter predicate
      Parameters:
      dest - , an array large enough dest.length >= size()
      filterPredicate - the predicate, only elements for which the predicate is true are kept
      Returns:
      the size of the included set of elements satisfying the predicate
    • fillPossible

      public int fillPossible(int[] dest)
    • fillPossible

      public int fillPossible(int[] dest, Predicate<Integer> filterPredicate)
      Sets the first values of dest to the possible ones that also satisfy the given filter predicate
      Parameters:
      dest - , an array large enough dest.length >= size()
      filterPredicate - the predicate, only elements for which the predicate is true are kept
      Returns:
      the size of the possible set of elements satisfying the predicate
    • fillIncludedAndPossible

      public int fillIncludedAndPossible(int[] dest)
    • fillIncludedAndPossible

      public int fillIncludedAndPossible(int[] dest, Predicate<Integer> filterPredicate)
      Sets the first values of dest to the included and possible ones that also satisfy the given filter predicate
      Parameters:
      dest - , an array large enough dest.length >= size()
      filterPredicate - the predicate, only elements for which the predicate is true are kept
      Returns:
      the size of the included and possible set of elements satisfying the predicate
    • fillExcluded

      public int fillExcluded(int[] dest)
    • toString

      public String toString()
      Overrides:
      toString in class Object