org.opt4j.satdecoding
Class Constraint

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<Term>
              extended by org.opt4j.satdecoding.Constraint
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<Term>, java.util.Collection<Term>, java.util.List<Term>, java.util.RandomAccess

public class Constraint
extends java.util.ArrayList<Term>

A linear pseudo-Boolean Constraint as used in an Integer Linear Program (ILP). A set of Constraints specify a search space.

This Constraint consists of a list of Terms, an Constraint.Operator and a right hand side. E.g., 4a - 3b + not(c) <= 7 is a valid Constraint consisting of three Literals a, b, not(c) with coefficients 4, 3, 1 , the less or equal operator from Constraint.Operator, and the right hand side 7.

This implementation is a plain data structure, i.e., 4a - 3a + c <= 1 is not simplified to a + c <= 1. Moreover, two Constraints are equal if they have an equal Constraint.Operator, right hand side, and equal Terms in the same order.

See Also:
Serialized Form

Nested Class Summary
static class Constraint.Operator
          The Constraint.Operators correspond to the Boolean operators <=,=,>=.
 
Field Summary
protected  Constraint.Operator operator
           
protected  int rhs
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Constraint()
          Constructs a linear Constraint with >=1.
Constraint(Constraint.Operator operator, int rhs)
          Constructs a linear Constraint.
Constraint(java.lang.String operator, int rhs)
          Constructs a linear Constraint.
 
Method Summary
 void add(int coeff, Literal lit)
          Add a Literal with specified coefficient.
 void add(Literal lit)
          Add a Literal with the coefficient 1.
 boolean contains(Literal literal)
          Returns true if the Constraint contains the Literal.
 Constraint copy()
          Copies the Constraint.
 boolean equals(java.lang.Object obj)
           
 java.lang.Iterable<java.lang.Integer> getCoefficients()
          Returns an iterable of the coefficients.
 java.lang.Iterable<Literal> getLiterals()
          Returns an iterable of the Literals.
 Constraint.Operator getOperator()
          Returns the Constraint.Operator.
 int getRhs()
          Return the right hand side value.
 int getViolationCount(Model model)
          Specifies if the Constraint is satisfied for a given Model.
 int hashCode()
           
 boolean isSatisfied(Model model)
          Checks, if this constraint is satisfied for a given model.
 void setOperator(Constraint.Operator operator)
          Sets the Constraint.Operator.
 void setRhs(int rhs)
          Sets the right hand side value.
 java.lang.String toString()
           
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Field Detail

operator

protected Constraint.Operator operator

rhs

protected int rhs
Constructor Detail

Constraint

public Constraint()
Constructs a linear Constraint with >=1.


Constraint

public Constraint(java.lang.String operator,
                  int rhs)
Constructs a linear Constraint.

Parameters:
operator - the operator (<=,=,>=) as a String
rhs - the right-hand-side value

Constraint

public Constraint(Constraint.Operator operator,
                  int rhs)
Constructs a linear Constraint.

Parameters:
operator - the operator
rhs - the right-hand-side value
Method Detail

getCoefficients

public java.lang.Iterable<java.lang.Integer> getCoefficients()
Returns an iterable of the coefficients.

Returns:
the coefficients

getLiterals

public java.lang.Iterable<Literal> getLiterals()
Returns an iterable of the Literals.

Returns:
the literals.

getOperator

public Constraint.Operator getOperator()
Returns the Constraint.Operator.

Returns:
the operator
See Also:
setOperator(org.opt4j.satdecoding.Constraint.Operator)

setOperator

public void setOperator(Constraint.Operator operator)
Sets the Constraint.Operator.

Parameters:
operator - the operator to be set
See Also:
getOperator()

getRhs

public int getRhs()
Return the right hand side value.

Returns:
the right hand side value
See Also:
setRhs(int)

setRhs

public void setRhs(int rhs)
Sets the right hand side value.

Parameters:
rhs - the right hand side value to set
See Also:
getRhs()

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractCollection<Term>

isSatisfied

public boolean isSatisfied(Model model)
Checks, if this constraint is satisfied for a given model.

Parameters:
model - the model
Returns:
true, iff this constraint is satisfied

getViolationCount

public int getViolationCount(Model model)
Specifies if the Constraint is satisfied for a given Model.

Parameters:
model - the model
Returns:
true if this constraint is satisfied for the model

add

public void add(Literal lit)
Add a Literal with the coefficient 1.

Parameters:
lit - the literal

add

public void add(int coeff,
                Literal lit)
Add a Literal with specified coefficient.

Parameters:
coeff - the coefficient
lit - the literal

copy

public Constraint copy()
Copies the Constraint.

Returns:
a copy of the constraint

contains

public boolean contains(Literal literal)
Returns true if the Constraint contains the Literal.

Parameters:
literal - the literal
Returns:
true if the constrain} contains the literal

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Collection<Term>
Specified by:
hashCode in interface java.util.List<Term>
Overrides:
hashCode in class java.util.AbstractList<Term>

equals

public boolean equals(java.lang.Object obj)
Specified by:
equals in interface java.util.Collection<Term>
Specified by:
equals in interface java.util.List<Term>
Overrides:
equals in class java.util.AbstractList<Term>