edu.mit.sketch.ddg
Class Constraint

java.lang.Object
  |
  +--edu.mit.sketch.ddg.Constraint
Direct Known Subclasses:
LinePropertyConstraint, LineRelationshipConstraint

public abstract class Constraint
extends Object

This abstract class represents the constraints on primitives. It contains a data structure that stores all the pairs of primitives between which a constraint holds. It provides methods dealing with this data structure that apply to any kinds of constraints - like query whether a constraint is true or not. Subclasses should implement the methods that apply to particular constraints.

If the constraint represents a property instead of a relationship, the primitive will have a self loop in the constraint graph - the constraint holds between the primitive and itself.

Constraint.java Created: Sat Nov 21 18:26:00 2001


Field Summary
protected  ConstraintGraph m_constraintGraph
          ConstraintGraph is a hashtable.
 
Constructor Summary
Constraint()
          Constructs an empty constraint graph.
Constraint(HashMap primToGeomParts, Object o)
          Constructs the constraint graph from and example drawn by the user.
 
Method Summary
 void addHoldsBetween(Primitive p1, Primitive p2, double confidence, double relevance)
          Add an edge to the constraint graph
 double confidence(Primitive p1, Primitive p2)
          Return the confidence of the constraint Returns 0 if the edge is not present.
 ConstraintGraph constraintGraph()
          Returns the constraint graph
 Vector edgeList()
          Return the list primitive pairs for which this constraint holds.
 boolean holdsBetween(Primitive p1, Primitive p2)
          Returns true if the constraint holds between the given primitives.
 boolean holdsBetween(Primitive p1, Primitive p2, double confidenceThreshold)
          Returns true if the constraint holds between the given primitives with a given threshold on confidence
abstract  void inferConstraints(HashMap primToGeomParts)
          Infer the constraints from the users stroke geom parts and record the constraint graph.
abstract  String name()
          Name of the constraint type (for example "intersects").
 void print()
          Print constraint graph
 double relevance(Primitive p1, Primitive p2)
          Return the relevance of the constraint.
 void removeHoldsBetween(Primitive p1, Primitive p2)
          Remove an edge from the constraint graph
 void removeLowConfidence()
          Remove constraints that are below the LOW_CONFIDENCE_THRESHOLD in confidence
 void removeUncertain()
          Remove constraints that are below the UNCERTAIN_THRESHOLD in combined confidence and relevance
 void setConfidence(Primitive p1, Primitive p2, double confidence)
          Change the confidence of the constraint
 void setRelevance(Primitive p1, Primitive p2, double relevance)
          Change the relevance of the constraint
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_constraintGraph

protected ConstraintGraph m_constraintGraph
ConstraintGraph is a hashtable. The nodes (hash keys) are Primitives. The value for each key is a ConstraintGraphEdgeList of directed edges (ConstraintGraphEdge) to other Primitives. The edges have confidence [0;1] that the constraint holds in the drawn example, and the relevance of the constraint for the essence of the symbol.
Constructor Detail

Constraint

public Constraint()
Constructs an empty constraint graph. Subclasses should implement proper intialization.

Constraint

public Constraint(HashMap primToGeomParts,
                  Object o)
Constructs the constraint graph from and example drawn by the user. The example is passed as a mapping primitives to the geometric parts of the stroke that they originated from. Object o for passing extra information for initialization. Subclasses should implement proper intialization. HashMap: type of key: Primitive, type of value: GeometricObject
Method Detail

inferConstraints

public abstract void inferConstraints(HashMap primToGeomParts)
Infer the constraints from the users stroke geom parts and record the constraint graph. Subclasses should implement this method (HashMap: type of key: Primitive, type of value: GeometricObject)

name

public abstract String name()
Name of the constraint type (for example "intersects"). Subclasses should implement this method.

holdsBetween

public boolean holdsBetween(Primitive p1,
                            Primitive p2)
Returns true if the constraint holds between the given primitives. Note: For now it will return true if the edge exists, no matter what the confidence or the relevance is, so it only makes sense if we want hard decisions and we have filtered out the low confidence constraints (function removeUncertain())

holdsBetween

public boolean holdsBetween(Primitive p1,
                            Primitive p2,
                            double confidenceThreshold)
Returns true if the constraint holds between the given primitives with a given threshold on confidence

constraintGraph

public ConstraintGraph constraintGraph()
Returns the constraint graph

print

public void print()
Print constraint graph

removeUncertain

public void removeUncertain()
Remove constraints that are below the UNCERTAIN_THRESHOLD in combined confidence and relevance

removeLowConfidence

public void removeLowConfidence()
Remove constraints that are below the LOW_CONFIDENCE_THRESHOLD in confidence

removeHoldsBetween

public void removeHoldsBetween(Primitive p1,
                               Primitive p2)
Remove an edge from the constraint graph

addHoldsBetween

public void addHoldsBetween(Primitive p1,
                            Primitive p2,
                            double confidence,
                            double relevance)
Add an edge to the constraint graph

relevance

public double relevance(Primitive p1,
                        Primitive p2)
Return the relevance of the constraint. 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)
Change the relevance of the constraint

setConfidence

public void setConfidence(Primitive p1,
                          Primitive p2,
                          double confidence)
Change the confidence of the constraint

edgeList

public Vector edgeList()
Return the list primitive pairs for which this constraint holds. Returns the list od Map.Entry's where the key is the first primitive and the value is the outgoing edge to the second primitive.