Class IntervalUnionSet
java.lang.Object
edu.udel.cis.vsl.sarl.simplify.common.IntervalUnionSet
- All Implemented Interfaces:
Range
Implementation of Range in which a set is represented as a finite
union of intervals. This class is immutable.
The following are invariants. They force there to be a unique representation for each set of numbers:
- All intervals in the array are non-
nullIntervals. - An empty interval cannot occur in the array.
- All of the intervals in the array are disjoint.
- The intervals in the array are ordered from least to greatest.
- If an interval has the form {a,+infty}, then it is open on the right. If an interval has the form {-infty,a}, then it is open on the left.
- If {a,b} and {b,c} are two consecutive intervals in the list, the first one must be open on the right and the second one must be open on the left.
- If the range set has integer type, all of the intervals are integer intervals. If it has real type, all of the intervals are real intervals. (All integral intervals are actually )
- If the range set has integer type, all of the intervals are closed, except for +infty and -infty.
-
Nested Class Summary
Nested classes/interfaces inherited from interface edu.udel.cis.vsl.sarl.simplify.IF.Range
Range.RangeSign -
Constructor Summary
ConstructorsConstructorDescriptionIntervalUnionSet(boolean isIntegral) Constructs anIntervalUnionSetrepresenting an empty setIntervalUnionSet(Interval interval) Constructs anIntervalUnionSetwith exactly oneInterval.IntervalUnionSet(Interval... intervals) Constructs anIntervalUnionSetwith an array ofIntervals.IntervalUnionSet(Number number) IntervalUnionSet(Number left, boolean strictLeft, Number right, boolean strictRight, boolean isIntegral) Constructs anIntervalUnionSetwith twoNumbers , two boolean representing whether the bound is closed or not, and one boolean showing whether theIntervalUnionSetis a integral one or not.IntervalUnionSet(IntervalUnionSet other) Constructs anIntervalnionSetbeing same withother. -
Method Summary
Modifier and TypeMethodDescriptionAdd a singleNumberto thisIntervalUnionSetIf this range is an interval, return the Interval representation, otherwise, returnsnull.booleanTo check all invariants ofthisIntervalUnionSetThose invariants are: 1.booleanIs this set a superset of the given one?booleancontainsNumber(Number number) Does this set contain the given number as a member?booleanIf this range represents a singleton set (a set consisting of exactly one Number), this method returns the value of its sole element; otherwise, returnsnull.inthashCode()booleanintersects(Range set) Is the intersection of this set with the given one nonempty?Get the over-approximatedIntervalofthisrange.Interval[]Get allIntervals contained inthisIntervalUnionSet;
Ifthisis an empty set, an array with size of zero will be returned.booleanisEmpty()Is this an empty set?booleanIs this an integer set?booleanIs this a universal set?sign()Get theRange.RangeSignofthisrange.symbolicRepresentation(NumericExpression x, PreUniverse universe) toString()
-
Constructor Details
-
IntervalUnionSet
public IntervalUnionSet(boolean isIntegral) Constructs anIntervalUnionSetrepresenting an empty set- Parameters:
isIntegral- A boolean value to represent whetherthisIntervalUnionSetis integral.
-
IntervalUnionSet
- Parameters:
number- a non-nullfiniteNumber
-
IntervalUnionSet
public IntervalUnionSet(Number left, boolean strictLeft, Number right, boolean strictRight, boolean isIntegral) Constructs anIntervalUnionSetwith twoNumbers , two boolean representing whether the bound is closed or not, and one boolean showing whether theIntervalUnionSetis a integral one or not. -
IntervalUnionSet
Constructs anIntervalUnionSetwith exactly oneInterval.- Parameters:
interval- a non-nullInterval.
-
IntervalUnionSet
Constructs anIntervalUnionSetwith an array ofIntervals.- Parameters:
intervals- an array ofIntervals (with at least one element) with same type (real/integer).
-
IntervalUnionSet
Constructs anIntervalnionSetbeing same withother.- Parameters:
other- A non-nullIntervalnionSetwould be copied.
-
-
Method Details
-
intervals
Get allIntervals contained inthisIntervalUnionSet;
Ifthisis an empty set, an array with size of zero will be returned.- Returns:
- An array of
Intervals
-
addNumber
Add a singleNumberto thisIntervalUnionSet- Parameters:
number- a single non-nullNumberof the same type (integer/real) with thisIntervalUnionSet
-
isIntegral
public boolean isIntegral()Description copied from interface:RangeIs this an integer set?- Specified by:
isIntegralin interfaceRange- Returns:
trueif this is a set of integers;falseif this is a set of reals
-
isEmpty
public boolean isEmpty()Description copied from interface:RangeIs this an empty set? -
isUniversal
public boolean isUniversal()Description copied from interface:RangeIs this a universal set?- Specified by:
isUniversalin interfaceRange- Returns:
trueiff this is a universal set
-
containsNumber
Description copied from interface:RangeDoes this set contain the given number as a member?- Specified by:
containsNumberin interfaceRange- Parameters:
number- any non-nullNumberof the same type (integer/real) as this set- Returns:
trueiff this set contains the given number
-
contains
Description copied from interface:RangeIs this set a superset of the given one? -
intersects
Description copied from interface:RangeIs the intersection of this set with the given one nonempty?- Specified by:
intersectsin interfaceRange- Parameters:
set- a number set of the same type (integer/real) as this one- Returns:
trueiff the intersection of the two sets is nonempty
-
symbolicRepresentation
Description copied from interface:RangeGiven aNumericExpressionx, returns aBooleanExpressionwhich holds iffxis inthisRange.Example: suppose
thisRangeis theInterval(0,1]. Givenx, this method will return aBooleanExpressionx>0 && x<=1.Example: (0,1] U [4,5]. Given
x, returns(x>0 && x<=1) || (x>=4 && x<=5).- Specified by:
symbolicRepresentationin interfaceRange- Parameters:
x- variable to use in the new expressionuniverse- symbolic universe used to construct the symbolic expression- Returns:
- a
BooleanExpressioninvolvingxwhich holds iffxis in this set
-
toString
-
checkInvariants
public boolean checkInvariants()To check all invariants ofthisIntervalUnionSetThose invariants are: 1. All of intervals in the array are non-nullintervals. 2. An empty interval cannot occur in the array. 3. All of the intervals in the array are disjoint. 4. The intervals in the array are ordered from least to greatest. 5. If an interval has the form {a,+infty}, then it is open on the right. If an interval has the form {-infty,a}, then it is open on the left. 6. If {a,b} and {b,c} are two consecutive intervals in the list, the the first one must be open on the right and the second one must be open on the left. 7. If the range set has integer type, all of the intervals are integer intervals. If it has real type, all of the intervals are real intervals. 8. If the range set has integer type, all of the intervals are closed, except for +infty and -infty.- Returns:
trueiff everyIntervalinthisset ensures invariants (Because allIntervalUnionSetconstructors would ensure those invariants, this function should always return the value of true)
-
getSingletonValue
Description copied from interface:RangeIf this range represents a singleton set (a set consisting of exactly one Number), this method returns the value of its sole element; otherwise, returnsnull.- Specified by:
getSingletonValuein interfaceRange- Returns:
- The exact
Numberrepresented bythisRange, ifthisrange represents a singleton number;
otherwise, it will returnnull.
-
asInterval
Description copied from interface:RangeIf this range is an interval, return the Interval representation, otherwise, returnsnull.- Specified by:
asIntervalin interfaceRange- Returns:
- The exact
Intervalrepresented bythisRange, ifthisrange represents a singleton interval;
otherwise, it will returnnull.
-
hashCode
public int hashCode() -
sign
Description copied from interface:RangeGet theRange.RangeSignofthisrange. -
intervalOverApproximation
Description copied from interface:RangeGet the over-approximatedIntervalofthisrange. (E.g., for an integral range consisting of [-1, 0), [3, 6) and [6, 10); the actual range should be [-1, -1] U [3, 9]; and its over-approximation range should be [-1, 9].)- Specified by:
intervalOverApproximationin interfaceRange- Returns:
- the over-approximation
Intervalofthis
-
equals
-