public abstract class ConstraintSolver
extends java.lang.Object
implements java.io.Serializable
MultiConstraint class. The latter is in fact an extension of this class,
as it implements the, addConstraintsSub() and
removeConstraintsSub() methods.
This abstract class also maintains a ConstraintNetwork, which is
represented internally as a graph. Any specific solver must implement this abstract class
to provide methods to create/remove variables, add/remove constraints, and perform
propagation.| Modifier and Type | Class and Description |
|---|---|
static class |
ConstraintSolver.OPTIONS
General class options.
|
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
autoprop |
protected java.util.HashMap<java.lang.String,java.util.ArrayList<Variable>> |
components |
protected java.lang.Class<?>[] |
constraintTypes |
protected int |
IDs |
protected java.util.logging.Logger |
logger |
protected java.lang.String |
name |
protected static int |
nesting |
protected boolean |
noPropOnVarCreation |
static int |
numcalls |
protected boolean |
skipPropagation |
protected static java.lang.String |
spacing |
protected ConstraintNetwork |
theNetwork
Access to the underlying constraint network.
|
protected java.lang.Class<?> |
variableType |
| Modifier | Constructor and Description |
|---|---|
protected |
ConstraintSolver(java.lang.Class<?>[] constraintTypes,
java.lang.Class<?> variableType)
Default constructor for this class.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addConstraint(Constraint c)
Add a constraint between
Variables. |
boolean |
addConstraintNoPropagation(Constraint c)
Add a constraint between
Variables, without propagation. |
boolean |
addConstraints(Constraint... c)
Add a batch of constraints between
Variables. |
Constraint |
addConstraintsDebug(Constraint... c)
Add a batch of constraints between
Variables. |
boolean |
addConstraintsNoPropagation(Constraint... c)
Add a batch of constraints between
Variables, but do not propagate. |
protected abstract boolean |
addConstraintsSub(Constraint[] c)
This method must be implemented by the developer of the specific
ConstraintSolver
class. |
boolean |
containsVariable(Variable v)
Return if the network of this
ConstraintSolver contains a Variable. |
Variable |
createVariable()
Factory method for creating a new
Variable for this ConstraintSolver. |
Variable |
createVariable(java.lang.String component)
Create a new
Variable for this ConstraintSolver, and
assign it to the given component label. |
Variable[] |
createVariables(int num)
Create a batch of new
Variables for this ConstraintSolver. |
Variable[] |
createVariables(int num,
java.lang.String component)
Create a batch of new
Variables for this ConstraintSolver. |
protected abstract Variable[] |
createVariablesSub(int num)
This method must be implemented by the developer of the specific
ConstraintSolver
class. |
protected Variable[] |
createVariablesSub(int num,
java.lang.String component)
This method must be implemented by the developer of the specific
ConstraintSolver
class. |
void |
deplenish()
Deplenish the network associated to the
ConstraintSolver (remove all constraints and variables). |
java.lang.String |
getComponent(Variable v)
Get the component of a given
Variable. |
java.util.HashMap<java.lang.String,java.util.ArrayList<Variable>> |
getComponents()
Get a
HashMap of all component tags with associated variables. |
ConstraintNetwork |
getConstraintNetwork()
Get the
ConstraintNetwork of this ConstraintSolver. |
Constraint[] |
getConstraints()
|
Constraint[] |
getConstraints(Variable from,
Variable to)
Get all
Constraints contained in this ConstraintSolver's ConstraintNetwork
with given source and destination Variables. |
java.lang.String |
getDescription()
Gets a description of this
ConstraintSolver stating which variable and constraint types it supports. |
int |
getID(Variable var)
Get the ID of a
Variable. |
boolean |
getOption(ConstraintSolver.OPTIONS op)
Get option value for this
ConstraintSolver. |
Variable |
getVariable(int id)
Get a
Variable given its ID. |
Variable[] |
getVariables()
|
Variable[] |
getVariables(java.lang.String component)
|
Variable[] |
getVariables(java.lang.String component,
java.lang.Object... markingsToExclude)
|
boolean |
isCompatible(Constraint c)
Assess whether a
Constraint is compatible with this ConstraintSolver. |
void |
maskConstraints(Constraint[] constraints)
Method to mask constraints; does nothing, must be overridden; always called before propagation.
|
abstract boolean |
propagate()
Propagate the constraint network.
|
abstract void |
registerValueChoiceFunctions() |
void |
removeConstraint(Constraint c)
Retract a constraint between
Variables. |
void |
removeConstraints(Constraint[] c)
Retract a batch of constraints between
Variables. |
protected abstract void |
removeConstraintsSub(Constraint[] c)
This method must be implemented by the developer of the specific
ConstraintSolver
class. |
void |
removeVariable(Variable v)
Remove a
Variable from this ConstraintSolver. |
void |
removeVariables(Variable[] v)
Remove a batch of
Variables from this ConstraintSolver. |
protected abstract void |
removeVariablesSub(Variable[] v)
This method must be implemented by the developer of the specific
ConstraintSolver
class. |
void |
setComponent(java.lang.String component,
Variable... vars)
Used to set the component of a variable.
|
void |
setComponents(java.util.HashMap<java.lang.String,java.util.ArrayList<Variable>> components)
Set the component tags of all variables.
|
void |
setConstraintNetwork(ConstraintNetwork newCS) |
void |
setName(java.lang.String name) |
void |
setOptions(ConstraintSolver.OPTIONS... ops)
Set options for this
ConstraintSolver. |
java.lang.String |
toString() |
void |
unmaskConstraints(Constraint[] constraints)
Method to unmask constraints (reverse making done in maskConstraints() method); does nothing, must be overridden; always called after propagation.
|
public static int numcalls
protected java.lang.Class<?>[] constraintTypes
protected java.lang.Class<?> variableType
protected static int nesting
protected static java.lang.String spacing
protected int IDs
protected java.lang.String name
protected ConstraintNetwork theNetwork
protected boolean autoprop
protected boolean noPropOnVarCreation
protected boolean skipPropagation
protected java.util.HashMap<java.lang.String,java.util.ArrayList<Variable>> components
protected transient java.util.logging.Logger logger
protected ConstraintSolver(java.lang.Class<?>[] constraintTypes,
java.lang.Class<?> variableType)
public void setName(java.lang.String name)
public void setOptions(ConstraintSolver.OPTIONS... ops)
ConstraintSolver.ops - Options to set (see ConstraintSolver.OPTIONS).public boolean getOption(ConstraintSolver.OPTIONS op)
ConstraintSolver.op - The option to get (see ConstraintSolver.OPTIONS).true iff the given option is set.public boolean isCompatible(Constraint c)
Constraint is compatible with this ConstraintSolver. This is used
internally to ignore processing of incompatible constraints by ConstraintSolvers that are aggregated into
MultiConstraintSolvers.c - The Constraint to check.true iff the given Constraint is compatible with this ConstraintSolver.public abstract boolean propagate()
public final boolean addConstraint(Constraint c)
Variables.c - The constraint to add.true iff the constraint was added successfully.public final boolean addConstraintNoPropagation(Constraint c)
Variables, without propagation.c - The constraint to add.true.public final Constraint addConstraintsDebug(Constraint... c)
Variables. This method is
NOT implemented so as to perform only one propagation, rather it adds all constraints
sequentially, and returns the first constraint that fails, null if no constraint
fails.c - The constraints to add.null if no constraint
fails.public final boolean addConstraintsNoPropagation(Constraint... c)
Variables, but do not propagate. This method always returns true,
hence if the constraint(s) to add are inconsistent, this will result in propagation failure the next time
a constraint is added and propagation occurs.c - The constraints to add.truepublic final boolean addConstraints(Constraint... c)
Variables. This method is
implemented so as to perform only one propagation, thus being more convenient than
performing c.length invocations of addConstraint(Constraint c).
In addition, all constraints are either accepted or rejected together.c - The constraints to add.ConstraintNetwork is consistent.
If false, the Constraint are not added.protected abstract boolean addConstraintsSub(Constraint[] c)
ConstraintSolver
class. It should implement all operations necessary to add multiple constraints, and should return
true upon success, false otherwise.c - The constraints to add.true iff the constraints were added to the ConstraintNetwork.public final void removeConstraint(Constraint c) throws ConstraintNotFound
Variables.c - The constraint to retract.ConstraintNotFoundpublic final void removeConstraints(Constraint[] c) throws ConstraintNotFound
Variables. This method should
be implemented so as to perform only one propagation, thus being more convenient than
performing c.length invocations of removeConstraint(Constraint c).
In addition, all constraints should be either accepted or rejected together.c - The constraints to add.ConstraintNotFoundprotected abstract void removeConstraintsSub(Constraint[] c)
ConstraintSolver
class. Should implement all operations necessary to remove a batch of constraints.c - The constraints to remove.public final Variable createVariable(java.lang.String component)
Variable for this ConstraintSolver, and
assign it to the given component label.component - The component label to which assign the new variable.Variable.public final Variable createVariable()
Variable for this ConstraintSolver.Variable.public void setComponent(java.lang.String component,
Variable... vars)
component - The component to set.vars - The variables that should be tagged under this component.public final Variable[] createVariables(int num)
Variables for this ConstraintSolver.num - The number of variables to create.Variables.public final Variable[] createVariables(int num, java.lang.String component)
Variables for this ConstraintSolver.num - The number of variables to create.component - The component tag to associate to these new variables.Variables.protected abstract Variable[] createVariablesSub(int num)
ConstraintSolver
class. It should implement all operations necessary to create a batch of variable for the specific
type of ConstraintSolver.num - The number of variables to create.Variable for this ConstraintSolver.protected Variable[] createVariablesSub(int num, java.lang.String component)
ConstraintSolver
class. It should implement all operations necessary to create a batch of variable for the specific
type of ConstraintSolver.component - The component label to associate to the new Variables.num - The number of Variables to create.Variable for this ConstraintSolver.public final void removeVariable(Variable v) throws VariableNotFound, IllegalVariableRemoval
Variable from this ConstraintSolver.v - The Variable to remove.VariableNotFoundIllegalVariableRemovalpublic final void removeVariables(Variable[] v) throws VariableNotFound, IllegalVariableRemoval
Variables from this ConstraintSolver.v - The batch of Variables to remove.VariableNotFoundIllegalVariableRemovalprotected abstract void removeVariablesSub(Variable[] v)
ConstraintSolver
class. It should implement all operations necessary to remove a batch of variables for
the specific type of ConstraintSolver.v - The Variables to remove.public ConstraintNetwork getConstraintNetwork()
ConstraintNetwork of this ConstraintSolver.ConstraintNetwork of this ConstraintSolver.public int getID(Variable var)
Variable.var - The Variable of which to get the ID.public Variable[] getVariables()
Variables contained in this ConstraintSolver's ConstraintNetwork.public Variable[] getVariables(java.lang.String component, java.lang.Object... markingsToExclude)
component - Only Variables associated with the given label (component) should be returned.Variables contained in this ConstraintSolver's ConstraintNetwork.public Variable[] getVariables(java.lang.String component)
component - Only Variables associated with the given label (component) should be returned.Variables contained in this ConstraintSolver's ConstraintNetwork.public Constraint[] getConstraints()
Constraints contained in this ConstraintSolver's ConstraintNetwork.public Constraint[] getConstraints(Variable from, Variable to)
Constraints contained in this ConstraintSolver's ConstraintNetwork
with given source and destination Variables.from - The source Variable of the Constraints to be obtained.to - The destination Variable of the Constraints to be obtained.Constraints contained in this ConstraintSolver's ConstraintNetwork
with given source and destination Variables.public java.lang.String getComponent(Variable v)
public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String getDescription()
ConstraintSolver stating which variable and constraint types it supports.ConstraintSolver stating which variable and constraint types it supports.public void deplenish()
ConstraintSolver (remove all constraints and variables).public java.util.HashMap<java.lang.String,java.util.ArrayList<Variable>> getComponents()
HashMap of all component tags with associated variables.HashMap whose entries are component tags and the associated variables.public void setComponents(java.util.HashMap<java.lang.String,java.util.ArrayList<Variable>> components)
components - A HashMap whose entries are the component tags and the associated variables.public boolean containsVariable(Variable v)
ConstraintSolver contains a Variable.v - The Variable variable to check.true iff the variable is present in the network.public abstract void registerValueChoiceFunctions()
public void setConstraintNetwork(ConstraintNetwork newCS)
public void maskConstraints(Constraint[] constraints)
constraints - The constraints that are being added by this call to propagate.public void unmaskConstraints(Constraint[] constraints)
constraints - The constraints that were added by this call to propagate.