public class ConstraintNetwork
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
Constraints. It is used by all
ConstraintSolvers and provides methods to add and remove Variables, Constraints, querying the
network for constraints, incident edges, etc. It also provide basic graphical rendering functions.| Modifier and Type | Field and Description |
|---|---|
java.lang.Object |
annotation |
static java.util.HashMap<org.metacsp.framework.ConstraintNetwork.FieldOfObject,java.lang.Object> |
backupForSerialization |
protected edu.uci.ics.jung.graph.DirectedSparseMultigraph<Variable,Constraint> |
g |
protected edu.uci.ics.jung.graph.ObservableGraph<Variable,Constraint> |
graph |
protected java.util.HashMap<Constraint,DummyVariable> |
hyperEdges |
int |
ID |
static int |
IDs |
ConstraintNetworkMarking |
marking |
protected ConstraintSolver |
solver |
java.lang.Object |
specilizedAnnotation |
protected java.util.HashMap<Variable,VariablePrototype> |
substituted |
protected java.util.HashMap<VariablePrototype,Variable> |
substitutions |
protected java.util.HashMap<java.lang.Integer,Variable> |
variables |
protected java.util.HashMap<Variable,java.lang.Integer> |
variablesR |
| Constructor and Description |
|---|
ConstraintNetwork(ConstraintSolver sol)
Instantiates a new
ConstraintNetwork. |
| Modifier and Type | Method and Description |
|---|---|
void |
addConstraint(Constraint c)
Adds a
Constraint to the network. |
void |
addConstraintNetworkChangeListener(ConstraintNetworkChangeListener listener) |
void |
addConstraints(Constraint... cons)
Adds a set of
Constraints to the network. |
void |
addSubstitution(VariablePrototype vp,
Variable v)
Convenience method to keep track of correspondences between
VariablePrototypes and Variables (useful
when ConstraintNetworks are used as meta-values in MetaConstraintSolvers). |
void |
addSubstitutions(org.apache.commons.collections15.map.HashedMap<VariablePrototype,Variable> vp2v)
Convenience method to keep track of correspondences between
VariablePrototypes and Variables (useful
when ConstraintNetworks are used as meta-values in MetaConstraintSolvers). |
void |
addVariable(Variable v)
Adds a given
Variable to the network. |
Variable |
checkDomainsInstantiated()
Checks whether the domains of the
Variables in the ConstraintNetwork are instantiated. |
java.lang.Object |
clone()
Clone this
ConstraintNetwork. |
boolean |
containsConstraint(Constraint c)
Query the network for the existence of a given
Constraint. |
boolean |
containsVariable(int ID)
Query the network for the existence of a
Variable with a given ID. |
boolean |
containsVariable(Variable v)
Query the network for the existence of a given
Variable. |
static void |
draw(ConstraintNetwork cn)
Same as the static two-argument draw method, using the
ConstraintNetwork's simple class name as the
title of the JFrame. |
static void |
draw(ConstraintNetwork cn,
Callback cb)
Same as the static two-argument draw method, using the
ConstraintNetwork's simple class name as the
title of the JFrame. |
static void |
draw(ConstraintNetwork cn,
java.lang.String title)
A static method for drawing
ConstraintNetworks. |
static void |
draw(ConstraintNetwork cn,
java.lang.String title,
Callback cb)
A static method for drawing
ConstraintNetworks. |
boolean |
equals(java.lang.Object o)
Checks if the given
ConstraintNetwork is equal to this. |
java.lang.Object |
getAnnotation()
Get the annotation for this
ConstraintNetwork. |
Constraint |
getConstraint(Variable from,
Variable to)
Returns the
Constraint between two given Variables (if it exists). |
Constraint[] |
getConstraints()
Get all
Constraints in the network. |
Constraint[] |
getConstraints(Variable from,
Variable to)
Returns all
Constraints between two given Variables. |
java.lang.String |
getEdgeLabel()
Get a
String representation of this ConstraintNetwork
(note that MetaConstraintSolvers use ConstraintNetworks as resolvers,
therefore this method is used to draw the edge label in the search tree rendering). |
edu.uci.ics.jung.graph.ObservableGraph<Variable,Constraint> |
getGraph() |
int |
getID() |
Constraint[] |
getIncidentEdges(Variable v)
Get all
Constraints involving a given Variable. |
Constraint[] |
getIncidentEdgesIncludingDependentVariables(Variable v)
Get all
Constraints involving a given Variable, along with all the constraints involving
the dependent variables of this variable (recursively). |
Constraint[] |
getIngoingEdges(Variable v)
Get all
Constraints for which a given Variable is source. |
java.util.HashMap<Variable,VariablePrototype> |
getInverseSubstitutions()
Get all the inverse substitutions of
VariablePrototypes to Variables. |
ConstraintNetworkMarking |
getMarking()
Get the marking of this
ConstraintNetwork. |
Constraint[] |
getMaskedConstraints()
Get all
Constraints that are not masked. |
Variable[] |
getNeighboringVariables(Variable var)
|
Constraint[] |
getOutgoingEdges(Variable v)
Get all
Constraints for which a given Variable is destination. |
java.lang.Object |
getSpecilizedAnnotation() |
VariablePrototype |
getSubstituted(Variable v)
Get the
VariablePrototype corresponding to a given Variable (see addSubstitution() method). |
Variable |
getSubstitution(VariablePrototype vp)
Get the
Variable corresponding to a given VariablePrototype (see addSubstitution() method). |
java.util.HashMap<VariablePrototype,Variable> |
getSubstitutions()
Get all the substitutions of
VariablePrototypes to Variables. |
Constraint[] |
getUnmaskedConstraints()
Get all
Constraints that are not masked. |
Variable |
getVariable(int id)
Gets a
Variable given its ID. |
Variable |
getVariableFrom(Constraint c)
Gets the source
Variable of a given (binary) Constraint. |
Variable[] |
getVariables()
Get all variables in the network.
|
Variable[] |
getVariables(java.lang.String component)
Get all variables in the network with a given component.
|
Variable[] |
getVariables(java.lang.String component,
java.lang.Object... markingsToExclude)
Get all variables in the network with a given component.
|
Variable |
getVariableTo(Constraint c)
Gets the destination
Variable of a given (binary) Constraint. |
double |
getWeight()
Weight associated to the
ConstraintNetwork for some metrics. |
void |
join(ConstraintNetwork cn)
Merges the given
ConstraintNetwork to this. |
static ConstraintNetwork |
loadConstraintNetwork(java.io.File file) |
static ConstraintNetwork |
loadConstraintNetwork(java.lang.String filename) |
void |
maskConstraints()
Masks all
Constraints in this ConstraintNetwork. |
static void |
maskConstraints(Constraint[] cons)
Masks all given
Constraints. |
void |
removeConstraint(Constraint c)
Removes a given
Constraint from the network. |
void |
removeSubstitution(VariablePrototype vp)
Remove the
Variable corresponding to a given VariablePrototype (see addSubstitution() method). |
void |
removeVariable(Variable v)
Removes a given
Variable from the network. |
static void |
saveConstraintNetwork(ConstraintNetwork cn,
java.io.File file) |
static void |
saveConstraintNetwork(ConstraintNetwork cn,
java.lang.String filename) |
void |
setAnnotation(java.lang.Object ann)
Set an annotation for this
ConstraintNetwork. |
void |
setMarking(ConstraintNetworkMarking marking)
Set the marking of this
ConstraintNetwork. |
void |
setSpecilizedAnnotation(java.lang.Object specilizedAnnotation) |
void |
setWeight(double weight)
Weight to associate to the
ConstraintNetwork for some metrics. |
java.lang.String |
toString()
Get a
String representation of this ConstraintNetwork. |
void |
unmaskConstraints()
Unmasks all
Constraints in this ConstraintNetwork. |
static void |
unmaskConstraints(Constraint[] cons)
Unmasks all given
Constraints. |
public static java.util.HashMap<org.metacsp.framework.ConstraintNetwork.FieldOfObject,java.lang.Object> backupForSerialization
protected ConstraintSolver solver
protected edu.uci.ics.jung.graph.ObservableGraph<Variable,Constraint> graph
protected edu.uci.ics.jung.graph.DirectedSparseMultigraph<Variable,Constraint> g
protected java.util.HashMap<java.lang.Integer,Variable> variables
protected java.util.HashMap<Variable,java.lang.Integer> variablesR
protected java.util.HashMap<VariablePrototype,Variable> substitutions
protected java.util.HashMap<Variable,VariablePrototype> substituted
protected java.util.HashMap<Constraint,DummyVariable> hyperEdges
public transient java.lang.Object annotation
public transient java.lang.Object specilizedAnnotation
public ConstraintNetworkMarking marking
public static int IDs
public int ID
public ConstraintNetwork(ConstraintSolver sol)
ConstraintNetwork. Note that all implementing classes must call this constructor
(i.e., specifying a ConstraintSolver is mandatory).sol - The ConstraintSolver which maintains this ConstraintNetwork.public void addConstraintNetworkChangeListener(ConstraintNetworkChangeListener listener)
public edu.uci.ics.jung.graph.ObservableGraph<Variable,Constraint> getGraph()
public int getID()
public java.lang.Object getSpecilizedAnnotation()
public void setSpecilizedAnnotation(java.lang.Object specilizedAnnotation)
public void addSubstitution(VariablePrototype vp, Variable v)
VariablePrototypes and Variables (useful
when ConstraintNetworks are used as meta-values in MetaConstraintSolvers).vp - The VariablePrototype.v - The Variable that corresponds to the given VariablePrototype.public void addSubstitutions(org.apache.commons.collections15.map.HashedMap<VariablePrototype,Variable> vp2v)
VariablePrototypes and Variables (useful
when ConstraintNetworks are used as meta-values in MetaConstraintSolvers).vp2v - Mapping between VariablePrototypes and Variables.public Variable getSubstitution(VariablePrototype vp)
Variable corresponding to a given VariablePrototype (see addSubstitution() method).vp - The VariablePrototype to look up.Variable corresponding to the given VariablePrototype.public VariablePrototype getSubstituted(Variable v)
VariablePrototype corresponding to a given Variable (see addSubstitution() method).v - The Variable to look up.VariablePrototype corresponding to the given Variable.public void removeSubstitution(VariablePrototype vp)
Variable corresponding to a given VariablePrototype (see addSubstitution() method).vp - The VariablePrototype to look up.public Constraint getConstraint(Variable from, Variable to)
Constraint between two given Variables (if it exists).
If more than one exists, it returns one of them (no guarantees as to which one).from - The source variable of the Constraint to find.to - The destination variable of the Constraint to find.Constraint between the two given Variables, null if
no such Constraint exists.public Constraint[] getConstraints(Variable from, Variable to)
Constraints between two given Variables.from - The source variable of the Constraints to find.to - The destination variable of the Constraints to find.Constraints between the two given Variables, null if
no such Constraint exists.public void addVariable(Variable v)
Variable to the network.v - The Variable to add to the network.public void removeVariable(Variable v)
Variable from the network.v - The Variable to remove from the network.public void addConstraints(Constraint... cons)
Constraints to the network.cons - The Constraints to add to the network. NOTE: this only works for
BinaryConstraints and MultiBinaryConstraints in the current implementation.public void addConstraint(Constraint c)
Constraint to the network.c - The Constraint to add to the network. NOTE: this only works for
BinaryConstraints and MultiBinaryConstraints in the current implementation.public void removeConstraint(Constraint c)
Constraint from the network.c - The Constraint to remove from the network.public Variable getVariableFrom(Constraint c)
Variable of a given (binary) Constraint.c - The Constraint from which to get the source Variable.Variable of the given Constraint.public Variable getVariableTo(Constraint c)
Variable of a given (binary) Constraint.c - The Constraint from which to get the destination Variable.Variable of the given Constraint.public Variable checkDomainsInstantiated()
Variables in the ConstraintNetwork are instantiated.
This is used by the ConstraintSolver class to assess whether automatic propagation
should occur (in some CSPs, domains of Variables cannot be instantiated by the Variable constructor,
rather an explicit call to a dedicated method is necessary).null if all domains are instantiated; a Variable whose domain is not instantiated if one exists.public static void draw(ConstraintNetwork cn, java.lang.String title)
ConstraintNetworks. This method is static so that
it can be called to draw an object of a subclass (Java enforces late-binding). This method instantiated a JFrame
containing a rendering of the ConstraintNetwork. The rendering is dynamic and attempts to animate transitions
when Constraint and/or Variables are added/removed from the network.cn - The ConstraintNetwork to draw.title - The title of the JFrame containing the rendered ConstraintNetwork.public static void draw(ConstraintNetwork cn, java.lang.String title, Callback cb)
ConstraintNetworks. This method is static so that
it can be called to draw an object of a subclass (Java enforces late-binding). This method instantiated a JFrame
containing a rendering of the ConstraintNetwork. The rendering is dynamic and attempts to animate transitions
when Constraint and/or Variables are added/removed from the network.cn - The ConstraintNetwork to draw.title - The title of the JFrame containing the rendered ConstraintNetwork.cb - A Callback object to use when the button is pressed.public static void draw(ConstraintNetwork cn)
ConstraintNetwork's simple class name as the
title of the JFrame.cn - The ConstraintNetwork to draw.public static void draw(ConstraintNetwork cn, Callback cb)
ConstraintNetwork's simple class name as the
title of the JFrame.cn - The ConstraintNetwork to draw.cb - A Callback object to use when the button is pressed.public Constraint[] getIncidentEdges(Variable v)
Constraints involving a given Variable.v - The Variable involved in the Constraints.Constraints involving the given Variable.public Constraint[] getIncidentEdgesIncludingDependentVariables(Variable v)
Constraints involving a given Variable, along with all the constraints involving
the dependent variables of this variable (recursively).v - The Variable involved in the Constraints.Constraints involving the given Variable (including those
involving dependent variables of this variable, recursively).public Constraint[] getIngoingEdges(Variable v)
Constraints for which a given Variable is source.v - The Variable involved in the Constraints.Constraints for which a given Variable is source.public Constraint[] getOutgoingEdges(Variable v)
Constraints for which a given Variable is destination.v - The Variable involved in the Constraints.Constraints for which a given Variable is destination.public Variable[] getVariables()
public Variable[] getVariables(java.lang.String component, java.lang.Object... markingsToExclude)
public Variable[] getVariables(java.lang.String component)
public Constraint[] getConstraints()
Constraints in the network.Constraints in the network.public boolean containsConstraint(Constraint c)
Constraint.c - The Constraint for the query.true iff the network contains the given Constraintpublic boolean containsVariable(Variable v)
Variable.public boolean containsVariable(int ID)
Variable with a given ID.public java.lang.String getEdgeLabel()
String representation of this ConstraintNetwork
(note that MetaConstraintSolvers use ConstraintNetworks as resolvers,
therefore this method is used to draw the edge label in the search tree rendering).String representation of this Constraint.public java.lang.String toString()
String representation of this ConstraintNetwork.toString in class java.lang.ObjectString representation of this ConstraintNetwork.public void join(ConstraintNetwork cn)
ConstraintNetwork to this.cn - The ConstraintNetwork to merge into this.public boolean equals(java.lang.Object o)
ConstraintNetwork is equal to this.equals in class java.lang.Objecttrue iff the given ConstraintNetwork has the same
Variables and the same Constraints as this.public double getWeight()
ConstraintNetwork for some metrics.ConstraintNetworkpublic void setWeight(double weight)
ConstraintNetwork for some metrics.weight - Weight related to the ConstraintNetwork.public java.lang.Object clone()
ConstraintNetwork.clone in class java.lang.ObjectConstraintNetwork of the runtime type of the original.public void setAnnotation(java.lang.Object ann)
ConstraintNetwork.ann - An object that should be used to annotate this ConstraintNetwork.public java.lang.Object getAnnotation()
ConstraintNetwork.ConstraintNetwork.public java.util.HashMap<VariablePrototype,Variable> getSubstitutions()
VariablePrototypes to Variables.VariablePrototypes to Variables.public java.util.HashMap<Variable,VariablePrototype> getInverseSubstitutions()
VariablePrototypes to Variables.VariablePrototypes to Variables.public ConstraintNetworkMarking getMarking()
ConstraintNetwork.ConstraintNetwork.public void setMarking(ConstraintNetworkMarking marking)
ConstraintNetwork.marking - The marking of this ConstraintNetwork.public Variable[] getNeighboringVariables(Variable var)
var - The Variable from which the connected Variables are to be computed.Variables that are directly connected to a given Variable through one Constraint.public void maskConstraints()
Constraints in this ConstraintNetwork.public void unmaskConstraints()
Constraints in this ConstraintNetwork.public static void maskConstraints(Constraint[] cons)
Constraints.cons - The Constraints to mask.public static void unmaskConstraints(Constraint[] cons)
Constraints.cons - The Constraints to unmask.public Constraint[] getUnmaskedConstraints()
Constraints that are not masked.Constraints that are not masked.public Constraint[] getMaskedConstraints()
Constraints that are not masked.Constraints that are not masked.public static void saveConstraintNetwork(ConstraintNetwork cn, java.lang.String filename)
public static void saveConstraintNetwork(ConstraintNetwork cn, java.io.File file)
public static ConstraintNetwork loadConstraintNetwork(java.lang.String filename)
public static ConstraintNetwork loadConstraintNetwork(java.io.File file)