kodkod.instance
Class Bounds

java.lang.Object
  extended by kodkod.instance.Bounds
All Implemented Interfaces:
java.lang.Cloneable

public final class Bounds
extends java.lang.Object
implements java.lang.Cloneable

A Bounds object maps a relation r to two sets of tuples, rL and rU, which represent the lower and upper bounds on the set of tuples to which an instance based on these bounds may map r. The set rL represents all the tuples that a given relation must contain. The set rU represents all the tuples that a relation may contain. All bounding sets range over the same universe.

A Bounds object also maps integers to singleton tupleset that represent them. A tupleset may represent more than one integer, but an integer is represented by at most one tupleset.

Author:
Emina Torlak
invariant:
all i: intBound.TupleSet | intBound[i].size() = 1 && intBound[i].arity() = 1
lowerBound[relations].universe = upperBound[relations].universe = universe
all r: relations | lowerBound[r].arity = upperBound[r].arity = r.arity
all r: relations | lowerBound[r].tuples in upperBound[r].tuples
specfield:
universe: Universe
relations: set Relation
intBound: int -> lone TupleSet
lowerBound: relations -> one TupleSet
upperBound: relations -> one TupleSet

Constructor Summary
Bounds(Universe universe)
          Constructs new Bounds over the given universe.
 
Method Summary
 void bound(Relation r, TupleSet upper)
          Makes the specified tupleset the upper bound on the contents of the given relation.
 void bound(Relation r, TupleSet lower, TupleSet upper)
          Sets the lower and upper bounds for the given relation.
 void boundExactly(int i, TupleSet ibound)
          Makes the specified tupleset an exact bound on the relational value that corresponds to the given integer.
 void boundExactly(Relation r, TupleSet tuples)
          Sets both the lower and upper bounds of the given relation to the given set of tuples.
 Bounds clone()
          Returns a deep copy of this Bounds object.
 TupleSet exactBound(int i)
          Returns the set of tuples representing the given integer.
 SparseSequence<TupleSet> intBounds()
          Returns a sparse sequence view of this.intBound.
 IntSet ints()
          Returns the set of all integers bound by this Bounds.
 TupleSet lowerBound(Relation r)
          Returns the set of tuples that r must contain (the lower bound on r's contents).
 java.util.Map<Relation,TupleSet> lowerBounds()
          Returns a map view of this.lowerBound.
 java.util.Set<Relation> relations()
          Returns the set of all relations bound by this Bounds.
 java.lang.String toString()
           
 Universe universe()
          Returns this.universe.
 Bounds unmodifiableView()
          Returns an unmodifiable view of this Bounds object.
 TupleSet upperBound(Relation r)
          Returns the set of tuples that r may contain (the upper bound on r's contents).
 java.util.Map<Relation,TupleSet> upperBounds()
          Returns a map view of this.upperBound.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Bounds

public Bounds(Universe universe)
Constructs new Bounds over the given universe.

Throws:
java.lang.NullPointerException - - universe = null
effects:
this.universe' = universe && no this.relations' && no this.intBound'
Method Detail

universe

public Universe universe()
Returns this.universe.

Returns:
this.universe

relations

public java.util.Set<Relation> relations()
Returns the set of all relations bound by this Bounds. The returned set does not support the add operation. It supports removal iff this is not an unmodifiable Bounds.

Returns:
this.relations

ints

public IntSet ints()
Returns the set of all integers bound by this Bounds. The returned set does not support the add operation. It supports removal iff this is not an unmodifiable Bounds.

Returns:
this.intBounds.TupleSet

lowerBound

public TupleSet lowerBound(Relation r)
Returns the set of tuples that r must contain (the lower bound on r's contents). If r is not mapped by this, null is returned.

Returns:
r in this.relations => lowerBound[r], null

lowerBounds

public java.util.Map<Relation,TupleSet> lowerBounds()
Returns a map view of this.lowerBound. The returned map is not modifiable.

Returns:
a map view of this.lowerBound

upperBound

public TupleSet upperBound(Relation r)
Returns the set of tuples that r may contain (the upper bound on r's contents). If r is not mapped by this, null is returned.

Returns:
r in this.relations => upperBound[r], null

upperBounds

public java.util.Map<Relation,TupleSet> upperBounds()
Returns a map view of this.upperBound. The returned map is not modifiable.

Returns:
a map view of this.upperBound

exactBound

public TupleSet exactBound(int i)
Returns the set of tuples representing the given integer. If i is not mapped by this, null is returned.

Returns:
this.intBound[i]

intBounds

public SparseSequence<TupleSet> intBounds()
Returns a sparse sequence view of this.intBound. The returned sequence is not modifiable.

Returns:
a sparse sequence view of this.intBound

boundExactly

public void boundExactly(Relation r,
                         TupleSet tuples)
Sets both the lower and upper bounds of the given relation to the given set of tuples.

Throws:
java.lang.NullPointerException - - r = null || tuples = null
java.lang.IllegalArgumentException - - tuples.arity != r.arity || tuples.universe != this.universe
effects:
this.relations' = this.relations + r this.lowerBound' = this.lowerBound' ++ r->tuples && this.upperBound' = this.lowerBound' ++ r->tuples
requires:
tuples.arity = r.arity && tuples.universe = this.universe

bound

public void bound(Relation r,
                  TupleSet lower,
                  TupleSet upper)
Sets the lower and upper bounds for the given relation.

Throws:
java.lang.NullPointerException - - r = null || lower = null || upper = null
java.lang.IllegalArgumentException - - lower.arity != r.arity || upper.arity != r.arity
java.lang.IllegalArgumentException - - lower.universe != this.universe || upper.universe != this.universe
java.lang.IllegalArgumentException - - lower.tuples !in upper.tuples
effects:
this.relations' = this.relations + r && this.lowerBound' = this.lowerBound ++ r->lower && this.upperBound' = this.upperBound ++ r->upper
requires:
lower.tuples in upper.tuples && lower.arity = upper.arity = r.arity && lower.universe = upper.universe = this.universe

bound

public void bound(Relation r,
                  TupleSet upper)
Makes the specified tupleset the upper bound on the contents of the given relation. The lower bound automatically becomen an empty tupleset with the same arity as the relation.

Throws:
java.lang.NullPointerException - - r = null || upper = null
java.lang.IllegalArgumentException - - upper.arity != r.arity || upper.universe != this.universe
effects:
this.relations' = this.relations + r this.lowerBound' = this.lowerBound ++ r->{s: TupleSet | s.universe = this.universe && s.arity = r.arity && no s.tuples} && this.upperBound' = this.upperBound ++ r->upper
requires:
upper.arity = r.arity && upper.universe = this.universe

boundExactly

public void boundExactly(int i,
                         TupleSet ibound)
Makes the specified tupleset an exact bound on the relational value that corresponds to the given integer.

Throws:
java.lang.NullPointerException - - ibound = null
java.lang.IllegalArgumentException - - ibound.arity != 1 || ibound.size() != 1
java.lang.IllegalArgumentException - - ibound.universe != this.universe
effects:
this.intBound' = this.intBound' ++ i -> ibound
requires:
ibound.arity = 1 && i.bound.size() = 1

unmodifiableView

public Bounds unmodifiableView()
Returns an unmodifiable view of this Bounds object.

Returns:
an unmodifiable view of his Bounds object.

clone

public Bounds clone()
Returns a deep copy of this Bounds object.

Overrides:
clone in class java.lang.Object
Returns:
a deep copy of this Bounds object.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()