choco.kernel.solver.constraints
Class AbstractSConstraint<V extends Var>

java.lang.Object
  extended by choco.kernel.solver.propagation.Propagator
      extended by choco.kernel.solver.constraints.AbstractSConstraint<V>
All Implemented Interfaces:
IExtensionnable, IPretty, SConstraint<V>, Cloneable, EventListener
Direct Known Subclasses:
AbstractIntSConstraint, AbstractMixedSetIntSConstraint, AbstractMixedSRealIntSConstraint, AbstractRealSConstraint, AbstractSetSConstraint, ReifiedAllSConstraint, TempTaskConstraintWrapper

public abstract class AbstractSConstraint<V extends Var>
extends Propagator
implements SConstraint<V>

An abstract class for all implementations of listeners


Field Summary
 int[] cIndices
          The list, containing, for each variable, the index of the constraint among all its incident listeners.
protected  SConstraintType constraintType
          Return the type of constraint.
 Extension[] extensions
          The extensions of this constraint, in order to add some data linked to this constraint (for specific algorithms)
protected  V[] vars
          The list of variables of the constraint.
 
Fields inherited from class choco.kernel.solver.propagation.Propagator
active, constAwakeEvent, priority, propagationEngine
 
Fields inherited from interface choco.kernel.solver.constraints.SConstraint
LOGGER
 
Constructor Summary
protected AbstractSConstraint(int priority, V[] vars)
          Constructs a constraint with the specified priority.
protected AbstractSConstraint(V[] vars)
          Constructs a constraint with the priority 0.
 
Method Summary
 void addExtension(int extensionNumber)
          Adds a new extension.
 void addListener(boolean dynamicAddition)
          This function connects a constraint with its variables in several ways.
 Object clone()
          Clone the constraint
static int getAbstractSConstraintExtensionNumber(String name)
          Returns a new number of extension registration
 int getConstraintIdx(int i)
          Returns the index of the constraint in the specified variable.
 Extension getExtension(int extensionNumber)
          Returns the queried extension
 int getFineDegree(int idx)
          Some global constraint might be able to provide some fine grained information about the "real" degree of a variables.
 int getNbVarNotInst()
          CPRU 07/12/2007: DomOverWDeg implementation This method returns the number of variables not already instanciated
 int getNbVars()
          Returns the number of variables.
 V getVar(int i)
          Returns the ith variable.
 V getVarQuick(int i)
          Network management: Accessing the ith variable of a constraint.
 boolean isCompletelyInstantiated()
          Checks wether all the variables are instantiated.
 Boolean isEntailed()
          Indicates if the constraint is entailed, from now on will be always satisfied
 AbstractSConstraint<V> opposite(Solver solver)
          Get the opposite constraint
 String pretty()
          pretty printing of the object.
 void setConstraintIndex(int i, int val)
          Let v be the i-th var of c, records that c is the n-th constraint involving v.
 void setExtension(Extension ext, int extensionNumber)
           
 void setVar(int i, V v)
          Network management: Setting (or overwriting) the ith variable of a constraint.
 String toString()
           
 
Methods inherited from class choco.kernel.solver.propagation.Propagator
activate, awake, constAwake, fail, getEvent, getFilteredEventMask, getPriority, isActive, isConsistent, propagate, setActive, setActiveSilently, setEntailed, setPassive, setPropagationEngine
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface choco.kernel.solver.constraints.SConstraint
getConstraintType, isSatisfied
 

Field Detail

vars

protected V extends Var[] vars
The list of variables of the constraint.


cIndices

public int[] cIndices
The list, containing, for each variable, the index of the constraint among all its incident listeners.


constraintType

protected SConstraintType constraintType
Return the type of constraint. Can be INTEGER, SET, REAL, MIXED


extensions

public Extension[] extensions
The extensions of this constraint, in order to add some data linked to this constraint (for specific algorithms)

Constructor Detail

AbstractSConstraint

protected AbstractSConstraint(V[] vars)
Constructs a constraint with the priority 0.

Parameters:
vars - variables involved in the constraint

AbstractSConstraint

protected AbstractSConstraint(int priority,
                              V[] vars)
Constructs a constraint with the specified priority.

Parameters:
priority - The wished priority.
vars - variables involved in the constraint
Method Detail

getAbstractSConstraintExtensionNumber

