public class Solver<V extends Variable<V,T>,T extends Value<V,T>> extends Object
procedure net.sf.cpsolver.ifs(initial) // initial solution is the parameter
iteration = 0; // iteration counter
current = initial; // current (partial) feasible solution
best = initial; // best solution
while canContinue(current, iteration) do
iteration = iteration + 1;
variable = selectVariable(current);
value = selectValue(current, variable);
UNASSIGN(current, CONFLICTING_VARIABLES(current, variable, value));
ASSIGN(current, variable, value);
if better(current, best) then best = current;
end while
return best;
end procedure
TerminationCondition
),
SolutionComparator
),
NeighbourSelection
) and
DataProperties cfg = ToolBox.loadProperties(inputCfg); //input configuration
Solver solver = new Solver(cfg);
solver.setInitalSolution(model); //sets initial solution
solver.start(); //server is executed in a thread
try { //wait untill the server finishes
solver.getSolverThread().join();
} catch (InterruptedException e) {}
Solution solution = solver.lastSolution(); //last solution
solution.restoreBest(); //restore best solution ever found
Parameter | Type | Comment |
---|---|---|
General.SaveBestUnassigned | Integer |
During the search, solution is saved when it is the best ever found solution and if the number of assigned variables is less or equal this parameter (if set to -1, the solution is always saved) |
General.Seed | Long |
If set, random number generator is initialized with this seed |
General.SaveConfiguration | Boolean |
If true, given configuration is stored into the output folder (during initialization of the solver, ${General.Output}/${General.ProblemName}.properties) |
Solver.AutoConfigure | Boolean |
If true, IFS Solver is configured according to the following parameters |
Termination.Class | String |
Fully qualified class name of the termination condition (see
TerminationCondition , e.g. GeneralTerminationCondition ) |
Comparator.Class | String |
Fully qualified class name of the solution comparator (see
SolutionComparator , e.g. GeneralSolutionComparator ) |
Neighbour.Class | String |
Fully qualified class name of the neighbour selection criterion (see
NeighbourSelection , e.g. StandardNeighbourSelection ) |
PerturbationCounter.Class | String |
Fully qualified class name of the perturbation counter in case of solving
minimal perturbation problem (see PerturbationsCounter , e.g.
DefaultPerturbationsCounter ) |
Extensions.Classes | String |
Semi-colon separated list of fully qualified class names of IFS
extensions (see Extension , e.g. ConflictStatistics or
MacPropagation ) |
SolverListener
,
Model
,
Solution
,
TerminationCondition
,
SolutionComparator
,
PerturbationsCounter
,
VariableSelection
,
ValueSelection
,
Extension
Modifier and Type | Class and Description |
---|---|
protected class |
Solver.SolverThread
Solver thread
|
Modifier and Type | Field and Description |
---|---|
protected Solution<V,T> |
iCurrentSolution
current solution
|
protected Solution<V,T> |
iLastSolution
last solution (after IFS Solver finishes)
|
protected Solver.SolverThread |
iSolverThread
solver thread
|
protected boolean |
iStop
solver is stopped
|
protected static Logger |
sLogger
log
|
static int |
THREAD_PRIORITY |
Constructor and Description |
---|
Solver(DataProperties properties)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addExtension(Extension<V,T> extension)
Add an IFS extension
|
void |
addSolverListener(SolverListener<V,T> listener)
Adds a solver listener
|
protected void |
autoConfigure()
Automatic configuratin of the solver -- when Solver.AutoConfigure is true
|
void |
clearBest()
Clears best solution
|
Solution<V,T> |
currentSolution()
Current solution (during the search)
|
void |
dispose()
Dispose solver
|
List<Extension<V,T>> |
getExtensions()
Returns list of all used extensions
|
NeighbourSelection<V,T> |
getNeighbourSelection()
Returns neighbour selection criterion
|
PerturbationsCounter<V,T> |
getPerturbationsCounter()
Returns perturbation counter (minimal perturbation problem)
|
DataProperties |
getProperties()
Returns configuration
|
SolutionComparator<V,T> |
getSolutionComparator()
Returns solution comparator
|
List<SolverListener<V,T>> |
getSolverListeners()
Registered solver listeners
|
Thread |
getSolverThread()
Returns solver's thread
|
TerminationCondition<V,T> |
getTerminationCondition()
Returns termination condition
|
void |
init()
Initialization
|
void |
initSolver() |
boolean |
isRunning()
True, if the solver is running
|
boolean |
isStop()
Return true if
stopSolver() was called |
Solution<V,T> |
lastSolution()
Last solution (when solver finishes)
|
protected void |
onAssigned(double startTime)
Called in each iteration, after a neighbour is assigned
|
protected void |
onFailure()
Called when the solver fails
|
protected void |
onFinish()
Called when the solver is finished
|
protected void |
onStart()
Called when the solver is started
|
protected void |
onStop()
Called when the solver is stopped
|
void |
removeSolverListener(SolverListener<V,T> listener)
Removes a solver listener
|
void |
setInitalSolution(Model<V,T> model)
Sets initial solution
|
void |
setInitalSolution(Solution<V,T> solution)
Sets initial solution
|
void |
setNeighbourSelection(NeighbourSelection<V,T> neighbourSelection)
Sets neighbour selection criterion
|
void |
setPerturbationsCounter(PerturbationsCounter<V,T> perturbationsCounter)
Sets perturbation counter (minimal perturbation problem)
|
void |
setSolutionComparator(SolutionComparator<V,T> solutionComparator)
Sets solution comparator
|
void |
setTerminalCondition(TerminationCondition<V,T> terminationCondition)
Sets termination condition
|
void |
setUpdateProgress(boolean updateProgress)
True, when solver should update progress (see
Progress ) |
void |
start()
Starts solver
|
void |
stopSolver()
Stop running solver
|
void |
stopSolver(boolean join)
Stop running solver
|
public static int THREAD_PRIORITY
protected Solution<V extends Variable<V,T>,T extends Value<V,T>> iCurrentSolution
protected Solution<V extends Variable<V,T>,T extends Value<V,T>> iLastSolution
protected boolean iStop
protected Solver.SolverThread iSolverThread
public Solver(DataProperties properties)
properties
- input configurationpublic void dispose()
public void setTerminalCondition(TerminationCondition<V,T> terminationCondition)
public void setSolutionComparator(SolutionComparator<V,T> solutionComparator)
public void setNeighbourSelection(NeighbourSelection<V,T> neighbourSelection)
public void setPerturbationsCounter(PerturbationsCounter<V,T> perturbationsCounter)
public void addExtension(Extension<V,T> extension)
public TerminationCondition<V,T> getTerminationCondition()
public SolutionComparator<V,T> getSolutionComparator()
public NeighbourSelection<V,T> getNeighbourSelection()
public PerturbationsCounter<V,T> getPerturbationsCounter()
public List<Extension<V,T>> getExtensions()
public void addSolverListener(SolverListener<V,T> listener)
public void removeSolverListener(SolverListener<V,T> listener)
public List<SolverListener<V,T>> getSolverListeners()
public DataProperties getProperties()
protected void autoConfigure()
public void clearBest()
public void setInitalSolution(Solution<V,T> solution)
public void setInitalSolution(Model<V,T> model)
public void start()
public Thread getSolverThread()
public void init()
public void setUpdateProgress(boolean updateProgress)
Progress
)public Solution<V,T> lastSolution()
public Solution<V,T> currentSolution()
public void initSolver()
public void stopSolver()
public void stopSolver(boolean join)
public boolean isRunning()
protected void onStop()
protected void onStart()
protected void onFinish()
protected void onFailure()
protected void onAssigned(double startTime)
public boolean isStop()
stopSolver()
was called