public class Solver
extends java.lang.Object
Modifier and Type | Class | Description |
---|---|---|
class |
Solver.OptimizationOptions |
Class used to store and modify info about which optimizations are enabled.
|
static class |
Solver.UnsafeRisException |
Unsafe Ris Exception, thrown when an unsafe RIS operation is performed while
Strict Ris Mode is ON.
|
Constructor | Description |
---|---|
Solver() |
Constructs a new solver.
|
Modifier and Type | Method | Description |
---|---|---|
void |
add(Constraint constraint) |
Adds a constraint conjunction at the end of the store.
|
void |
addChoicePoint(Constraint constraint) |
Opens a choice point for the first atomic constraint in the constraint conjunction
constraint . |
boolean |
check() |
Solves the conjunction of constraints in the current constraint store.
|
boolean |
check(Constraint constraint) |
Solves the passed constraint
constraint in the context of the current
constraint store and returns a boolean result. |
void |
clearStore() |
Removes all constraints from the Constraint Store
|
void |
failure() |
Method used to signal that the constraint resolution mechanism has failed and no solutions could be found.
|
int |
forEachSolution(java.util.function.Consumer<java.lang.Integer> consumer) |
Runs the given runnable for each solution, counts the number of solutions and returns it.
|
Constraint |
getConstraint() |
Returns a constraint conjunction consisting of all the not solved atomic constraints currently in the store.
|
Solver.OptimizationOptions |
getOptimizationOptions() |
Returns the instance of
OptimizationOptions used by the solver. |
static boolean |
getUnsafeRisUsageWarning() |
Tells whether the warning flag is
true or not and does changes its value to false . |
static boolean |
getUseStrictRisMode() |
Tells whether the Strict Ris Mode is ON (
true ) or OFF (false ). |
java.lang.Integer |
maximize(IntLVar intLVar) |
Maximises the given integer logical variable and returns its maximum
(in the context of the current constraint store).
|
java.lang.Integer |
minimize(IntLVar intLVar) |
Minimizes the given integer logical variable and returns its minimum
(in the context of the current constraint store).
|
boolean |
nextSolution() |
This method tries to find a
new solution (if any) each time it is called.
|
static boolean |
peekUnsafeRisUsageWarning() |
Tells whether the warning flag is
true or not but does not change its value. |
LSet |
setof(LObject x) |
Finds all possible values (by calling
x.getValue) for a logical object that satisfy the constraint
in current constraint store of this solver. |
LSet |
setof(LObject x,
Constraint constraint) |
Computes and returns the (logical) set of all values (obtained calling
x.getValue() of x that satisfy constraint
and the constraints in the constraint store. |
static void |
setUseStrictRisMode(boolean value) |
Sets the Strict Ris Mode ON (
true ) or OFF (false ). |
void |
showStore() |
This method prints each constraint that is not solved yet to standard output.
|
void |
showStoreAll() |
This method prints each constraint still in the constraint store (solved or not) to standard output.
|
void |
showStoreInternals() |
Like
showStoreAll() but prints the internal view of the constraint store to standard output. |
int |
size() |
This method returns the number of atomic constraints in the store that are not yet solved.
|
void |
solve() |
Solves (using backtracking) the constraints that are not in solved form.
|
void |
solve(Constraint constraint) |
Adds the given constraint to the constraint store and solves it using solve()
|
boolean |
test() |
Tests whether the constraint in the store is satisfiable but leaves each variable
that occur in the store unchanged.
|
public static void setUseStrictRisMode(boolean value)
true
) or OFF (false
).
Moreover, calling this method resets to false
the value
of the warning flag, even if the call to this method does not actually
modify the value of the flag for the Strict Ris Mode.
If Strict Ris Mode is ON and the exception is thrown the solver is left
in an inconsistent state so it should not be reused, nor should the result of the
operation that caused the throw of the exception be trusted.value
- the new value for the flagpublic static boolean getUseStrictRisMode()
true
) or OFF (false
).
The Strict Ris Mode is ON by default.
If Strict Ris Mode is ON and the exception is thrown the solver is left
in an inconsistent state so it should not be reused, nor should the result of the
operation that caused the throw of the exception be trusted.true
if the Strict Ris Mode is on, false
if the Strict Ris Mode is offpublic static boolean peekUnsafeRisUsageWarning()
true
or not but does not change its value.true
if the warning flag is set to true
, false
otherwise.public static boolean getUnsafeRisUsageWarning()
true
or not and does changes its value to false
.true
if the warning flag is set to true
, false
otherwise.public void add(@NotNull Constraint constraint)
constraint
- The constraint conjunction to be added to the store.public void addChoicePoint(@NotNull Constraint constraint)
constraint
.constraint
- the constraint that is opening the choice point. It must be an atomic constraint (not a conjunction).public void clearStore()
@NotNull public Constraint getConstraint()
public void showStore()
toString
on the returned constraint of the method getConstraint()
.public void showStoreAll()
public void showStoreInternals()
showStoreAll()
but prints the internal view of the constraint store to standard output.
Used for debugging purposes.public int size()
public boolean check()
true
if the conjunction is satisfiable, false
otherwise.public boolean check(@NotNull Constraint constraint)
constraint
in the context of the current
constraint store and returns a boolean result. If constraint
is unsatisfiable,
constraint
is removed from the constraint store.constraint
- the constraint conjunction to solve.true
constraint
is satisfiable in the context of the current store, false
otherwise.public void failure() throws Failure
Failure
- always.public int forEachSolution(@NotNull java.util.function.Consumer<java.lang.Integer> consumer)
consumer
- a consumer that gets the index of the solution and performs an action.public void solve() throws Failure
Fail
exception can be raised if constraints are inconsistent,
this exception is caught inside the method and starts the backtracking
procedure.Failure
- If the constraint in the store is unsatisfiable.public void solve(@NotNull Constraint constraint) throws Failure
constraint
- constraint conjunction to add to the constraint store.Failure
- if the constraint store and constraint
together are unsatisfiable.public boolean test()
true
if the constraint is satisfiable, otherwise it returns false
.@NotNull public java.lang.Integer minimize(@NotNull IntLVar intLVar)
intLVar
- variable to minimize.intLVar
.@NotNull public java.lang.Integer maximize(@NotNull IntLVar intLVar)
intLVar
- variable to minimize.intLVar
.public boolean nextSolution()
check
or solve
.true
if a next solution exists, false
otherwise.solve()
@NotNull public LSet setof(@NotNull LObject x)
x.getValue)
for a logical object that satisfy the constraint
in current constraint store of this solver.x
- The logical object of which we search the values.x.getValue()
.solve()
public LSet setof(@NotNull LObject x, @NotNull Constraint constraint)
x.getValue()
of x
that satisfy constraint
and the constraints in the constraint store.x
- logical variable the values of which are collected.constraint
- constraint that must be satisfied by the values of x
.x
.@NotNull public Solver.OptimizationOptions getOptimizationOptions()
OptimizationOptions
used by the solver.