choco.palm.dbt.explain
Class GenericExplanation

java.lang.Object
  extended by choco.palm.dbt.explain.GenericExplanation
All Implemented Interfaces:
ConstraintCollection, PalmExplanation, Explanation
Direct Known Subclasses:
AbstractBoundExplanation, AbstractRealBoundExplanation, RemovalExplanation

public class GenericExplanation
extends java.lang.Object
implements PalmExplanation

Generic implementation of explanations. It is used by filtering algorithms before specializing them for specific use (bound modification, value removal, contradiction...).


Field Summary
protected  java.util.BitSet explanation
          Set of all the constraint in the explain.
protected  PalmProblem pb
          The current problem.
protected  int timeStamp
           
 
Constructor Summary
GenericExplanation(AbstractProblem pb)
          Initializes the explain set.
 
Method Summary
 void add(Propagator constraint)
          Adds a new constraint in the explain.
 void addAll(java.util.Collection collection)
          Adds several constraints at a time
 void addDependencies()
          Updates dependencies.
 void clear()
          Deletes all indirect constraints.
 boolean contains(Propagator constraint)
          Checks if the explain contains a constraint.
 boolean containsAll(ConstraintCollection expl)
          Checks if another explain is included in this one.
 ConstraintCollection copy()
          Clones the explain as a new one.
 void delete(Propagator constraint)
          Deletes a constraint from the explain.
 void empties()
          Clears the constraint set.
 java.util.BitSet getBitSet()
          Copies the explain set and returns the new bitset.
 Propagator getConstraint(int i)
          return the i-th constraint of the explanation
 SymbolicDecision[] getNogood()
          return the nogood associated to the explanation
 int hashCode()
           
 boolean isEmpty()
          Checks if the explain is empty (that is wether the size of the set is null).
 boolean isValid()
          Checks if the explain is valid, that is wether all the constraint are active.
 boolean isValid(int time)
          Checks if the explain is valid, that is wether all the constraint are active.
 RealBoundExplanation makeDecSupExplanation(double sup, PalmRealVar var)
          Makes a DecSupExplanation from the current explain by adding dependencies.
 IBoundExplanation makeDecSupExplanation(int sup, PalmIntVar var)
          Makes a DecSupExplanation from the current explain by adding dependencies.
 RealBoundExplanation makeIncInfExplanation(double inf, PalmRealVar var)
          Makes an IncInfExplanation from the current explain by adding dependencies.
 IBoundExplanation makeIncInfExplanation(int inf, PalmIntVar var)
          Makes an IncInfExplanation from the current explain by adding dependencies.
 IRemovalExplanation makeRemovalExplanation(int value, PalmIntVar var)
          Makes a RemovalExplanation from the current explain by adding dependencies.
 void merge(ConstraintCollection explanation)
          Merges an explain in the current one.
 void postUndoRemoval(Constraint constraint)
          Posts a restoration prop.
static void reinitTimestamp()
           
 void removeDependencies(Constraint removed)
          Removes all dependencies except for one constraint.
 int size()
          Get the size of the bitSet
 java.util.Set toNogood()
           
 java.util.Set toSet()
          Creates a set with all the constraints in the explain.
 java.lang.String toString()
          Pretty print of the explain.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

timeStamp

protected int timeStamp

explanation

protected java.util.BitSet explanation
Set of all the constraint in the explain.


pb

protected PalmProblem pb
The current problem.

Constructor Detail

GenericExplanation

public GenericExplanation(AbstractProblem pb)
Initializes the explain set.

Method Detail

reinitTimestamp

public static void reinitTimestamp()

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Pretty print of the explain.

Overrides:
toString in class java.lang.Object

add

public void add(Propagator constraint)
Adds a new constraint in the explain.

Specified by:
add in interface ConstraintCollection
Parameters:
constraint - The constraint that should be added to the explain. It must be a PalmConstraint.

delete

public void delete(Propagator constraint)
Deletes a constraint from the explain.

Specified by:
delete in interface ConstraintCollection
Parameters:
constraint - The constraint that must be removed.

addAll

public void addAll(java.util.Collection collection)
Description copied from interface: ConstraintCollection
Adds several constraints at a time

Specified by:
addAll in interface ConstraintCollection
Parameters:
collection - The set of constraints

merge

public void merge(ConstraintCollection explanation)
Merges an explain in the current one.

