choco
Class AbstractConstraint

java.lang.Object
  extended by choco.AbstractEntity
      extended by choco.AbstractConstraint
All Implemented Interfaces:
Constraint, Entity, VarEventListener, Propagator, java.lang.Cloneable, java.util.EventListener
Direct Known Subclasses:
AbstractBinRealIntConstraint, AbstractCompositeConstraint, AbstractIntConstraint, AbstractLargeRealConstraint, AbstractMixedConstraint, AbstractSetConstraint, AbstractUnRealConstraint, ConstantConstraint

public abstract class AbstractConstraint
extends AbstractEntity
implements Propagator

An abstract class for all implementations of listeners


Field Summary
protected  IStateBool active
          a field for storing whether the constraint is active or not
protected  ConstraintEvent constAwakeEvent
          The constraint awake var attached to the constraint.
protected  ConstraintPlugin hook
          A field for attaching additional data util (useful for PaLM)
protected  int priority
          The priority of the constraint.
 
Fields inherited from class choco.AbstractEntity
problem
 
Constructor Summary
AbstractConstraint()
          Constraucts a constraint with the priority 0.
AbstractConstraint(int priority)
          Constructs a constraint with the specified priority.
 
Method Summary
 void addListener(boolean dynamicAddition)
          This function connects a constraint with its variables in several ways.
 void awake()
          Default initial propagation: full constraint re-propagation.
 void awakeOnVar(int idx)
          Default propagation on variable revision: full constraint re-propagation.
 java.lang.Object clone()
          returns a copy of the constraint.
 int connectVar(AbstractVar v, int j, boolean dynamicAddition)
           
 void constAwake(boolean isInitialPropagation)
          Initial propagation of the constraint.
 void delete()
          Removes a constraint from the network.
 void fail()
          raise a contradiction during propagation when the constraint can definitely not be satisfied given the current domains
 PropagationEvent getEvent()
          Returns the constraint awake var attached to the constraint.
 ConstraintPlugin getPlugIn()
          Returns the constraint plugin.
 int getPriority()
          Returns the priority.
 AbstractProblem getProblem()
          Retrieve the problem of the constraint.
 int getVarIdxInOpposite(int i)
          computes the index of the i-th variable in the counter-opposite of the constraint
 boolean isActive()
          Checks if the constraint is active (e.g. plays a role in the propagation phase).
 java.lang.Boolean isEntailed()
          Checks whether the constraint is definitely satisfied, no matter what further restrictions occur to the domain of its variables.
 boolean isEquivalentTo(Constraint compareTo)
          tests the equivalence (logical equality of the conditions) between two constraints.
 AbstractConstraint opposite()
          computes the constraint modelling the counter-opposite condition of this
 void setActive()
          Un-freezing a constraint (this is useful for mimicking dynamic constraint posts...).
 void setEntailed()
          records that a constraint is now entailed (therefore it is now useless to propagate it again)
 void setPassive()
          Freezing a constraint (this is useful for backtracking when mimicking dynamic constraint posts...).
 void setPlugIn(ConstraintPlugin hook)
          Set the ConstraintPlugin of the constraint.
 int substituteVar(Var oldvar, Var newvar)
          substitues all occurrences of a variable in a constraint by another variable
 
Methods inherited from class choco.AbstractEntity
pretty
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface choco.Propagator
assignIndices, isCompletelyInstantiated, isConsistent, propagate
 
Methods inherited from interface choco.Constraint
getConstraintIdx, getNbVars, getVar, isSatisfied, setConstraintIndex, setVar
 
Methods inherited from interface choco.Entity
pretty
 

Field Detail

priority

protected int priority
The priority of the constraint.


constAwakeEvent

protected ConstraintEvent constAwakeEvent
The constraint awake var attached to the constraint.


hook

protected ConstraintPlugin hook
A field for attaching additional data util (useful for PaLM)


active

protected IStateBool active
a field for storing whether the constraint is active or not

Constructor Detail

AbstractConstraint

public AbstractConstraint()
Constraucts a constraint with the priority 0.


AbstractConstraint

public AbstractConstraint(int priority)
Constructs a constraint with the specified priority.

Parameters:
priority - The wished priority.
Method Detail

getPlugIn

public ConstraintPlugin getPlugIn()
Returns the constraint plugin. Useful for extending the solver.

Specified by:
getPlugIn in interface Propagator

setPlugIn

