javax.constraints
Interface Constraint
- All Known Implementing Classes:
- AbstractConstraint, ConstraintElementAtOnSets, ConstraintFalse, ConstraintGlobalCardinality, ConstraintMax, ConstraintMin, ConstraintNotAllEqual, ConstraintTable, ConstraintTraceVar, ConstraintTrue
public interface Constraint
The interface Constraint defines a generic interface for all
constraints that could be created and posted within the Problem.
Concrete constraints can be defined in two ways:
- explicitly in the interface Problem such as "allDifferent"
- implicitly inside constrained expressions such as var1.eq(var2).
The interface Problem includes only commonly used and de-facto standardized
global constraints in their most popular forms. This API assumes that there
will be a library of global constraints that implements the interface Constraint
and follows the guidelines of the
Global Constraint Catalog.
|
Method Summary |
Constraint |
and(Constraint c)
Returns an "AND" Constraint. |
VarBool |
asBool()
This method returns a Var variable that is equal 1 if the constraint
is satisfied and equals 0 if it is violated. |
java.lang.Object |
getImpl()
This method should be defined by a concrete solver
implementation. |
java.lang.String |
getName()
Returns the name of this object. |
java.lang.Object |
getObject()
This method may be used to get an attached Business Object for this
object. |
Problem |
getProblem()
Return a problem to which this object belongs |
Constraint |
implies(Constraint c)
Returns a Constraint that states the implication: this => c. |
Constraint |
negation()
Returns a Constraint that is satisfied if and only if this constraint is not satisfied. |
Constraint |
or(Constraint c)
Returns an "OR" Constraint. |
void |
post()
This method is used to post the
constraint. |
void |
post(ConsistencyLevel consistencyLevel)
This method is used to post the constraint. |
void |
setImpl(java.lang.Object impl)
This method defines an Object that represents an actual
implementation of this object inside a concrete solver. |
void |
setName(java.lang.String name)
Sets the name of this object. |
void |
setObject(java.lang.Object obj)
This method may be used to attach a business object to this
object. |
and
Constraint and(Constraint c)
- Returns an "AND" Constraint. The Constraint "AND" is satisfied if both of the
Constraints "this" and "c" are satisfied. The Constraint "AND" is not satisfied
if at least one of the Constraints "this" or "c" is not satisfied.
- Parameters:
c - the Constraint which is part of the new "AND" Constraint
- Returns:
- a Constraint "AND" between the Constraints "this" and "c2".
asBool
VarBool asBool()
- This method returns a Var variable that is equal 1 if the constraint
is satisfied and equals 0 if it is violated.
- Returns:
- Var with a domain [0;1]: a 1 value indicates the constraint is satisfied,
a 0 value indicates the constraint is violated.
getImpl
java.lang.Object getImpl()
- This method should be defined by a concrete solver
implementation. This method returns an Object that represents an actual
implementation of this object inside an underlying solver.
- Returns:
- an Object that represents an actual implementation of this Constrained
Object inside an underlying solver.
getName
java.lang.String getName()
- Returns the name of this object.
- Returns:
- the name of this object.
getObject
java.lang.Object getObject()
- This method may be used to get an attached Business Object for this
object.
- Returns:
- the Business Object attached to this object.
getProblem
Problem getProblem()
- Return a problem to which this object belongs
- Returns:
- a problem to which this object belongs
implies
Constraint implies(Constraint c)
- Returns a Constraint that states the implication: this => c.
In other words, if this constraint is satisfied, then constraint "c"
should also be satisfied.
- Parameters:
c - the Constraint in the implication.
- Returns:
- a Constraint that means this => c (if this then c).
negation
Constraint negation()
- Returns a Constraint that is satisfied if and only if this constraint is not satisfied.
- Returns:
- a Constraint that is satisfied if and only if this constraint is not satisfied.
or
Constraint or(Constraint c)
- Returns an "OR" Constraint. The Constraint "OR" is satisfied if either of the
Constraints "this" and "c" is satisfied. The Constraint "OR" is not satisfied
if both of the Constraints "this" and "c" are not satisfied.
- Parameters:
c - the Constraint which is part of the new "OR" Constraint
- Returns:
- a Constraint "OR" between the Constraints "this" and "c".
post
void post()
- This method is used to post the
constraint. The constraint posting may do two things:
1) initial constraint propagation will be executed;
2) the constraint will be memorized and wait for notification events
when the variables it controls are changed.
The actual posting logic depends on an underlying CP solver.
If the posting was unsuccessful, this method throws a runtime exception.
A user may put constraint posting in a try-catch block to react to
posting failures.
- Throws:
java.lang.RuntimeException - if a failure happened during the posting
post
void post(ConsistencyLevel consistencyLevel)
- This method is used to post the constraint. Additionally to post()
this methods specifies a particular level of consistency that will
be selected by an implementation to control the propagation strength of
this constraint.
- Parameters:
consistencyLevel -
- Throws:
java.lang.RuntimeException - if a failure happened during the posting
setImpl
void setImpl(java.lang.Object impl)
- This method defines an Object that represents an actual
implementation of this object inside a concrete solver.
- Parameters:
impl - the Object that represents an actual implementation of this
object inside a implementation solver.
setName
void setName(java.lang.String name)
- Sets the name of this object.
- Parameters:
name - the name for this object.
setObject
void setObject(java.lang.Object obj)
- This method may be used to attach a business object to this
object.
- Parameters:
obj - the business object being attached.