Specified by:
merge in interface ConstraintCollection
Parameters:
explanation - The explain with the constraints to add.

isEmpty

public boolean isEmpty()
Checks if the explain is empty (that is wether the size of the set is null).

Specified by:
isEmpty in interface ConstraintCollection

size

public int size()
Get the size of the bitSet

Specified by:
size in interface ConstraintCollection
Returns:
the size of the explanation

empties

public void empties()
Clears the constraint set.

Specified by:
empties in interface Explanation

toSet

public java.util.Set toSet()
Creates a set with all the constraints in the explain.

Specified by:
toSet in interface Explanation
Returns:
The explain as a set.

getBitSet

public java.util.BitSet getBitSet()
Copies the explain set and returns the new bitset.

Specified by:
getBitSet in interface PalmExplanation
Returns:
The explain as a BitSet.

contains

public boolean contains(Propagator constraint)
Checks if the explain contains a constraint.

Specified by:
contains in interface ConstraintCollection
Parameters:
constraint - The constraint to search.

copy

public ConstraintCollection copy()
Clones the explain as a new one.

Specified by:
copy in interface ConstraintCollection

isValid

public boolean isValid()
Checks if the explain is valid, that is wether all the constraint are active.

Specified by:
isValid in interface PalmExplanation

isValid

public boolean isValid(int time)
Description copied from interface: PalmExplanation
Checks if the explain is valid, that is wether all the constraint are active. Moreover, it checks that all constraints were poseted before the specified date.

Specified by:
isValid in interface PalmExplanation

containsAll

public boolean containsAll(ConstraintCollection expl)
Checks if another explain is included in this one.

Specified by:
containsAll in interface ConstraintCollection
Parameters:
expl - The explain that is tested to be included.

clear

public void clear()
Deletes all indirect constraints.

Specified by:
clear in interface ConstraintCollection

addDependencies

public void addDependencies()
Updates dependencies.


removeDependencies

public void removeDependencies(Constraint removed)
Removes all dependencies except for one constraint.

Parameters:
removed -

makeIncInfExplanation

public IBoundExplanation makeIncInfExplanation(int inf,
                                               PalmIntVar var)
Makes an IncInfExplanation from the current explain by adding dependencies.

Specified by:
makeIncInfExplanation in interface PalmExplanation
Parameters:
inf - The previous value of the bound.
var - The involved variable.

makeDecSupExplanation

public IBoundExplanation makeDecSupExplanation(int sup,
                                               PalmIntVar var)
Makes a DecSupExplanation from the current explain by adding dependencies.

Specified by:
makeDecSupExplanation in interface PalmExplanation
Parameters:
sup - The previous value of the bound.
var - The involved variable.

makeRemovalExplanation

public IRemovalExplanation makeRemovalExplanation(int value,
                                                  PalmIntVar var)
Makes a RemovalExplanation from the current explain by adding dependencies.

Specified by:
makeRemovalExplanation in interface PalmExplanation
Parameters:
value - The removed value of the domain.
var - The involved variable.

makeIncInfExplanation

public RealBoundExplanation makeIncInfExplanation(double inf,
                                                  PalmRealVar var)
Makes an IncInfExplanation from the current explain by adding dependencies.

Specified by:
makeIncInfExplanation in interface PalmExplanation
Parameters:
inf - The previous value of the bound.
var - The involved variable.

makeDecSupExplanation

public RealBoundExplanation makeDecSupExplanation(double sup,
                                                  PalmRealVar var)
Makes a DecSupExplanation from the current explain by adding dependencies.

Specified by:
makeDecSupExplanation in interface PalmExplanation
Parameters:
sup - The previous value of the bound.
var - The involved variable.

postUndoRemoval

public void postUndoRemoval(Constraint constraint)
Posts a restoration prop.

Specified by:
postUndoRemoval in interface PalmExplanation
Parameters:
constraint -

toNogood

public java.util.Set toNogood()

getConstraint

public Propagator getConstraint(int i)
Description copied from interface: Explanation
return the i-th constraint of the explanation

Specified by:
getConstraint in interface Explanation
Parameters:
i - : the number of the constraint to return

getNogood

public SymbolicDecision[] getNogood()
Description copied from interface: Explanation
return the nogood associated to the explanation

Specified by:
getNogood in interface Explanation