|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.ObjectCSPGen.Variable
An instance of this class represents one variable in a CSP. Each instance stores the curren tvalue of the variable, the constraints the variable is involved in, the livedomain, the order (a unique ID number for the variable), and the domain size of the variable. The constructor of this class should be called within the constructor of the Problem class with the value of domain size and order of variables so that user of this generator need not access it.
Since this is a generator of Flawless Random CSPs, and in Random CSPs, all the variables are supposed to have same domain, there is no "domain" field in this class. The domain consists of all the integers on [0,domainsize). For similar reasons each instance is identified by a unique ID number stored in the id field instead of a name.
Problem,
BinaryConstraint| Field Summary | |
protected java.util.ArrayList |
constraints
The pool of all binary constraints this variable is involved in. |
protected int |
currentValue
The current value of this variable. |
int |
domainSize
The domain size of this variable. |
int |
id
The unique identifier of this variable. |
protected boolean[] |
liveDomain
The data structure to record if values are still in the livedomain. |
Problem |
problem
|
| Constructor Summary | |
protected |
Variable(Problem p,
int d,
int id)
The constructor of a Variable object, it will be called in the constructor of Problem Class |
| Method Summary | |
protected void |
addConstraint(BinaryConstraint bc)
Called by the BinaryConstraint class constructor to notify the Variable that it is constrained by the given constraint. |
boolean |
constrainedBy(int v)
Returns true iff this variable shares a constraint with the given variable. |
boolean |
constrainedBy(Variable v)
Returns true iff this variable shares a constraint with the given variable. |
java.util.Enumeration |
constraints()
Returns an enumeration on all the constraints involving this Variable. |
BinaryConstraint |
constraintWith(int v)
Checks if this variable shares are constraint with the given variable. |
BinaryConstraint |
constraintWith(Variable v)
Checks if this variable shares are constraint with the given variable. |
void |
eliminateValue(int x)
Removes the given value from into the live domain of this variable. |
static boolean |
equal(Variable v1,
Variable v2)
This method determines if two variables are in fact the same one. |
boolean |
equals(java.lang.Object o)
Determines if this instance is equal to the given instance. |
int |
getValue()
Returns the current assignment of this variable. |
boolean |
isConsistant()
Returns true iff none of the constraints on this variable are violated. |
boolean |
liveDomain(int x)
Returns true iff the given value is in this variable's live domain. |
int |
numConstraints()
Returns the total number of constraints on this Variable. |
void |
releaseAllValues()
Adds all possible values back into the live domain of this variable. |
void |
releaseValue(int x)
Adds the given value back into the live domain of this variable. |
void |
setValue(int v)
Sets the current assignment of this variable. |
int |
value()
Returns the current assignment of this variable. |
void |
value(int v)
Sets the current assignment of this variable. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public final int id
All identifiers should be in [0, n) where n is the number of variables.
public final int domainSize
public final Problem problem
protected int currentValue
protected boolean[] liveDomain
All values in the array will be initialized to true.
protected java.util.ArrayList constraints
| Constructor Detail |
protected Variable(Problem p,
int d,
int id)
p - the creating Problemid - the identifier (order) of this variabled - the domain size of this variable| Method Detail |
public boolean constrainedBy(Variable v)
v - the Variable to be checkedpublic boolean constrainedBy(int v)
v - the id of the Variable to be checkedpublic BinaryConstraint constraintWith(Variable v)
v - the Variable to be checked
null is returned.public BinaryConstraint constraintWith(int v)
v - the id of the Variable to be checked
null is returned.public boolean isConsistant()
protected void addConstraint(BinaryConstraint bc)
bc - the BinaryConstraint making the callpublic int numConstraints()
public java.util.Enumeration constraints()
public static boolean equal(Variable v1,
Variable v2)
v1 - the first variable to be comparedv2 - the second variable to be compared
true if these two variables have the same id
false otherwise.public int value()
public int getValue()
public void value(int v)
If the given value is >= the domain size then the current value will be set to -1.
public void setValue(int v)
If the given value is >= the domain size then the current value will be set to -1.
value(int v)public boolean liveDomain(int x)
java.lang.ArrayIndexOutOfBoundsException - if the given value
is not part of this variable's domainpublic void eliminateValue(int x)
java.lang.ArrayIndexOutOfBoundsException - if the given value
is not part of this variable's domainpublic void releaseValue(int x)
java.lang.ArrayIndexOutOfBoundsException - if the given value
is not part of this variable's domainpublic void releaseAllValues()
public boolean equals(java.lang.Object o)
Requirements are that the two variables have the same problem (determined using ==) and that they have the same id. Under normal circumstances (v1==v2) should yield the same results as (v1.equals(v2)).
o - the object to which the comparison is made
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||