choco.cp.solver.constraints.reified
Class ExpressionSConstraint

java.lang.Object
  extended by choco.kernel.solver.constraints.integer.extension.ConsistencyRelation
      extended by choco.kernel.solver.constraints.integer.extension.TuplesTest
          extended by choco.cp.solver.constraints.reified.ExpressionSConstraint
All Implemented Interfaces:
IExtensionnable, IPretty, BinRelation, LargeRelation, SConstraint, Cloneable

public final class ExpressionSConstraint
extends TuplesTest
implements SConstraint, BinRelation

User: hcambaza A constraint to deal with complex expression of variables involving a wide range of operators


Nested Class Summary
static class ExpressionSConstraint.VarMinDomComparator
          Sort variables from the biggest domain to the smallest
 
Field Summary
protected  int[] bint
           
protected  Boolean decomposeExp
          Tell the solver if this expression should be decomposed or not (dealt as an extensional constraint if not) if null, the solver will make a decision by itself
protected  INode expr
          A reference to the Expression itself
protected  SConstraint knownIntensionalConstraint
           
protected  int levelAc
          Enforce the level of consistency if the expression is posted as an extentionnal constraint. 0: AC 1: FC
protected  IntDomainVar[] vars
          The scope of the predicat
 
Fields inherited from class choco.kernel.solver.constraints.integer.extension.ConsistencyRelation
feasible, LOGGER
 
Fields inherited from interface choco.kernel.solver.constraints.SConstraint
LOGGER
 
Constructor Summary
ExpressionSConstraint(BoolNode expr)
          Construct an Expression from a root Node
ExpressionSConstraint(BoolNode expr, Boolean decomp)
          Construct an Expression from a root Node
 
Method Summary
 void addExtension(int extensionNumber)
          Adds a new extension.
 double cardProd()
           
 boolean checkCouple(int a, int b)
          Api to check a couple for binary AC
 boolean checkDecompositionIsPossible()
           
 boolean checkIsReified()
           
 boolean checkTuple(int[] tuple)
          Api to check a tuple
static int[] copy(int[] tab)
           
 int getConstraintIdx(int idx)
          Network management: Among all listeners linked to the idx-th variable of c, find the index of constraint c.
 SConstraintType getConstraintType()
          Return the type of constraint, ie the type of variable involved in the constraint
 SConstraint getDecomposition(Solver s)
          Perform the decomposition of the Expression into elementary constraints.
 Extension getExtension(int extensionNumber)
          Returns the queried extension
 SConstraint getExtensionnal(Solver s)
          return the extensional propagator intended to propagate the expression
 int getFineDegree(int idx)
          Some global constraint might be able to provide some fine grained information about the "real" degree of a variables.
 SConstraint getKnownIntensionalConstraint()
           
 int getLevelAc()
           
 int getNbVars()
          Network management: Get the number of variables involved in the constraint.
 ExpressionSConstraint getOpposite()
          return the opposite relation of itself
 INode getRootNode()
           
 List<int[]> getTuples(Solver s)
          Generate the list of tuples corresponding to this predicat
 Var getVar(int i)
          Network management: Accessing the ith variable of a constraint.
 Iterator<IntegerVariable> getVariableIterator()
           
 Var getVarQuick(int i)
          Network management: Accessing the ith variable of a constraint.
 IntDomainVar[] getVars()
           
 boolean isConsistent(int x, int y)
          Test whether the couple (x,y) is consistent
 Boolean isDecomposeExp()
           
 boolean isSatisfied()
          Semantic: Testing if the constraint is satisfied.
 AbstractSConstraint opposite(Solver solver)
          computes the constraint modelling the counter-opposite condition of this
 String pretty()
          pretty printing of the object.
 void setConstraintIndex(int i, int idx)
          Network management: Storing that among all listeners linked to the i-th variable of c, this (the current constraint) is found at index idx.
 void setDecomposeExp(Boolean decomposeExp)
           
 void setKnownIntensionalConstraint(SConstraint knownIntensionalConstraint)
           
 void setLevelAc(int levelAc)
          Set the level of AC in case the expression is not decomposed 0 gives AC, 1 gives FC, -1 let the expression choose automatically
 void setScope(Solver s)
          compute the scope of this predicat as the union of the scopes of all the leaves and set the indexes of each variable of each leave regarding its position in the scope "vars" This is called once when posting the propagator
 void setVar(int i, Var v)
          Network management: Setting (or overwriting) the ith variable of a constraint.
 
Methods inherited from class choco.kernel.solver.constraints.integer.extension.TuplesTest
isConsistent
 
Methods inherited from class choco.kernel.solver.constraints.integer.extension.ConsistencyRelation
isDefinedByFeasability, switchToOppositeRelation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vars

protected IntDomainVar[] vars
The scope of the predicat


expr

protected INode expr
A reference to the Expression itself


decomposeExp

protected Boolean decomposeExp
Tell the solver if this expression should be decomposed or not (dealt as an extensional constraint if not) if null, the solver will make a decision by itself


levelAc

protected int levelAc
Enforce the level of consistency if the expression is posted as an extentionnal constraint. 0: AC 1: FC


knownIntensionalConstraint

protected SConstraint knownIntensionalConstraint

bint

protected int[] bint
Constructor Detail

ExpressionSConstraint

public ExpressionSConstraint(BoolNode expr,
                             Boolean decomp)
