public class Solver extends Object implements ISolver, IMeasures, IOutputFactory
It declares a search loop made of three components:
Created by cprudhom on 01/09/15. Project: choco.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
Solver.Action
Define the possible actions of SearchLoop
|
IOutputFactory.DefaultDecisionMessage, IOutputFactory.DefaultSolutionMessage| Modifier | Constructor and Description |
|---|---|
protected |
Solver(Model aModel)
Create a resolver based for the model aModel.
|
| Modifier and Type | Method and Description |
|---|---|
Solver |
_me() |
void |
addStopCriterion(Criterion... criterion)
Adds a stop criterion, which, when met, stops the search loop.
|
long |
getBackTrackCount() |
Number |
getBestSolutionValue() |
IBoundsManager |
getBoundsManager() |
ContradictionException |
getContradictionException() |
long |
getCurrentDepth() |
long |
getDecisionCount() |
DecisionPath |
getDecisionPath() |
IPropagationEngine |
getEngine() |
IEnvironment |
getEnvironment() |
PrintStream |
getErr() |
IExplanationEngine |
getExplainer()
Return the explanation engine plugged into
this. |
long |
getFailCount() |
int |
getJumpTo() |
Learn |
getLearner() |
long |
getMaxDepth() |
MeasuresRecorder |
getMeasures()
Returns a reference to the measures recorder.
|
Model |
getModel() |
String |
getModelName() |
Move |
getMove() |
long |
getNodeCount() |
<V extends Variable> |
getObjectiveManager() |
PrintStream |
getOut() |
Propagate |
getPropagate() |
float |
getReadingTimeCount() |
long |
getReadingTimeCountInNanoSeconds() |
long |
getRestartCount() |
<V extends Variable> |
getSearch() |
SearchMonitorList |
getSearchMonitors() |
SearchState |
getSearchState() |
int |
getSearchWorldIndex() |
long |
getSolutionCount() |
float |
getTimeCount() |
long |
getTimeCountInNanoSeconds() |
long |
getTimestamp() |
void |
hardReset()
Resetting a solver to its creation state.
|
boolean |
hasEndedUnexpectedly() |
boolean |
hasObjective() |
protected void |
initialize()
Preparation of the search:
- start time recording,
- store root world
- push a back up world,
- run the initial propagation,
- initialize the Move and the search strategy
|
boolean |
isDefaultSearchUsed()
Indicates if the default search strategy is used
|
ESat |
isFeasible()
Returns information on the feasibility of the current problem defined by the solver.
|
boolean |
isObjectiveOptimal() |
ESat |
isSatisfied()
Return the current state of the CSP.
|
boolean |
isSearchCompleted()
Indicates if the search strategy is completed with one over all variables
|
boolean |
isStopCriterionMet() |
void |
makeCompleteStrategy(boolean isComplete)
Completes (or not) the declared search strategy with one over all variables
|
void |
plugMonitor(ISearchMonitor sm)
Put a search monitor to react on search events (solutions, decisions, fails, ...).
|
void |
propagate()
Propagates constraints and related events through the constraint network until a fix point is find,
or a contradiction is detected.
|
void |
removeAllStopCriteria()
Empties the list of stop criteria declared.
|
void |
removeStopCriterion(Criterion... criterion)
Removes one or many stop criterion from the one to declare to the search loop.
|
void |
reset()
Resetting a solver to the state just before running the last resolution instruction.
|
void |
restart()
Sets the following action in the search to be a restart instruction.
|
void |
restoreRootNode()
Retrieves the state of the root node (after the initial propagation)
Has an immediate effect
|
void |
setEngine(IPropagationEngine propagationEngine)
Attaches a propagation engine
this. |
void |
setErr(PrintStream printStream)
Set the current error stream (default is System.err)
|
void |
setExplainer(IExplanationEngine explainer)
Overrides the explanation engine.
|
void |
setJumpTo(int jto)
Sets how many worlds to rollback when backtracking
|
void |
setLearner(Learn l)
Replaces the current learn with
l |
void |
setMove(Move... m)
Replaces the current move with
m |
void |
setObjectiveManager(IObjectiveManager om)
Declares an objective manager to use.
|
void |
setOut(PrintStream printStream)
Set the current output stream (default is System.out)
|
void |
setPropagate(Propagate p)
Overrides the Propagate object
|
void |
setSearch(AbstractStrategy... strategies)
Override the default search strategies to use in
this. |
boolean |
solve()
Executes the resolver as it is configured.
|
void |
throwsException(ICause c,
Variable v,
String s) |
void |
unplugAllSearchMonitors()
Empties the list of search monitors.
|
void |
unplugMonitor(ISearchMonitor sm)
Removes a search monitors from the ones to plug when the search will start.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsetCBJLearning, setDBTLearning, setNoLearningsetDDS, setDFS, setGeometricalRestart, setHBFS, setLDS, setLNS, setLNS, setLubyRestart, setRestartOnSolutions, setRestartslimitBacktrack, limitFail, limitNode, limitSearch, limitSolution, limitTime, limitTime, setNoGoodRecordingFromRestarts, setNoGoodRecordingFromSolutionseachSolutionWithMeasure, findAllOptimalSolutions, findAllSolutions, findLexOptimalSolution, findOptimalSolution, findParetoFront, findSolution, streamOptimalSolutions, streamSolutionstoArray, toCSV, toDimacsString, toMultiLineString, toOneLineStringprintCSVStatistics, printFeatures, printShortFeatures, printShortStatistics, printStatistics, printVersion, showContradiction, showDecisions, showDecisions, showShortStatistics, showSolutions, showSolutions, showStatistics, showStatisticsDuringResolutionprotected Solver(Model aModel)
aModel - the target modelpublic void throwsException(ICause c, Variable v, String s) throws ContradictionException
ContradictionExceptionpublic ContradictionException getContradictionException()
public boolean solve()
protected void initialize()
public void reset()
Resetting a solver to the state just before running the last resolution instruction.
That is, Propagate, Learn, Move and Search are kept as declared.
ISearchMonitor are also kept plugged to the search loop.
For hard reset, see hardReset().
rootWorldIndexsearchWorldIndex to 0action to initialize()mMeasuresenginedpath to erase out-dated decisions, presumably all of themobjectivemanager (calling IBoundsManager.resetBestBounds()removeAllStopCriteria()feasible to ESat.UNDEFINEDhardReset()public void hardReset()
Resetting a solver to its creation state.
For soft reset, see reset().
In details, calling this method will, first call reset() and then:
M by MoveBinaryDFSP by PropagateBasicILearnFactory.setNoLearning()searchMonitors, that forget any declared oneModel.removeMinisat()Model.removeNogoodStore()reset()public void propagate()
throws ContradictionException
ContradictionException - inconsistency is detected, the problem has no solution with the current set of domains and constraints.public void restart()
public void restoreRootNode()
public Model getModel()
public Learn getLearner()
public Move getMove()
public Propagate getPropagate()
public IEnvironment getEnvironment()
public DecisionPath getDecisionPath()
public <V extends Variable> AbstractStrategy<V> getSearch()
V - kind of variables the search strategy deals withpublic <V extends Variable> IObjectiveManager<V> getObjectiveManager()
V - type of the objective variablepublic boolean isDefaultSearchUsed()
public boolean isSearchCompleted()
public boolean hasEndedUnexpectedly()
public boolean isStopCriterionMet()
public int getSearchWorldIndex()
public MeasuresRecorder getMeasures()
public IExplanationEngine getExplainer()
this.public IPropagationEngine getEngine()
this.public ESat isFeasible()
Possible back values are:
- ESat.TRUE: a solution has been found,
- ESat.FALSE: the CSP has been proven to have no solution,
- ESat.UNDEFINED: no solution has been found so far (within given limits)
without proving the unfeasibility, though.
ESat.public ESat isSatisfied()
Given the current domains, it can return a value among:
- ESat.TRUE: all constraints of the CSP are satisfied for sure,
- ESat.FALSE: at least one constraint of the CSP is not satisfied.
- ESat.UNDEFINED: neither satisfiability nor unsatisfiability could be proven so far.
Presumably, not all variables are instantiated.
public int getJumpTo()
public void setLearner(Learn l)
ll - the new learn to applypublic void setMove(Move... m)
mm - the new move to applypublic void setPropagate(Propagate p)
p - the new Propagate to usepublic void setObjectiveManager(IObjectiveManager om)
om - the objective manager to use instead of the declared one (if any).public void setSearch(AbstractStrategy... strategies)
this.
In case many strategies are given, they will be called in sequence:
The first strategy in parameter is first called to compute a decision, if possible.
If it cannot provide a new decision, the second strategy is called ...
and so on, until the last strategy.
strategies - the search strategies to use.public void setExplainer(IExplanationEngine explainer)
explainer - the explanation to usepublic void setEngine(IPropagationEngine propagationEngine)
this.
It overrides the previously defined one, only
if no propagation was done yet.
Indeed, some incremental propagators may have set up their internal structure,
which cannot be set up twice safely.
If propagation was done calling solve(),
calling reset() enables to set the propagation engine anew.
If propagation was done "manually" (calling propagate(), then nothing can be done.propagationEngine - a propagation strategySolverException - if the current propagation is not NoPropagationEngine.SINGLETON
and is already initialized.public void makeCompleteStrategy(boolean isComplete)
isComplete - set to true to complete the current search strategypublic void addStopCriterion(Criterion... criterion)
SMF.limitTime(solver, "20s");
With lambda, stop when 10 nodes are visited:
() -> solver.getNodeCount() >= 10
criterion - one or many stop criterion to add.removeStopCriterion(Criterion...),
removeAllStopCriteria()public void removeStopCriterion(Criterion... criterion)
criterion - criterion to removepublic void removeAllStopCriteria()
reset().public SearchMonitorList getSearchMonitors()
public void plugMonitor(ISearchMonitor sm)
sm - a search monitor to be plugged in the solverpublic void unplugMonitor(ISearchMonitor sm)
sm - a search monitor to be unplugged in the solverpublic void unplugAllSearchMonitors()
public void setJumpTo(int jto)
jto - how many worlds to rollback when backtrackingpublic String getModelName()
getModelName in interface IMeasurespublic long getTimestamp()
getTimestamp in interface IMeasurespublic float getTimeCount()
getTimeCount in interface IMeasurespublic long getTimeCountInNanoSeconds()
getTimeCountInNanoSeconds in interface IMeasurespublic long getReadingTimeCountInNanoSeconds()
getReadingTimeCountInNanoSeconds in interface IMeasurespublic float getReadingTimeCount()
getReadingTimeCount in interface IMeasurespublic long getNodeCount()
getNodeCount in interface IMeasurespublic long getBackTrackCount()
getBackTrackCount in interface IMeasurespublic long getFailCount()
getFailCount in interface IMeasurespublic long getRestartCount()
getRestartCount in interface IMeasurespublic long getSolutionCount()
getSolutionCount in interface IMeasurespublic long getDecisionCount()
getDecisionCount in interface IMeasurespublic long getMaxDepth()
getMaxDepth in interface IMeasurespublic long getCurrentDepth()
getCurrentDepth in interface IMeasurespublic boolean hasObjective()
hasObjective in interface IMeasurespublic boolean isObjectiveOptimal()
isObjectiveOptimal in interface IMeasurespublic Number getBestSolutionValue()
getBestSolutionValue in interface IMeasurespublic SearchState getSearchState()
getSearchState in interface IMeasurespublic IBoundsManager getBoundsManager()
getBoundsManager in interface IMeasurespublic void setOut(PrintStream printStream)
IOutputFactorysetOut in interface IOutputFactoryprintStream - a print streampublic PrintStream getOut()
getOut in interface IOutputFactorypublic void setErr(PrintStream printStream)
IOutputFactorysetErr in interface IOutputFactoryprintStream - a print streampublic PrintStream getErr()
getErr in interface IOutputFactoryCopyright © 2017. All rights reserved.