Modifier and Type | Method and Description |
---|---|
default void |
eachSolutionWithMeasure(BiConsumer<Solution,IMeasures> cons,
Criterion... stop)
|
default List<Solution> |
findAllOptimalSolutions(IntVar objective,
boolean maximize,
Criterion... stop)
Attempt to find the solution that optimizes the mono-objective problem defined by
a unique objective variable and an optimization criteria, then finds and stores all optimal solution.
|
default List<Solution> |
findAllSolutions(Criterion... stop)
Attempts to find all solutions of the declared satisfaction problem.
|
default Solution |
findLexOptimalSolution(IntVar[] objectives,
boolean maximize,
Criterion... stop)
Attempts optimize the value of the objectives variable w.r.t.
|
default Solution |
findOptimalSolution(IntVar objective,
boolean maximize,
Criterion... stop)
Attempt to find the solution that optimizes the mono-objective problem defined by a unique objective variable and
an optimization criteria.
|
default List<Solution> |
findParetoFront(IntVar[] objectives,
boolean maximize,
Criterion... stop)
Attempts optimize the value of the objectives variable w.r.t.
|
default Solution |
findSolution(Criterion... stop)
Attempts to find a solution of the declared satisfaction problem.
|
default Stream<Solution> |
streamOptimalSolutions(IntVar objective,
boolean maximize,
Criterion... stop)
Attempt to find the solution that optimizes the mono-objective problem defined by a unique objective variable and
an optimization criteria, then finds and stores all optimal solution.
|
default Stream<Solution> |
streamSolutions(Criterion... stop)
Attempts to find all solutions of the declared problem.
|
default Solution findSolution(Criterion... stop)
Solution
:
If a solution has been found, since the search process stops on that solution, variables' value can be read, e.g.,
intvar.getValue()
or the solution can be recorded:
Solution s = new Solution(model);
s.record();
Basically, this method runs the following instructions:
if(ref().solve()) {
return new Solution(ref()).record();
}else{
return null;
}
Note that all variables will be recorded
Note that it clears the current objective function, if anystop
- optional criterion to stop the search before finding a solutionSolution
if and only if a solution has been found, null otherwise.default List<Solution> findAllSolutions(Criterion... stop)
This method run the following instructions:
List<Solution> solutions = new ArrayList<>();
while (model.getSolver().solve()){
solutions.add(new Solution(model).record());
}
return solutions;
Note that all variables will be recorded
Note that it clears the current objective function, if anystop
- optional criterion to stop the search before finding all solutionsdefault Stream<Solution> streamSolutions(Criterion... stop)
Basically, this method runs the following instructions:
List<Solution> solutions = new ArrayList<>();
while (model.getSolver().solve()) {
solutions.add(new Solution(model).record());
}
return solutions;
Note that all variables will be recordedstop
- optional criterion to stop the search before finding all/best solutiondefault Solution findOptimalSolution(IntVar objective, boolean maximize, Criterion... stop)
Solution
:Basically, this method runs the following instructions:
model.setObjective(maximize, objective);
Solution s = new Solution(model);
while (model.getSolver().solve()) {
s.record();
}
return model.getSolver().isFeasible() == ESat.TRUE ? s : null;
Note that all variables will be recordedobjective
- integer variable to optimizemaximize
- set to true to solve a maximization problem, set to false to solve a minimization
problem.stop
- optional criterion to stop the search before finding all/best solutionSolution
if at least one solution has been found. The solution is proven to be optimal if no
stop criterion stops the search.default List<Solution> findAllOptimalSolutions(IntVar objective, boolean maximize, Criterion... stop)
ref().findOptimalSolution(objective, maximize, stop);
if (!ref().isStopCriterionMet() &&
model.getSolver().getMeasures().getSolutionCount() > 0) {
int opt = _model.getSolver().getObjectiveManager().getBestSolutionValue().intValue();
model.getSolver().reset();
model.clearObjective();
model.arithm(objective, "=", opt).post();
return findAllSolutions();
} else {
return Collections.emptyList();
}
Note that all variables will be recordedobjective
- the variable to optimizemaximize
- set to true to solve a maximization problem,
set to false to solve a minimization problem.stop
- optional criterion to stop the search before finding all/best solutiondefault Stream<Solution> streamOptimalSolutions(IntVar objective, boolean maximize, Criterion... stop)
Basically, this method runs the following instructions:
ref().findOptimalSolution(objective, maximize);
if (model.getSolver().getMeasures().getSolutionCount() > 0) {
int opt = _model.getSolver().getObjectiveManager().getBestSolutionValue().intValue();
model.getSolver().reset();
model.clearObjective();
model.arithm(objective, "=", opt).post();
return findAllSolutions();
} else {
return Collections.emptyList();
}
Note that all variables will be recordedobjective
- the variable to optimizemaximize
- set to true to solve a maximization problem, set to false to solve a minimization
problem.stop
- optional criterion to stop the search before finding all/best solutiondefault List<Solution> findParetoFront(IntVar[] objectives, boolean maximize, Criterion... stop)
ParetoOptimizer pareto = new ParetoOptimizer(maximize, objectives);
while (ref().solve()) {
pareto.onSolution();
}
return pareto.getParetoFront();
Note that all variables will be recordedobjectives
- the array of variables to optimizemaximize
- set to true to solve a maximization problem, set to false to solve a minimization
problem.stop
- optional criterions to stop the search before finding all/best solutiondefault Solution findLexOptimalSolution(IntVar[] objectives, boolean maximize, Criterion... stop)
objectives
- the list of objectives to find the optimal. A solution o1..on is optimal if lexicographically better than
any other correct solution s1..snmaximize
- to maximize the objective, false to minimize.stop
- stop criterion are added before search and removed after search.default void eachSolutionWithMeasure(BiConsumer<Solution,IMeasures> cons, Criterion... stop)
BiConsumer
for each Solution
with its corresponding IMeasures
.
The Solution
and the IMeasures
provided by the Biconsumer are always the same reference, consider
either extracting values from them or copy them. See IMeasures
and Solution.copySolution()
The consumer and the criterion should not be linked ; instead use ACounter
sub-classes.
cons
- the consumer of solution and measure couplesstop
- optional criterions to stop the search before finding all/best solutionCopyright © 2018. All rights reserved.