Class ParallelPortfolio
 java.lang.Object

 org.chocosolver.solver.ParallelPortfolio

public class ParallelPortfolio extends Object
A Portfolio helper.
The ParallelPortfolio resolution of a problem is made of four steps:
 adding models to be run in parallel,
 running resolution in parallel,
 getting the model which finds a solution (or the best one), if any.
Note also that there should not be pending resolution process in any models. Otherwise, unexpected behaviors may occur.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.
 Since:
 23/12/2015.
 Author:
 Charles Prud'homme, JeanGuillaume Fages


Constructor Summary
Constructors Constructor Description ParallelPortfolio()
Creates a new ParallelPortfolio This class stores the models to be executed in parallel in aArrayList
initially empty.ParallelPortfolio(boolean searchAutoConf)
Creates a new ParallelPortfolio This class stores the models to be executed in parallel in aArrayList
initially empty.

Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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()
void
prepare()
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.



Constructor Detail

ParallelPortfolio
public ParallelPortfolio(boolean searchAutoConf)
Creates a new ParallelPortfolio This class stores the models to be executed in parallel in aArrayList
initially empty. Parameters:
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 erased

ParallelPortfolio
public ParallelPortfolio()
Creates a new ParallelPortfolio This class stores the models to be executed in parallel in aArrayList
initially empty. Search heuristics will be changed automatically (except for the first thread that will remain in the same configuration).


Method Detail

addModel
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:
 the populating process is not managed by this ParallelPortfolio and should be done externally, with a dedicated method for example.

when dealing with optimization problems, the objective variables HAVE to be declared eagerly with
Model.setObjective(boolean, Variable)
.
 Parameters:
model
 a model to add

solve
public boolean solve()
Run the solve() instruction of every model of the portfolio in parallel.Note that a call to
getBestModel()
returns a model which has found the best solution. Returns:
true
if and only if at least one new solution has been found. Throws:
SolverException
 if no model or only model has been added.

getBestModel
public 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.
 Returns:
 the first model which finds a solution (or the best one) or null if no such model exists.

getModels
public List<Model> getModels()
 Returns:
 the (mutable!) list of models used in this ParallelPortfolio

streamSolutions
public Stream<Solution> streamSolutions()
Attempts to find all solutions of the declared problem. If the method returns an empty list:
 either a stop criterion (e.g., a time limit) stops the search before any solution has been found,
 or no solution exists for the problem (i.e., overconstrained).
 if the method returns a list with at least one element in it:
 either the resolution stops eagerly du to a stop criterion before finding all solutions,
 or all solutions have been found.
Note that all variables will be recorded
 Returns:
 a list that contained the found solutions.

prepare
public void prepare()

