CSPGen
Class BinaryConstraint

java.lang.Object
  extended byCSPGen.BinaryConstraint

public class BinaryConstraint
extends java.lang.Object

This class is used to store the data structure of a single binary constraint. Only on instance of this class need be created for each edge in the constraint graph. When an instance of this class is created it will notified both Variables that it constraints of itself. Thus all the variables of a problem should be created before any BinaryCosntraints are created.
There can be only ONE instance of this class per edge in the graph. Additional instances will be rejected.

An instance of this class is immutable once created.

See Also:
Variable, Problem

Field Summary
protected  boolean[][] truthTable
          Stores the truth table of this constraint.
 Variable V1
          The first variable involved in this constraint.
 Variable V2
          The second variable involved in this constraint.
 
Constructor Summary
protected BinaryConstraint()
          Deprecated. DO NOT USE.
protected BinaryConstraint(Variable v1, Variable v2, boolean[][] truthTable)
          Constructs a new binary constraint.
 
Method Summary
 boolean equals(java.lang.Object o)
          Determines if this constraint is equal to the given instance.
 boolean isSatisfied()
          Checks if this constraint is satisfied given the current state of the problem.
 boolean isViolated()
          Checks if this constraint is violated given the current state of the problem.
 java.lang.String toString()
          Returns a string representation of this BinaryConstraint.
 boolean truthTable(int x1, int x2)
          The truth table of this constraint.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

V1

public final Variable V1
The first variable involved in this constraint.

See Also:
Variable

V2

public final Variable V2
The second variable involved in this constraint.

See Also:
Variable

truthTable

protected boolean[][] truthTable
Stores the truth table of this constraint. This struture should be set at creation time and then should not be changed.

See Also:
truthTable(int x1, int x2)
Constructor Detail

BinaryConstraint

protected BinaryConstraint()
Deprecated. DO NOT USE.


BinaryConstraint

protected BinaryConstraint(Variable v1,
                           Variable v2,
                           boolean[][] truthTable)
Constructs a new binary constraint.

Parameters:
v1 - the first variable of the constraint
v2 - the second variable of the constraint
truthTable - a complete truth table for this constraint of size d1 by d2. The array is NOT cloned.
Throws:
java.lang.IllegalArgumentException - if the truth table is too small
See Also:
truthTable
Method Detail

truthTable

public boolean truthTable(int x1,
                          int x2)
The truth table of this constraint.
truthTable[x1][x2]==true means v1=x1 and v2=x2 is consistent under this constraint

Parameters:
x1 - the value of the first variable
x2 - the value of the second variable
See Also:
isSatisfied()

isSatisfied

public boolean isSatisfied()
Checks if this constraint is satisfied given the current state of the problem.

Returns:
true iff both variables are assigned and consistant under this constraint
false under any other conditions
See Also:
truthTable(int x1, int x2)

isViolated

public boolean isViolated()
Checks if this constraint is violated given the current state of the problem.

Returns:
true if and only if both variables are instantiated and are inconsistant with each other.
false in all other cases.
See Also:
truthTable(int x1, int x2)

equals

public boolean equals(java.lang.Object o)
Determines if this constraint is equal to the given instance.

Requirements are that the two variables of the constraint must be the same (determined using ==) and that the two constraints have the exact same truth table.
Under normal circumstances (bc1==bc2) should yield the same results as (bc.equals(bc)).

Parameters:
o - the object to which the comparison is made

toString

public java.lang.String toString()
Returns a string representation of this BinaryConstraint. The format of the string is:

The truth table is using nested for loops with the first dimension on the outside and the second on the inside.