public void setPlugIn(ConstraintPlugin hook)
Set the ConstraintPlugin of the constraint. The constraint plugin gives access to the dependency net of each constraint, it can be useful to design search heuristic based on explanation.

Parameters:
hook -

getEvent

public PropagationEvent getEvent()
Returns the constraint awake var attached to the constraint.

Specified by:
getEvent in interface Propagator

constAwake

public void constAwake(boolean isInitialPropagation)
Initial propagation of the constraint.

Specified by:
constAwake in interface Propagator

getPriority

public int getPriority()
Returns the priority.

Specified by:
getPriority in interface Propagator

awakeOnVar

public void awakeOnVar(int idx)
                throws ContradictionException
Default propagation on variable revision: full constraint re-propagation.

Specified by:
awakeOnVar in interface VarEventListener
Specified by:
awakeOnVar in interface Propagator
Throws:
ContradictionException

awake

public void awake()
           throws ContradictionException
Default initial propagation: full constraint re-propagation.

Specified by:
awake in interface Propagator
Throws:
ContradictionException

getProblem

public AbstractProblem getProblem()
Retrieve the problem of the constraint.

Specified by:
getProblem in interface Entity
Overrides:
getProblem in class AbstractEntity

setActive

public void setActive()
Un-freezing a constraint (this is useful for mimicking dynamic constraint posts...).

Specified by:
setActive in interface VarEventListener

setPassive

public void setPassive()
Freezing a constraint (this is useful for backtracking when mimicking dynamic constraint posts...).

Specified by:
setPassive in interface VarEventListener

setEntailed

public void setEntailed()
records that a constraint is now entailed (therefore it is now useless to propagate it again)


delete

public void delete()
Removes a constraint from the network. Beware, this is a permanent removal, it may not be backtracked

Specified by:
delete in interface Propagator

fail

public void fail()
          throws ContradictionException
raise a contradiction during propagation when the constraint can definitely not be satisfied given the current domains

Throws:
ContradictionException

isEntailed

public java.lang.Boolean isEntailed()
Description copied from interface: Propagator
Checks whether the constraint is definitely satisfied, no matter what further restrictions occur to the domain of its variables.

Specified by:
isEntailed in interface Propagator

isActive

public boolean isActive()
Checks if the constraint is active (e.g. plays a role in the propagation phase).

Specified by:
isActive in interface VarEventListener
Returns:
true if the constraint is indeed currently active

addListener

public void addListener(boolean dynamicAddition)
This function connects a constraint with its variables in several ways. Note that it may only be called once the constraint has been fully created and is being posted to a problem. Note that it should be called only once per constraint. This can be a dynamic addition (undone upon backtracking) or not

Specified by:
addListener in interface VarEventListener

getVarIdxInOpposite

public int getVarIdxInOpposite(int i)
Description copied from interface: Constraint
computes the index of the i-th variable in the counter-opposite of the constraint

Specified by:
getVarIdxInOpposite in interface Constraint
Parameters:
i - the index of the variable in the current constraint (this)
Returns:
the index of the variable in the opposite constraint (this.opposite())

opposite

public AbstractConstraint opposite()
Description copied from interface: Constraint
computes the constraint modelling the counter-opposite condition of this

Specified by:
opposite in interface Constraint
Returns:
a new constraint (modelling the opposite condition)

connectVar

public int connectVar(AbstractVar v,
                      int j,
                      boolean dynamicAddition)

isEquivalentTo

public boolean isEquivalentTo(Constraint compareTo)
Description copied from interface: Constraint
tests the equivalence (logical equality of the conditions) between two constraints. In particular whenever c1.equals(c2), then c1.isEquivalent(c2).

Specified by:
isEquivalentTo in interface Constraint
Parameters:
compareTo - the constraint to be compared to
Returns:
true if and only if the constraints model the same logical condition.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Description copied from interface: Constraint
returns a copy of the constraint. This copy is a new object, may be a recursive copy in case of composite constraints. The original and the copy share the same variables & plugins

Specified by:
clone in interface Constraint
Overrides:
clone in class java.lang.Object
Returns:
Throws:
java.lang.CloneNotSupportedException

substituteVar

public int substituteVar(Var oldvar,
                         Var newvar)
substitues all occurrences of a variable in a constraint by another variable

Parameters:
oldvar - the variable to be removed
newvar - the variable to be introduced in place of the other
Returns:
the number of occurrences that have been substituted