Class IntervalUnionSet

java.lang.Object
edu.udel.cis.vsl.sarl.simplify.common.IntervalUnionSet
All Implemented Interfaces:
Range

public class IntervalUnionSet extends Object implements 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:

  1. All intervals in the array are non-null Intervals.
  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 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. (All integral intervals are actually )
  8. If the range set has integer type, all of the intervals are closed, except for +infty and -infty.

  • Constructor Details

    • IntervalUnionSet

      public IntervalUnionSet(boolean isIntegral)
      Constructs an IntervalUnionSet representing an empty set
      Parameters:
      isIntegral - A boolean value to represent whether this IntervalUnionSet is integral.
    • IntervalUnionSet

      public IntervalUnionSet(Number number)
      Constructs an IntervalUnionSet with exactly one Interval containing exactly one Number.
      Parameters:
      number - a non-null finite Number
    • IntervalUnionSet

      public IntervalUnionSet(Number left, boolean strictLeft, Number right, boolean strictRight, boolean isIntegral)
      Constructs an IntervalUnionSet with two Numbers , two boolean representing whether the bound is closed or not, and one boolean showing whether the IntervalUnionSet is a integral one or not.
      Parameters:
      left - a non-null Number
      strictLeft - a boolean value
      right - a non-null Number
      rightstrict - a boolean value
      isIntegral - a boolean value
    • IntervalUnionSet

      public IntervalUnionSet(Interval interval)
      Constructs an IntervalUnionSet with exactly one Interval.
      Parameters:
      interval - a non-null Interval.
    • IntervalUnionSet

      public IntervalUnionSet(Interval... intervals)
      Constructs an IntervalUnionSet with an array of Interval s.
      Parameters:
      intervals - an array of Intervals (with at least one element) with same type (real/integer).
    • IntervalUnionSet

      public IntervalUnionSet(IntervalUnionSet other)
      Constructs an IntervalnionSet being same with other.
      Parameters:
      other - A non-null IntervalnionSet would be copied.
  • Method Details

    • intervals

      public Interval[] intervals()
      Get all Intervals contained in this IntervalUnionSet;
      If this is an empty set, an array with size of zero will be returned.
      Returns:
      An array of Intervals
    • addNumber

      public Range addNumber(Number number)
      Add a single Number to this IntervalUnionSet
      Parameters:
      number - a single non-null Number of the same type (integer/real) with this IntervalUnionSet
    • isIntegral

      public boolean isIntegral()
      Description copied from interface: Range
      Is this an integer set?
      Specified by:
      isIntegral in interface Range
      Returns:
      true if this is a set of integers; false if this is a set of reals
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Range
      Is this an empty set?
      Specified by:
      isEmpty in interface Range
      Returns:
      true iff this is an empty set
    • isUniversal

      public boolean isUniversal()
      Description copied from interface: Range
      Is this a universal set?
      Specified by:
      isUniversal in interface Range
      Returns:
      true iff this is a universal set
    • containsNumber

      public boolean containsNumber(Number number)
      Description copied from interface: Range
      Does this set contain the given number as a member?
      Specified by:
      containsNumber in interface Range
      Parameters:
      number - any non-null Number of the same type (integer/real) as this set
      Returns:
      true iff this set contains the given number
    • contains

      public boolean contains(Range set)
      Description copied from interface: Range
      Is this set a superset of the given one?
      Specified by:
      contains in interface Range
      Parameters:
      set - a number set of the same type (integer/real) as this one
      Returns:
      true iff this one contains the given one
    • intersects

      public boolean intersects(Range set)
      Description copied from interface: Range
      Is the intersection of this set with the given one nonempty?
      Specified by:
      intersects in interface Range
      Parameters:
      set - a number set of the same type (integer/real) as this one
      Returns:
      true iff the intersection of the two sets is nonempty
    • symbolicRepresentation

      public BooleanExpression symbolicRepresentation(NumericExpression x, PreUniverse universe)
      Description copied from interface: Range
      Given a NumericExpression x, returns a BooleanExpression which holds iff x is in this Range.

      Example: suppose this Range is the Interval (0,1]. Given x, this method will return a BooleanExpression x>0 && x<=1.

      Example: (0,1] U [4,5]. Given x, returns (x>0 && x<=1) || (x>=4 && x<=5).

      Specified by:
      symbolicRepresentation in interface Range
      Parameters:
      x - variable to use in the new expression
      universe - symbolic universe used to construct the symbolic expression
      Returns:
      a BooleanExpression involving x which holds iff x is in this set
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • checkInvariants

      public boolean checkInvariants()
      To check all invariants of this IntervalUnionSet Those invariants are: 1. All of intervals in the array are non-null intervals. 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:
      true iff every Interval in this set ensures invariants (Because all IntervalUnionSet constructors would ensure those invariants, this function should always return the value of true)
    • getSingletonValue

      public Number getSingletonValue()
      Description copied from interface: Range
      If this range represents a singleton set (a set consisting of exactly one Number), this method returns the value of its sole element; otherwise, returns null.
      Specified by:
      getSingletonValue in interface Range
      Returns:
      The exact Number represented by this Range, if this range represents a singleton number;
      otherwise, it will return null.
    • asInterval

      public Interval asInterval()
      Description copied from interface: Range
      If this range is an interval, return the Interval representation, otherwise, returns null.
      Specified by:
      asInterval in interface Range
      Returns:
      The exact Interval represented by this Range, if this range represents a singleton interval;
      otherwise, it will return null.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • sign

      public Range.RangeSign sign()
      Description copied from interface: Range
      Get the Range.RangeSign of this range.
      Specified by:
      sign in interface Range
      Returns:
    • intervalOverApproximation

      public Interval intervalOverApproximation()
      Description copied from interface: Range
      Get the over-approximated Interval of this range. (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:
      intervalOverApproximation in interface Range
      Returns:
      the over-approximation Interval of this
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object