public abstract class Constraint<V extends Variable<V,T>,T extends Value<V,T>> extends Object implements Comparable<Constraint<V,T>>
computeConflicts(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(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(long,Value)
and
unassigned(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 Collection<V> |
iAssignedVariables |
protected List<ConstraintListener<T>> |
iConstraintListeners |
protected long |
iId |
Constructor and Description |
---|
Constraint()
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addConstraintListener(ConstraintListener<T> listener)
Adds a constraint listener
|
void |
addVariable(V variable)
Add a variable to this constraint
|
void |
assigned(long iteration,
T value)
Given value is to be assigned to its varable.
|
Collection<V> |
assignedVariables()
The list of variables of this constraint that are assigned
|
int |
compareTo(Constraint<V,T> c) |
abstract void |
computeConflicts(T value,
Set<T> conflicts)
The only method which has to be implemented by any constraint.
|
List<ConstraintListener<T>> |
constraintListeners()
Returns the list of registered constraint listeners
|
int |
countAssignedVariables()
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(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<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(long iteration,
T value)
Given value is unassigned from its variable.
|
List<V> |
variables()
The list of variables of this constraint
|
protected long iId
protected Collection<V extends Variable<V,T>> iAssignedVariables
protected List<ConstraintListener<T extends Value<V,T>>> iConstraintListeners
public Constraint()
public Collection<V> assignedVariables()
public int countVariables()
public int countAssignedVariables()
public void addVariable(V variable)
public void removeVariable(V variable)
public abstract void computeConflicts(T value, Set<T> conflicts)
value
- value to be assigned to its varaibleconflicts
- resultant set of conflicting valuespublic boolean isConsistent(T value1, T value2)
MacPropagation
).public boolean inConflict(T value)
MacPropagation
).public void assigned(long iteration, T value)
public void unassigned(long iteration, T value)
public void addConstraintListener(ConstraintListener<T> listener)
public void removeConstraintListener(ConstraintListener<T> listener)
public List<ConstraintListener<T>> constraintListeners()
public long getId()
public String getDescription()
public boolean isHard()
public int compareTo(Constraint<V,T> c)