Construct an Expression from a root Node

Parameters:
expr -

ExpressionSConstraint

public ExpressionSConstraint(BoolNode expr)
Construct an Expression from a root Node

Parameters:
expr -
Method Detail

getRootNode

public INode getRootNode()

isDecomposeExp

public Boolean isDecomposeExp()

setDecomposeExp

public void setDecomposeExp(Boolean decomposeExp)

setScope

public void setScope(Solver s)
compute the scope of this predicat as the union of the scopes of all the leaves and set the indexes of each variable of each leave regarding its position in the scope "vars" This is called once when posting the propagator


getVars

public IntDomainVar[] getVars()
Returns:
the scope of the expression computed as solver variables

getNbVars

public int getNbVars()
Description copied from interface: SConstraint
Network management: Get the number of variables involved in the constraint.

Specified by:
getNbVars in interface SConstraint
Returns:
the size of the scope

getVar

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

Specified by:
getVar in interface SConstraint
Parameters:
i - index of the variable in the constraint
Returns:
the i^th variable involved in the constraint

getVarQuick

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

Specified by:
getVarQuick in interface SConstraint
Parameters:
i - index of the variable in the constraint
Returns:
the i^th variable involved in the constraint

setVar

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

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

getLevelAc

public int getLevelAc()

setLevelAc

public void setLevelAc(int levelAc)
Set the level of AC in case the expression is not decomposed 0 gives AC, 1 gives FC, -1 let the expression choose automatically

Parameters:
levelAc -

checkDecompositionIsPossible

public boolean checkDecompositionIsPossible()
Returns:
true iff all the operators are decomposable (choco provides an intensional constraint for them)

checkIsReified

public boolean checkIsReified()
Returns:
true is the expression contains an operator of reification i.e or, and, not.

getOpposite

public ExpressionSConstraint getOpposite()
Description copied from class: ConsistencyRelation
return the opposite relation of itself

Overrides:
getOpposite in class TuplesTest

getKnownIntensionalConstraint

public SConstraint getKnownIntensionalConstraint()

setKnownIntensionalConstraint

public void setKnownIntensionalConstraint(SConstraint knownIntensionalConstraint)

checkCouple

public boolean checkCouple(int a,
                           int b)
Api to check a couple for binary AC

Specified by:
checkCouple in interface BinRelation
Parameters:
a -
b -
Returns:
true if the given couple satisfy the expression

isConsistent

public boolean isConsistent(int x,
                            int y)
Description copied from interface: BinRelation
Test whether the couple (x,y) is consistent

Specified by:
isConsistent in interface BinRelation
Returns:
true if (x,y) is a consistent couple

checkTuple

public boolean checkTuple(int[] tuple)
Api to check a tuple

Specified by:
checkTuple in interface LargeRelation
Parameters:
tuple -
Returns:
true if the given tuple satisfy the expression

getExtensionnal

public SConstraint getExtensionnal(Solver s)
return the extensional propagator intended to propagate the expression

Parameters:
s -

getDecomposition

public SConstraint getDecomposition(Solver s)
Perform the decomposition of the Expression into elementary constraints.

Parameters:
s -

cardProd

public double cardProd()
Returns:
the size of the cartesian products representing the Expression

getTuples

public List<int[]> getTuples(Solver s)
Generate the list of tuples corresponding to this predicat

Returns:

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

getConstraintType

public SConstraintType getConstraintType()
Description copied from interface: SConstraint
Return the type of constraint, ie the type of variable involved in the constraint

Specified by:
getConstraintType in interface SConstraint
Returns:

getVariableIterator

public Iterator<IntegerVariable> getVariableIterator()

setConstraintIndex

public void setConstraintIndex(int i,
                               int idx)
Description copied from interface: SConstraint
Network management: Storing that among all listeners linked to the i-th variable of c, this (the current constraint) is found at index idx.

Specified by:
setConstraintIndex in interface SConstraint
Parameters:
i - index of the variable in the constraint
idx - index of the constraint in the among all listeners linked to that variable

getConstraintIdx

public int getConstraintIdx(int idx)
Description copied from interface: SConstraint
Network management: Among all listeners linked to the idx-th variable of c, find the index of constraint c.

Specified by:
getConstraintIdx in interface SConstraint
Parameters:
idx - index of the variable in the constraint
Returns:
index of the constraint within the variable network

isSatisfied

public boolean isSatisfied()
Description copied from interface: SConstraint
Semantic: Testing if the constraint is satisfied. Note that all variables involved in the constraint must be instantiated when this method is called.

Specified by:
isSatisfied in interface SConstraint
Returns:
true if the constraint is satisfied

opposite

public AbstractSConstraint opposite(Solver solver)
Description copied from interface: SConstraint
computes the constraint modelling the counter-opposite condition of this

Specified by:
opposite in interface SConstraint
Parameters:
solver - the current solver
Returns:
a new constraint (modelling the opposite condition) @param solver

copy

public static int[] copy(int[] tab)

getExtension

public Extension getExtension(int extensionNumber)
Description copied from interface: IExtensionnable
Returns the queried extension

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

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

getFineDegree

public int getFineDegree(int idx)
Description copied from interface: SConstraint
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
Parameters:
idx - index of the variable in the constraint
Returns:
a weight given to the variable by the constraint


Copyright © 2012. All Rights Reserved.