public class ParallelPortfolio extends Object
A Portfolio helper.
The ParallelPortfolio resolution of a problem is made of four steps:
The resolution process is synchronized. As soon as one model ends (naturally or by hitting a limit)
the other ones are eagerly stopped.
Moreover, when dealing with an optimization problem, cut on the objective variable's value is propagated
to all models on solution.
It is essential to eagerly declare the objective variable(s) with Model.setObjective(boolean, Variable)
.
Note that the similarity of the models declared is not required. However, when dealing with an optimization problem, keep in mind that the cut on the objective variable's value is propagated among all models, so different objectives may lead to wrong results.
Since there is no condition on the similarity of the models, once the resolution ends, the model which finds the (best) solution is internally stored.
Example of use.
ParallelPortfolio pares = new ParallelPortfolio();
int n = 4; // number of models to use
for (int i = 0; i < n; i++) {
pares.addModel(modeller());
}
pares.solve();
IOutputFactory.printSolutions(pares.getBestModel());
This class uses Java 8 streaming feature, and may be not compliant with older versions.
Project: choco.
Constructor and Description 

ParallelPortfolio()
Creates a new ParallelPortfolio
This class stores the models to be executed in parallel in a
ArrayList initially empty. 
ParallelPortfolio(boolean searchAutoConf)
Creates a new ParallelPortfolio
This class stores the models to be executed in parallel in a
ArrayList initially empty. 
Modifier and Type  Method and Description 

void 
addModel(Model model)
Adds a model to the list of models to run in parallel.

Model 
getBestModel()
Returns the first model from the list which, either :
finds a solution when dealing with a satisfaction problem,
or finds (and possibly proves) the best solution when dealing with an optimization problem.

List<Model> 
getModels() 
boolean 
solve()
Run the solve() instruction of every model of the portfolio in parallel.

Stream<Solution> 
streamSolutions()
Attempts to find all solutions of the declared problem.

public ParallelPortfolio(boolean searchAutoConf)
ArrayList
initially empty.searchAutoConf
 changes the search heuristics of the different solvers, except the first one (true by default).
Must be set to false if search heuristics of the different threads are specified manually, so that they are not erasedpublic ParallelPortfolio()
ArrayList
initially empty.
Search heuristics will be changed automatically (except for the first thread that will remain in the same configuration).public void addModel(Model model)
Adds a model to the list of models to run in parallel. The model can either be a fresh one, ready for populating, or a populated one.
Important:
Model.setObjective(boolean, Variable)
.
model
 a model to addpublic boolean solve()
Note that a call to getBestModel()
returns a model which has found the best solution.
true
if and only if at least one new solution has been found.SolverException
 if no model or only model has been added.public Model getBestModel()
public List<Model> getModels()
public Stream<Solution> streamSolutions()
Note that all variables will be recorded
Copyright © 2019. All rights reserved.