jpaul.Constraints
Class CtConstraint<V extends Var<Info>,Info>

java.lang.Object
  extended by jpaul.Constraints.Constraint<V,Info>
      extended by jpaul.Constraints.CtConstraint<V,Info>

public final class CtConstraint<V extends Var<Info>,Info>
extends Constraint<V,Info>

CtConstraint models a constraint of the form "constant ct is less than the value of the variable vd". This order is implicitly given by the join operation of the variable vd. The constant ct must have the same type as the values of vd.

Version:
$Id: CtConstraint.java,v 1.7 2005/08/12 18:44:58 salcianu Exp $
Author:
Alexandru Salcianu - salcianu@alum.mit.edu

Field Summary
 Info ct
           
 V vd
           
 
Fields inherited from class jpaul.Constraints.Constraint
AVG_COST, HIGH_COST, LOW_COST, VERY_LOW_COST
 
Constructor Summary
CtConstraint(Info ct, V vd)
          Creates a LtConstraint with default cost Constraint.VERY_LOW_COST.
CtConstraint(Info ct, V vd, int cost)
          Creates a CtConstraint with the meaning "the constant ct is smaller than the value of the variable vd."
 
Method Summary
 void action(SolAccessor<V,Info> sa)
          Performs the action attached to this constraint.
 int cost()
          Returns a rough estimate of the evaluation cost of this constraint.
 boolean equals(java.lang.Object o)
           
 int hashCode()
           
 java.util.Collection<V> in()
           
 java.util.Collection<V> out()
           
 Constraint<V,Info> rewrite(DisjointSet<V> uf)
          Rewrites this constraint by replacing each variable with the representative of its equivalence class.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ct

public final Info ct

vd

public final V extends Var<Info> vd
Constructor Detail

CtConstraint

public CtConstraint(Info ct,
                    V vd)
Creates a LtConstraint with default cost Constraint.VERY_LOW_COST.


CtConstraint

public CtConstraint(Info ct,
                    V vd,
                    int cost)
Creates a CtConstraint with the meaning "the constant ct is smaller than the value of the variable vd."

Parameters:
cost - Relative cost of this constraint.
Method Detail

cost

public int cost()
Description copied from class: Constraint
Returns a rough estimate of the evaluation cost of this constraint. This cost has only a relative meaning: e.g., a constraint is more/less costly than another. A constraint solver may choose to iterate first over the cheap constraints, and only next iterate over the other, more expensive constraints. The cost should influence only the speed, not the correctness: the solution of a system of constraints should satisfy all constraints, regardless of their cost.

By default, it returns AVG_COST.

Overrides:
cost in class Constraint<V extends Var<Info>,Info>

in

public java.util.Collection<V> in()
Specified by:
in in class Constraint<V extends Var<Info>,Info>
Returns:
List of variables whose values may be read in order to construct the values of the outputs.

out

public java.util.Collection<V> out()
Specified by:
out in class Constraint<V extends Var<Info>,Info>
Returns:
List of variables whose values may be affected by this constraint.

action

public void action(SolAccessor<V,Info> sa)
Description copied from class: Constraint
Performs the action attached to this constraint. The action should have the following form:
  1. Read the values of several in-variables using sa.get.
  2. Compute some values.
  3. Use sa.join to join the computed values to several out-variables.

Note1: It is a serious mistake to write an action method that reads/modifies variables that are not listed in the collections returned by in()/out(). If you ever suspect such an error, please set ConstraintSystem.CHECK_IN_OUT to true.

Note2: The solver initializes each variable to null (null is considered equivalent to the bottom element of the correspoding lattice). The body of action should be prepared to receive a null result from sa.get.

Specified by:
action in class Constraint<V extends Var<Info>,Info>
Parameters:
sa - Provides access to the values of the variables that are read/modified.

rewrite

public Constraint<V,Info> rewrite(DisjointSet<V> uf)
Description copied from class: Constraint
Rewrites this constraint by replacing each variable with the representative of its equivalence class. The real implementation of this method is optional: the default implementation returns this constraint, unmodified. This is safe: the constraint writer does not need to be aware of variable unification, as the SolAccessor passed by the constraint solver already deals with it.

Implementing rewrite may be useful when unification causes several constraints to become identical: e.g., consider v1 <= v2 and v3 <= v4, after we unify v1 with v3 and v2 with v4. Implementing rewrite, equals (and hashCode) allows the solver to avoid working with several identical constraints.

Overrides:
rewrite in class Constraint<V extends Var<Info>,Info>
Parameters:
uf - Union-find structure; for each variable v, uf.find(v) is the representative of its equivalence class.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

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


Copyright 2005 Alexandru Salcianu - salcianu@alum.mit.edu