kodkod.instance
Class Instance

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

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

Represents a model (an instance) of a relational formula, which is a mapping from relations and integers to sets of tuples drawn from a given universe.

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

Constructor Summary
Instance(Universe universe)
          Constructs an empty instance over the given universe
 
Method Summary
 void add(int i, TupleSet s)
          Maps the given integer to the given tuple set.
 void add(Relation relation, TupleSet s)
          Maps the given relation to the given tuple set.
 Instance clone()
          Returns a deep copy of this Instance object.
 boolean contains(int i)
          Returns true if this instance maps the given integer to a singleton tupleset; otherwise returns false.
 boolean contains(Relation relation)
          Returns true if this instance maps the given relation to a set of tuples; otherwise returns false.
 IntSet ints()
          Returns the integers mapped by this instance.
 SparseSequence<TupleSet> intTuples()
          Returns a sparse sequence view of int<:this.tuples.
 java.util.Set<Relation> relations()
          Returns the relations mapped by this instance.
 java.util.Map<Relation,TupleSet> relationTuples()
          Returns a map view of Relation<:this.tuples.
 java.lang.String toString()
          
 TupleSet tuples(int i)
          Returns the set of tuples assigned to the given integer by this Instance.
 TupleSet tuples(Relation relation)
          Returns the set of tuples assigned to the given relation by this Instance.
 Universe universe()
          Returns the universe from which the tuples in this instance are drawn.
 Instance unmodifiableView()
          Returns an unmodifiable view of this instance.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Instance

public Instance(Universe universe)
Constructs an empty instance over the given universe

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

universe

public Universe universe()
Returns the universe from which the tuples in this instance are drawn.

Returns:
this.universe

contains

public boolean contains(Relation relation)
Returns true if this instance maps the given relation to a set of tuples; otherwise returns false.

Returns:
r in this.relations

contains

public boolean contains(int i)
Returns true if this instance maps the given integer to a singleton tupleset; otherwise returns false.

Returns:
some this.tuples[i]

relations

public java.util.Set<Relation> relations()
Returns the relations mapped by this instance. The returned set does not support addition. It supports remval if this is not an unmodifiable instance.

Returns:
this.relations

ints

public IntSet ints()
Returns the integers mapped by this instance. The returned set does not support addition. It supports remval if this is not an unmodifiable instance.

Returns:
this.ints.TupleSet

add

public void add(Relation relation,
                TupleSet s)
Maps the given relation to the given tuple set.

Throws:
java.lang.NullPointerException - - relation = null || s = null
java.lang.IllegalArgumentException - - relation.arity != s.arity
java.lang.IllegalArgumentException - - s.universe != this.universe
java.lang.UnsupportedOperationException - - this is an unmodifiable instance
effects:
this.tuples' = this.tuples ++ relation->s

add

public void add(int i,
                TupleSet s)
Maps the given integer to the given tuple set.

Throws:
java.lang.NullPointerException - - s = null
java.lang.IllegalArgumentException - - s.arity != 1 || s.size() != 1
java.lang.IllegalArgumentException - - s.universe != this.universe
java.lang.UnsupportedOperationException - - this is an unmodifiable instance
effects:
this.tuples' = this.tuples ++ i->s

tuples

public TupleSet tuples(Relation relation)
Returns the set of tuples assigned to the given relation by this Instance. If the relation is not mapped by the model, null is returned.

Returns:
this.tuples[relation]

relationTuples

public java.util.Map<Relation,TupleSet> relationTuples()
Returns a map view of Relation<:this.tuples. The returned map is unmodifiable.

Returns:
a map view of Relation<:this.tuples.

tuples

public TupleSet tuples(int i)
Returns the set of tuples assigned to the given integer by this Instance. If the integer is not mapped by the model, null is returned.

Returns:
this.tuples[i]

intTuples

public SparseSequence<TupleSet> intTuples()
Returns a sparse sequence view of int<:this.tuples. The returned sequence is unmodifiable.

Returns:
a sparse sequence view of int<:this.tuples.

unmodifiableView

public Instance unmodifiableView()
Returns an unmodifiable view of this instance.

Returns:
an unmodifiable view of this instance.

clone

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

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

toString

public java.lang.String toString()

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