public class InequalitySolver
extends java.lang.Object
The algorithm in Rehof works for definite inequalities. This class does not enforce this requirement. However, if the inequalities are not definite, this solver may not be able to find the solution even when the set of inequalities is satisfiable. See the above paper for details.
This solver supports finding both the least and greatest solutions (if they exist). It assumes that the CPO passed to the constructor is a lattice, but it does not verify it. If the algorithm finds that the LUB or GLB of some elements does not exist, an Exception is thrown.
Constructor and Description |
---|
InequalitySolver(CPO cpo)
Construct an inequality solver.
|
Modifier and Type | Method and Description |
---|---|
void |
addInequalities(java.util.Iterator inequalities)
Add a group of inequalities to the set of constraints.
|
void |
addInequality(Inequality ineq)
Add an
Inequality to the set of constraints. |
java.util.Iterator |
bottomVariables()
Return an
Iterator of the variables whose current
values are the bottom of the underlying CPO. |
java.lang.String |
description()
Return a description of this solver as a String.
|
boolean |
solveGreatest()
Solve the set of inequalities for the greatest solution.
|
boolean |
solveLeast()
Solve the set of inequalities for the least solution.
|
java.util.Iterator |
topVariables()
Return an
Iterator of the variables whose current
values are the top of the underlying CPO. |
java.util.Iterator |
unsatisfiedInequalities()
Return an
Iterator of Inequalities
that are not satisfied with the current value of variables. |
java.util.Iterator |
variables()
Return an
Iterator of all the variables in the
inequality constraints. |
public InequalitySolver(CPO cpo)
cpo
- The CPO over which the inequalities are defined.public void addInequalities(java.util.Iterator inequalities)
inequalities
- An Iterator
for instances of
Inequality
.public void addInequality(Inequality ineq)
Inequality
to the set of constraints.ineq
- An Inequality
.public java.util.Iterator bottomVariables() throws IllegalActionException
Iterator
of the variables whose current
values are the bottom of the underlying CPO. If none of the
variables have its current value set to the bottom, an empty
Iterator
is returned.InvalidStateException
- If the underlying CPO does not
have a bottom element.IllegalActionException
- If testing any one of the
variables throws an exception.public java.lang.String description()
public boolean solveGreatest() throws IllegalActionException
true
, and the variables are set to the greatest solution.
If the set of inequalities is not satisfiable, this method returns
false
.
If the set of inequalities is not definite, this method cannot
always determine satisfiability. In this case, if the set of
inequalities is satisfiable, this method may or may not return
true
. If this method returns true
,
the variables are set to the greatest solution. If the set of
inequalities is not satisfiable, this method returns
false
.
In any case, if this method returns false
, the
variables are set to the greatest solution for the subset of
inequalities whose lesser terms are a single variable.
See the paper referred in the class document for details.
IllegalActionException
- If testing any one of the
inequalities throws an exception.public boolean solveLeast() throws IllegalActionException
true
, and the variables are set to the least solution.
If the set of inequalities is not satisfiable, this method returns
false
.
If the set of inequalities is not definite, this method cannot
always determine satisfiability. In this case, if the set of
inequalities is satisfiable, this method may or may not return
true
. If this method returns true
,
the variables are set to the least solution. If the set of
inequalities is not satisfiable, this method returns
false
.
In any case, if this method returns false
, the
variables are set to the least solution for the subset of
inequalities whose greater terms are a single variable.
See the paper referred to in the class document for details.
false
otherwise.IllegalActionException
- If testing any one of the
inequalities throws an exception.public java.util.Iterator topVariables() throws IllegalActionException
Iterator
of the variables whose current
values are the top of the underlying CPO. If none of the
variables have the current value set to the top, an empty
Iterator
is returned.InvalidStateException
- If the underlying CPO does not
have a top element.IllegalActionException
- If testing any one of the
variables throws an exception.public java.util.Iterator unsatisfiedInequalities() throws IllegalActionException
Iterator
of Inequalities
that are not satisfied with the current value of variables.
If all the inequalities are satisfied, an empty
Iterator
is returned.IllegalActionException
- If testing any one of the
inequalities throws an exception.public java.util.Iterator variables()
Iterator
of all the variables in the
inequality constraints.