public static int getAbstractSConstraintExtensionNumber(String name)
Returns a new number of extension registration

Parameters:
name - A name for the extension (should be an UID, like the anbsolute path for instance)
Returns:
a number that can be used for specifying an extension (setExtension method)

addExtension

public void addExtension(int extensionNumber)
Adds a new extension.

Specified by:
addExtension in interface IExtensionnable
Parameters:
extensionNumber - should use the number returned by getAbstractSConstraintExtensionNumber

getExtension

public final Extension getExtension(int extensionNumber)
Returns the queried extension

Specified by:
getExtension in interface IExtensionnable
Parameters:
extensionNumber - should use the number returned by getAbstractSConstraintExtensionNumber
Returns:
the queried extension

setExtension

public final void setExtension(Extension ext,
                               int extensionNumber)

isEntailed

public Boolean isEntailed()
Indicates if the constraint is entailed, from now on will be always satisfied

Specified by:
isEntailed in class Propagator
Returns:
wether the constraint is entailed

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 model. 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 class Propagator
Parameters:
dynamicAddition - if the addition should be dynamical

setConstraintIndex

public final void setConstraintIndex(int i,
                                     int val)
Let v be the i-th var of c, records that c is the n-th constraint involving v.

Specified by:
setConstraintIndex in interface SConstraint<V extends Var>
Parameters:
i - index of the variable in the constraint
val - index of the constraint in the among all listeners linked to that variable

getConstraintIdx

public final int getConstraintIdx(int i)
Returns the index of the constraint in the specified variable.

Specified by:
getConstraintIdx in interface SConstraint<V extends Var>
Parameters:
i - index of the variable in the constraint
Returns:
index of the constraint within the variable network

isCompletelyInstantiated

public final boolean isCompletelyInstantiated()
Checks wether all the variables are instantiated.

Specified by:
isCompletelyInstantiated in class Propagator
Returns:
whether all the variables have been completely instantiated

getNbVars

public final int getNbVars()
Returns the number of variables.

Specified by:
getNbVars in interface SConstraint<V extends Var>
Returns:
number of variables involved in the constraint

getVar

public final V getVar(int i)
Returns the ith variable.

Specified by:
getVar in interface SConstraint<V extends Var>
Parameters:
i - index of the variable in the constraint
Returns:
the i^th variable involved in the constraint

getVarQuick

public final V getVarQuick(int i)
Description copied from interface: SConstraint
Network management: Accessing the ith variable of a constraint.

Specified by:
getVarQuick in interface SConstraint<V extends Var>
Parameters:
i - index of the variable in the constraint
Returns:
the i^th variable involved in the constraint

setVar

public final void setVar(int i,
                         V v)
Description copied from interface: SConstraint
Network management: Setting (or overwriting) the ith variable of a constraint.

Specified by:
setVar in interface SConstraint<V extends Var>
Parameters:
i - index of the variable in the constraint
v - the variable (may be an IntDomainVar, SetVar, RealVar, ...

opposite

public AbstractSConstraint<V> opposite(Solver solver)
Get the opposite constraint

Specified by:
opposite in interface SConstraint<V extends Var>
Parameters:
solver - the current solver
Returns:
the opposite constraint @param solver

clone

public Object clone()
             throws CloneNotSupportedException
Clone the constraint

Overrides:
clone in class Object
Returns:
the clone of the constraint
Throws:
CloneNotSupportedException - Clone not supported exception

getNbVarNotInst

public final int getNbVarNotInst()
CPRU 07/12/2007: DomOverWDeg implementation This method returns the number of variables not already instanciated

Returns:
the number of failure

toString

public String toString()
Overrides:
toString in class Object

pretty

public String pretty()
Description copied from interface: IPretty
pretty printing of the object. This String is not constant and may depend on the context.

Specified by:
pretty in interface IPretty
Returns:
a readable string representation of the object

getFineDegree

public int getFineDegree(int idx)
Some global constraint might be able to provide some fine grained information about the "real" degree of a variables. For example the global constraint on clauses can give the real number of clauses on each variable

Specified by:
getFineDegree in interface SConstraint<V extends Var>
Parameters:
idx - index of the variable in the constraint
Returns:
a weight given to the variable by the constraint


Copyright © 2012. All Rights Reserved.