edu.mit.sketch.ddg
Class ConstraintGraph

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable
          extended by edu.mit.sketch.ddg.ConstraintGraph
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map

public class ConstraintGraph
extends java.util.Hashtable
implements java.io.Serializable

A hashtable that stores the graph for a constraint of a particular type (like "connects"). If a constraint holds between to primitives (nodes in the graph), there will be an edge (ConstraintGraphEdge) between them. The edge also stores the confidence that the constraint holds and the importance of the constraint. The keys of the Hashtable are Primitives and the values are a list of outgoing directed edges (ConstraintGraphEdgeList).

Note: If the constraint is just a property of one primitive, it will have a self loop in the constraint graph.
If a primitive does not participate in the constraint at all, it will not be in the hashtable. Classes that use this graph should also be careful to maintain this property.

ConstraintGraph.java Created: Mon Feb 11 10:40:00 2002

Author:
Olya Veselova
See Also:
Serialized Form

Constructor Summary
ConstraintGraph()
           
 
Method Summary
 void addEdge(ConstraintGraphEdge edge)
          Add an edge between two given primitives.
 void addEdge(Primitive p1, Primitive p2, double confidence, double relevance)
          Add an edge between two given primitives.
 java.lang.Object clone()
          Clone the graph
 double confidence(Primitive p1, Primitive p2)
          Return the confidence of the constraint.
 boolean containsEdge(Primitive p1, Primitive p2)
          Returns true if the graph contains an edge between the given primitives.
 ConstraintGraphEdgeList edgeList()
          Return the list of edges in the current constraint graph.
 ConstraintGraphEdgeList edgeList(Constraint constraint)
          Return the list of edges in the current constraint graph labelled with the name of a constraint.
 ConstraintGraphEdge getEdge(Primitive p1, Primitive p2)
          Get edge between the two given primitives.
 ConstraintGraphEdgeList getIncomingEdges(Primitive p2)
          Get the list of incoming edges for a given primitive.
 ConstraintGraphEdgeList getOutgoingEdges(Primitive p1)
          Get the list of outgoing edges for a given primitive.
 PrimitiveList primitiveList()
          Return the list of primitives in the current constraint graph.
 void print(java.io.PrintStream out, boolean printDetails)
          Print the constraint graph to the given output stream.
 double relevance(Primitive p1, Primitive p2)
          Return the relevance of the constraint between two given primitives.
 boolean removeEdge(Primitive p1, Primitive p2)
          Remove and edge between two given primitives and return true.
 boolean sameAs(ConstraintGraph other, PrimitiveMapping mapping)
          Verifies whether this constraint is the same as the other one given the mapping between primitives.
 void setConfidence(Primitive p1, Primitive p2, double confidence)
          Change the confidence of the constraint between two given primitives.
 void setRelevance(Primitive p1, Primitive p2, double relevance)
          Change the relevance of the constraint between two given primitives.
 
Methods inherited from class java.util.Hashtable
clear, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, remove, size, toString, values
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConstraintGraph

public ConstraintGraph()
Method Detail

getOutgoingEdges

public ConstraintGraphEdgeList getOutgoingEdges(Primitive p1)
                                         throws PrimitiveNotFoundException
Get the list of outgoing edges for a given primitive. Throws an exception if the primitive is not found.

Throws:
PrimitiveNotFoundException

getIncomingEdges

public ConstraintGraphEdgeList getIncomingEdges(Primitive p2)
                                         throws PrimitiveNotFoundException
Get the list of incoming edges for a given primitive. Throws an exception if the primitive is not found.

Throws:
PrimitiveNotFoundException

getEdge

public ConstraintGraphEdge getEdge(Primitive p1,
                                   Primitive p2)
                            throws EdgeNotFoundException
Get edge between the two given primitives. Throws an exception if the edge is not found.

Throws:
EdgeNotFoundException

addEdge

public void addEdge(Primitive p1,
                    Primitive p2,
                    double confidence,
                    double relevance)
Add an edge between two given primitives.


addEdge

public void addEdge(ConstraintGraphEdge edge)
Add an edge between two given primitives.


removeEdge

public boolean removeEdge(Primitive p1,
                          Primitive p2)
Remove and edge between two given primitives and return true. Return false if the edge is not there.


containsEdge

public boolean containsEdge(Primitive p1,
                            Primitive p2)
Returns true if the graph contains an edge between the given primitives.


print

public void print(java.io.PrintStream out,
                  boolean printDetails)
Print the constraint graph to the given output stream. Prints confidence and relevance if printDetails is specified.


relevance

public double relevance(Primitive p1,
                        Primitive p2)
Return the relevance of the constraint between two given primitives. Returns 0 if the edge is not present.


confidence

public double confidence(Primitive p1,
                         Primitive p2)
Return the confidence of the constraint. Returns 0 if the edge is not present.


setRelevance

public void setRelevance(Primitive p1,
                         Primitive p2,
                         double relevance)
                  throws EdgeNotFoundException
Change the relevance of the constraint between two given primitives. Throws an exception if the edge is not found.

Throws:
EdgeNotFoundException

setConfidence

public void setConfidence(Primitive p1,
                          Primitive p2,
                          double confidence)
                   throws EdgeNotFoundException
Change the confidence of the constraint between two given primitives. Throws an exception if the edge is not found.

Throws:
EdgeNotFoundException

edgeList

public ConstraintGraphEdgeList edgeList()
Return the list of edges in the current constraint graph. Returns an empty list if there are no edges.


edgeList

public ConstraintGraphEdgeList edgeList(Constraint constraint)
Return the list of edges in the current constraint graph labelled with the name of a constraint. Returns an empty list if there are no edges.


primitiveList

public PrimitiveList primitiveList()
Return the list of primitives in the current constraint graph. Returns an empty list if the graph is empty. Each primitive will appear only once in this list.


clone

public java.lang.Object clone()
Clone the graph

Overrides:
clone in class java.util.Hashtable

sameAs

public boolean sameAs(ConstraintGraph other,
                      PrimitiveMapping mapping)
Verifies whether this constraint is the same as the other one given the mapping between primitives. The first primitive in the mapping pair is from the other object and the second is from this.