V
 VariableT
 Valuepublic abstract class Constraint<V extends Variable<V,T>,T extends Value<V,T>> extends Object implements Comparable<Constraint<V,T>>
computeConflicts(Assignment, Value, Set)
which returns all
the already assigned values that are incompatible we the selected assignment
(value which is to be assigned to its variable). This procedure is called for
all constraints which contain the selected variable in an ordered manner.
Furthermore, this order can be changed during the search. Moreover, the
computed set of conflicting variables is passed to this
computeConflicts(Assignment, Value, Set)
procedure as a parameter, so
the constraint can "see" what variables are already selected for unassignment
by previously processed constraints. This way, we are not computing the very
minimal set of conflicting variables, however, we allow for computing this
set in an efficient way. It can be also tuned for a particular problem by
changing the order of constraints. assigned(Assignment,long,Value)
and
unassigned(Assignment,long,Value)
methods that are responsible to
keeping the problem consistent with the constraint. Also note that this
default consistency technique is defined on a problem level and it can be
changed by a more dedicated one, implemented for a particular problem.Variable
,
Model
,
Solver
Modifier and Type  Field and Description 

protected List<ConstraintListener<V,T>> 
iConstraintListeners 
protected long 
iId 
Constructor and Description 

Constraint()
Constructor

Modifier and Type  Method and Description 

void 
addConstraintListener(ConstraintListener<V,T> listener)
Adds a constraint listener

void 
addVariable(V variable)
Add a variable to this constraint

void 
assigned(Assignment<V,T> assignment,
long iteration,
T value)
Given value is to be assigned to its variable.

Collection<V> 
assignedVariables(Assignment<V,T> assignment)
The list of variables of this constraint that are assigned

int 
compareTo(Constraint<V,T> c) 
abstract void 
computeConflicts(Assignment<V,T> assignment,
T value,
Set<T> conflicts)
The only method which has to be implemented by any constraint.

protected void 
computeConflictsNoForwardCheck(Assignment<V,T> assignment,
T value,
Set<T> conflicts)
Compute conflicts method that does not do any forward checking.

List<ConstraintListener<V,T>> 
constraintListeners()
Returns the list of registered constraint listeners

int 
countAssignedVariables(Assignment<V,T> assignment)
The number of variables of this constraint that are assigned

int 
countVariables()
The number of variables of this constraint

boolean 
equals(Object o)
Compare two constraints for equality (
getId() is used) 
String 
getDescription()
Constraint's description  for printing purposes

long 
getId()
Unique id

Model<V,T> 
getModel()
The model which the constraint belongs to

String 
getName()
Constraint's name  for printing purposes

int 
hashCode() 
boolean 
inConflict(Assignment<V,T> assignment,
T value)
Returns true if the given assignment is inconsistent with the existing
assignments respecting this constraint.

boolean 
isConsistent(T value1,
T value2)
Returns true if the given assignments are consistent respecting this
constraint.

boolean 
isHard()
Returns true if the constraint is hard.

void 
removeConstraintListener(ConstraintListener<V,T> listener)
Removes a constraint listener

void 
removeVariable(V variable)
Remove a variable from this constraint

void 
setModel(Model<V,T> model)
Sets the model which the constraint belongs to

void 
unassigned(Assignment<V,T> assignment,
long iteration,
T value)
Given value is unassigned from its variable.

List<V> 
variables()
The list of variables of this constraint

protected long iId
public Constraint()
public Model<V,T> getModel()
public void setModel(Model<V,T> model)
model
 problem modelpublic List<V> variables()
public Collection<V> assignedVariables(Assignment<V,T> assignment)
assignment
 current assignmentpublic int countVariables()
public int countAssignedVariables(Assignment<V,T> assignment)
assignment
 current assignmentpublic void addVariable(V variable)
variable
 a variablepublic void removeVariable(V variable)
variable
 a variablepublic abstract void computeConflicts(Assignment<V,T> assignment, T value, Set<T> conflicts)
assignment
 current assignmentvalue
 value to be assigned to its variableconflicts
 resultant set of conflicting valuespublic boolean isConsistent(T value1, T value2)
MacPropagation
).value1
 a valuevalue2
 a valuepublic boolean inConflict(Assignment<V,T> assignment, T value)
MacPropagation
).assignment
 current assignmentvalue
 given valuepublic void assigned(Assignment<V,T> assignment, long iteration, T value)
assignment
 current assignmentiteration
 current iterationvalue
 assigned valueprotected void computeConflictsNoForwardCheck(Assignment<V,T> assignment, T value, Set<T> conflicts)
computeConflicts(Assignment, Value, Set)
and it is called during assignment (from assigned(Assignment, long, Value)
) to check for conflicting variables that need to be
unassigned first.assignment
 current assignmentvalue
 value to be assigned to its variableconflicts
 resultant set of conflicting valuespublic void unassigned(Assignment<V,T> assignment, long iteration, T value)
assignment
 current assignmentiteration
 current iterationvalue
 unassigned valuepublic void addConstraintListener(ConstraintListener<V,T> listener)
listener
 a constraint listenerpublic void removeConstraintListener(ConstraintListener<V,T> listener)
listener
 a constraint listenerpublic List<ConstraintListener<V,T>> constraintListeners()
public long getId()
public String getDescription()
public boolean isHard()
public int compareTo(Constraint<V,T> c)