omnics
Class Constraint

java.lang.Object
  extended by omnics.Constraint
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
AllDiff, BinaryConstraint, ConstantSum, ExplicitConstraint, ScalarProduct, ScalarProductLeq, SoftScalarProduct, SumDiff, UnaryConstraint

public abstract class Constraint
extends java.lang.Object
implements java.io.Serializable

Represents an abstract constraint. A constraint is a logical relation among several variables, restricting the possible values that variables can take. There are no assumptions regarding the definition of the constraints: they can be represented as the underlying relation of permitted values or as a function defined on a set of variables and returning an integer that represents an evaluation of a given tuple.

Author:
Cristian Frasinaru
See Also:
Serialized Form

Field Summary
static int ALLOWED
           
protected  Filter filter
           
static int FORBIDDEN
           
static int MAX
           
static int MIN
           
protected  java.lang.String name
           
protected  Problem problem
           
protected  VarSet variables
           
 
Constructor Summary
Constraint(Var... vars)
          Creates a new constraint on the specified variables.
Constraint(VarSet variables)
          Creates a new constraint on the specified set of variables.
 
Method Summary
abstract  int eval(Tuple tuple)
          Evaluates a tuple.
 int eval(Var x, java.lang.Object a)
          Convenience method that evaluates an assignment (x=a).
 int eval(Var x, Var y, java.lang.Object a, java.lang.Object b)
          Convenience method that evaluates an assignment (x=a, y=b).
 Filter getFilter()
          Gets the associated filter (if any).
 java.lang.String getName()
          Gets the name of the constraint.
 Problem getProblem()
          Gets the problem this constraint belongs to.
 TupleSet getTuples()
          Creates and returns a set containing all the tuples that satisfy this constraint.
 Var[] getVarArray()
          Returns the variables of the constraint as an array.
 VarSet getVariables()
          Gets a reference to the variables of the constraint.
 void setFilter(Filter filter)
          Sets a filter for this (global) constraint.
 void setName(java.lang.String name)
          Sets the name of the constraint.
 void setVariables(Var... vars)
          Sets the variables of the constraint.
 void setVariables(VarSet variables)
          Sets the variables of the constraint.
 java.lang.String toString()
          Returns a string representation of the constraint.
 Var variable(int index)
          Gets the variable at the specified index
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name

problem

protected Problem problem

variables

protected VarSet variables

filter

protected Filter filter

ALLOWED

public static final int ALLOWED
See Also:
Constant Field Values

FORBIDDEN

public static final int FORBIDDEN
See Also:
Constant Field Values

MIN

public static final int MIN
See Also:
Constant Field Values

MAX

public static final int MAX
See Also:
Constant Field Values
Constructor Detail

Constraint

public Constraint(VarSet variables)
Creates a new constraint on the specified set of variables.

Parameters:
variables - a set of variables

Constraint

public Constraint(Var... vars)
Creates a new constraint on the specified variables.

Parameters:
vars - some variables
Method Detail

getName

public java.lang.String getName()
Gets the name of the constraint.

Returns:
the name given to this constraint

setName

public void setName(java.lang.String name)
Sets the name of the constraint.

Parameters:
name - the name given to the constraint

getProblem

public Problem getProblem()
Gets the problem this constraint belongs to. This information is set when the constraint is added to a problem.

Returns:
the problem this constraint belongs to or null if the constraint has not been added to a problem.

getVariables

public VarSet getVariables()
Gets a reference to the variables of the constraint.

Returns:
the variables of the constraint

setVariables

public void setVariables(VarSet variables)
Sets the variables of the constraint.

Parameters:
variables - the variables of the constraint

setVariables

public void setVariables(Var... vars)
Sets the variables of the constraint.

Parameters:
vars - the variables of the constraint

getVarArray

public Var[] getVarArray()
Returns the variables of the constraint as an array.

Returns:
an array of variables

variable

public Var variable(int index)
Gets the variable at the specified index

Parameters:
index - an index
Returns:
the variable at the specified index

getFilter

public Filter getFilter()
Gets the associated filter (if any).

Returns:
the associated filter or null if there is no filter

setFilter

public void setFilter(Filter filter)
Sets a filter for this (global) constraint.

Parameters:
filter - a filter
See Also:
Filter

eval

public int eval(Var x,
                java.lang.Object a)
Convenience method that evaluates an assignment (x=a).

Parameters:
x - some variable of the constraint
a - some value in x's domain
Returns:
a value between ValuationStructure.MIN and ValuationStructure.MAX.
See Also:
eval(Tuple), ValuationStructure

eval

public int eval(Var x,
                Var y,
                java.lang.Object a,
                java.lang.Object b)
Convenience method that evaluates an assignment (x=a, y=b).

Parameters:
x - some variable of the constraint
a - some value in x's domain
y - some variable of the constraint
b - some value in y's domain
Returns:
a value between ValuationStructure.MIN and ValuationStructure.MAX.
See Also:
eval(Tuple), ValuationStructure

eval

public abstract int eval(Tuple tuple)
Evaluates a tuple. The result of the evaluation could be: Constants MIN, MAX, ALLOWED, FORBIDDEN are defined in ValuationStructure

Parameters:
tuple - some tuple
Returns:
a value between ValuationStructure.MIN and ValuationStructure.MAX.
See Also:
eval(Tuple), ValuationStructure

getTuples

public TupleSet getTuples()
Creates and returns a set containing all the tuples that satisfy this constraint.

Warning: if the constrained is not an explicit constraint

Returns:
all the tuples that satisfy this constraint.

toString

public java.lang.String toString()
Returns a string representation of the constraint. It actually returns the name of the constraint. If the constraint has not been given an explicit name, it's name is: getClass().getName() + "(" + variables + ")"

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the constraint