omnics
Class Var

java.lang.Object
  extended by omnics.Var
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable
Direct Known Subclasses:
IntVar

public class Var
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

Represents a variable of a constraint satisfaction problem.

Author:
Cristian Frasinaru
See Also:
Serialized Form

Constructor Summary
Var(java.lang.String name)
          Creates a new instance of Var, having a specified name and no domain (the domain is null).
Var(java.lang.String name, Domain domain)
          Creates a new instance of Var, having a specified name and a specified domain.
 
Method Summary
 int compareTo(java.lang.Object object)
          Specifies how two variables are compared to each other.
 ConstraintSet getConstraints()
          Gets a reference to the collection of constraints this variable holds, consisting of constraints in which it is involved.
 ConstraintSet getConstraints(Var var)
          Returns the constraints of the problem which contain this variable and the variable given as argument.
 java.lang.Object getData()
          Gets the annotation of this variable.
 Domain getDomain()
          Gets a reference to the domain of the variable.
 int getIndex()
          Gets the index of the variable in the set of the problems variables.
 Domain getInitialDomain()
          Gets the initial domain of the solver.
 java.lang.String getName()
          Gets the name of the variable.
 Problem getProblem()
          Gets the problem this variable belongs to.
 java.util.List<java.lang.Object> getSupportFor(Var x, java.lang.Object a)
          Constructs the support set for x=a from this variable.
 java.lang.Object getValue()
          Gets the value assigned to this variable in the current partial solution.
 boolean isActive()
          Returns true if the variable is active.
 boolean isInstantiated()
          Returns true if this variable has been instantiated.
 boolean isTarget()
           
 void restoreInitialDomain()
          Sets the domain of this variable to be a copy of its initial domain.
 void setActive(boolean active)
          Sets the active status of the variable.
 void setData(java.lang.Object data)
          Sets the annotation of this variable.
 void setDomain(Domain domain)
          Sets the domain of the variable.
 void setName(java.lang.String name)
          Sets the name of the variable.
 void setTarget(boolean target)
           
 void setValue(java.lang.Object value)
          Assigns a value to this variable in the current partial solution.
 java.lang.String toString()
          Returns a string representation of this variable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Var

public Var(java.lang.String name)
Creates a new instance of Var, having a specified name and no domain (the domain is null).

Parameters:
name - the name of the variable

Var

public Var(java.lang.String name,
           Domain domain)
Creates a new instance of Var, having a specified name and a specified domain.

Parameters:
name - the name of the variable
domain - the domain of the variable
See Also:
Domain
Method Detail

getProblem

public Problem getProblem()
Gets the problem this variable belongs to. This information is set when the variable is added to a problem.

Returns:
the problem this variable belongs to or null if the variable has not been added to a problem.

getName

public java.lang.String getName()
Gets the name of the variable.

Returns:
the name of the variable

setName

public void setName(java.lang.String name)
Sets the name of the variable. The names of a problem's variables must be unique.

Parameters:
name - the name given to this variable
Throws:
IllegalArgumentException - if the name is not unique

getData

public java.lang.Object getData()
Gets the annotation of this variable. Every variable can be annotated, meaning that it can hold an object of any type which represents some information specific to a problem. For instance, if this variable represents the vertex of a grah, its data can hold a reference to the corresponding vertex of the graph.

Returns:
the annotation of this variable or null if there is no annotation

setData

public void setData(java.lang.Object data)
Sets the annotation of this variable. Every variable can be annotated, meaning that it can hold an object of any type which represents some information specific to a problem. For instance, if this variable represents the vertex of a grah, its data can hold a reference to the corresponding vertex of the graph.

Parameters:
data - the annotation associated to this variable

getIndex

public int getIndex()
Gets the index of the variable in the set of the problems variables.

Returns:
the index of the variable

getDomain

public Domain getDomain()
Gets a reference to the domain of the variable.

Returns:
the domain of the variable

setDomain

public void setDomain(Domain domain)
Sets the domain of the variable. If the solver is not running yet, the domain is stored as the initial domain of the variable.

Parameters:
domain - the domain of the variable
See Also:
getInitialDomain()

getInitialDomain

public Domain getInitialDomain()
Gets the initial domain of the solver. The initial domain of a variable is the domain set for the variable when the problem's solver is not running.

Returns:
the initial domain of this variable

restoreInitialDomain

public void restoreInitialDomain()
Sets the domain of this variable to be a copy of its initial domain. The copy is necessary in order not to corrupt the initial domain.


getConstraints

public ConstraintSet getConstraints()
Gets a reference to the collection of constraints this variable holds, consisting of constraints in which it is involved. This is redundant information maintained for performance reasons.

Returns:
the constraints of the problem which contain this variable.

getConstraints

public ConstraintSet getConstraints(Var var)
Returns the constraints of the problem which contain this variable and the variable given as argument.


getValue

public java.lang.Object getValue()
Gets the value assigned to this variable in the current partial solution.

Returns:
the value assigned to this variable in the current partial solution or null if the variable has not been instantiated

setValue

public void setValue(java.lang.Object value)
Assigns a value to this variable in the current partial solution.

Parameters:
value - the value to be assigned to this variable.

isInstantiated

public boolean isInstantiated()
Returns true if this variable has been instantiated. This is a convenience method for testing getValue() != null.

Returns:
true if this variable has been instantiated

getSupportFor

public java.util.List<java.lang.Object> getSupportFor(Var x,
                                                      java.lang.Object a)
Constructs the support set for x=a from this variable. Let us denote with y this variable. The method searches for values b in Dy such that the tuple ((x=a), (y=b)) satisfies all the problem's constraints.

Parameters:
x - some variable, other than this
a - some value from x's domain
Returns:
a list of values from this variable's domain that support the instantiation x=a

compareTo

public int compareTo(java.lang.Object object)
Specifies how two variables are compared to each other.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
object - an object representing a variable
Returns:
the difference of indices of this variable and the other's.

toString

public java.lang.String toString()
Returns a string representation of this variable. It actually returns the name of the variable.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this variable.

isActive

public boolean isActive()
Returns true if the variable is active. A variable which is not active is ignored by the solver, meaning that it will not be instantiated.

Returns:
true if the variable is active

setActive

public void setActive(boolean active)
Sets the active status of the variable. A variable which is not active is ignored by the solver, meaning that it will not be instantiated.

Parameters:
active - if true, the variable is active, otherwise it is not

isTarget

public boolean isTarget()

setTarget

public void setTarget(boolean target)