jpaul.Constraints.SetConstraints
Class FilterConstraint<T>

java.lang.Object
  extended by jpaul.Constraints.Constraint<SVar<T>,java.util.Set<T>>
      extended by jpaul.Constraints.SetConstraints.FilterConstraint<T>
Direct Known Subclasses:
CtDiffConstraint

public class FilterConstraint<T>
extends Constraint<SVar<T>,java.util.Set<T>>

FilterConstraint models a filtering constraint. Mathematically, such a constraint has the form:

vIn | pred <= vDest
where /\ stands for set intersection, <= stands for set inclusion, and vIn, vDest are set-valued variables, and pred is a predicate. The constraints states that all elements of vIn that satisfy the predicate pred should appear in vDest.

Note: pred should be a constant predicate (it should just be a way of specifying a constant set). Things may get really wild if the predicate changes while the system is solved.

Version:
$Id: FilterConstraint.java,v 1.6 2006/03/14 02:29:30 salcianu Exp $
Author:
Alexandru Salcianu - salcianu@alum.mit.edu

Field Summary
protected  Predicate<T> pred
           
protected  SVar<T> vDest
           
protected  SVar<T> vIn
           
 
Fields inherited from class jpaul.Constraints.Constraint
AVG_COST, HIGH_COST, LOW_COST, VERY_LOW_COST
 
Constructor Summary
FilterConstraint(SVar<T> vIn, Predicate<T> pred, SVar<T> vDest)
          Creates a FilterConstraint with the meaning vIn | pred <= vDest.
 
Method Summary
 void action(SolAccessor<SVar<T>,java.util.Set<T>> sa)
          Performs the action attached to this constraint.
 int cost()
          Returns HIGH_COST.
 java.util.Collection<SVar<T>> in()
           
 java.util.Collection<SVar<T>> out()
           
 java.lang.String toString()
           
 
Methods inherited from class jpaul.Constraints.Constraint
rewrite
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

vIn

protected final SVar<T> vIn

pred

protected final Predicate<T> pred

vDest

protected final SVar<T> vDest
Constructor Detail

FilterConstraint

public FilterConstraint(SVar<T> vIn,
                        Predicate<T> pred,
                        SVar<T> vDest)
Creates a FilterConstraint with the meaning vIn | pred <= vDest.

Method Detail

in

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

out

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

cost

public int cost()
Returns HIGH_COST.

Overrides:
cost in class Constraint<SVar<T>,java.util.Set<T>>

action

public void action(SolAccessor<SVar<T>,java.util.Set<T>> 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<SVar<T>,java.util.Set<T>>
Parameters:
sa - Provides access to the values of the variables that are read/modified.

toString

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


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