java.lang.Object
org.maxicp.state.datastructures.StateTriPartition
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionStateTriPartition(StateManager sm, int n) Creates a tri-partition with the elements{I : {}, P: {0,...,n-1}, E: {}}.StateTriPartition(StateManager sm, int minInclusive, int maxInclusive) Creates a tri-partition with the elements{I : {}, P: {min,...,max}, E: {}}.StateTriPartition(StateManager sm, Set<Integer> values) Creates a tri-partition with the elements{R : {}, P: values, E: {}} -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(int val) tell if a value belongs to the domainbooleanexclude(int val) Moves a value from the set of possible values P to the set of excluded values E.voidMoves all values, also the included ones into the set of excluded values.booleanMoves all possible values into the set of excluded values.intfillExcluded(int[] dest) intfillIncluded(int[] dest) intfillIncluded(int[] dest, Predicate<Integer> filterPredicate) Sets the first values ofdestto the included ones that also satisfy the given filter predicateintfillIncludedAndPossible(int[] dest) intfillIncludedAndPossible(int[] dest, Predicate<Integer> filterPredicate) Sets the first values ofdestto the included and possible ones that also satisfy the given filter predicateintfillPossible(int[] dest) intfillPossible(int[] dest, Predicate<Integer> filterPredicate) Sets the first values ofdestto the possible ones that also satisfy the given filter predicatebooleaninclude(int val) Moves a value from the possible partition P to the included partition I.booleanMoves all possible values into the set of included values.booleanincludeAndExcludeOthers(int v) Sets the specified value as the only included one and move all others into the exclusion partition.booleanisExcluded(int val) Tells if the specified value belongs to the excluded partition E.booleanisIncluded(int val) Tells if the specified value belongs to the included partition I.booleanisPossible(int val) intintintintsize()toString()
-
Field Details
-
elems
protected int[] elems -
elemPos
protected int[] elemPos -
i
-
p
-
n
protected int n -
ofs
protected int ofs -
nOmitted
protected int nOmitted
-
-
Constructor Details
-
StateTriPartition
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 whenStateManager.saveState()/StateManager.restoreState()methods are called.n- number of elements within the set.
-
StateTriPartition
Creates a tri-partition with the elements{I : {}, P: {min,...,max}, E: {}}.- Parameters:
sm- the state manager that will save and restore the set whenStateManager.saveState()/StateManager.restoreState()methods are called.minInclusive- minimum value of the partitionmaxInclusive- maximum value of the partition withmaxInclusive >= minInclusive
-
StateTriPartition
Creates a tri-partition with the elements{R : {}, P: values, E: {}}- Parameters:
sm- the state manager that will save and restore the set whenStateManager.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
Sets the first values ofdestto the included ones that also satisfy the given filter predicate- Parameters:
dest- , an array large enoughdest.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
Sets the first values ofdestto the possible ones that also satisfy the given filter predicate- Parameters:
dest- , an array large enoughdest.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
Sets the first values ofdestto the included and possible ones that also satisfy the given filter predicate- Parameters:
dest- , an array large enoughdest.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
-