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 |
---|---|
static class |
Solver.Action
Define the possible actions of SearchLoop
|
IOutputFactory.DefaultDecisionMessage, IOutputFactory.DefaultSolutionMessage
Modifier and Type | Field and Description |
---|---|
protected Solver.Action |
action
The next action to execute in the search loop
|
protected boolean |
canBeRepaired
Set to true when no more reparation can be achieved, ie entire search tree explored.
|
protected boolean |
completeSearch
Indicates if a complementary search strategy should be added (set to true in that case).
|
protected List<Criterion> |
criteria
List of stopping criteria.
|
protected boolean |
defaultSearch
Indicates if the default search loop is in use (set to true in that case).
|
protected DecisionPath |
dpath
The current decision
|
protected PropagationEngine |
engine
The propagation engine to use
|
protected ContradictionException |
exception
Internal unique contradiction exception, used on propagation failures
|
protected IExplanationEngine |
explainer
An explanation engine
|
protected ESat |
feasible
Problem feasbility:
- UNDEFINED if unknown,
- TRUE if satisfiable,
- FALSE if unsatisfiable
|
protected int |
jumpTo
Counter that indicates how many world should be rolled back when backtracking
|
protected Learn |
L
The learning component of this search loop
|
protected Move |
M
The moving component of this search loop
|
protected MeasuresRecorder |
mMeasures
The measure recorder to keep up to date
|
protected Model |
mModel
The declaring model
|
protected IObjectiveManager |
objectivemanager
The objective manager declare
|
protected Propagate |
P
The propagate component of this search loop
|
protected int |
rootWorldIndex
Index of the initial world, before initialization.
|
protected SearchMonitorList |
searchMonitors
List of search monitors attached to this search loop
|
protected int |
searchWorldIndex
Index of the world where the search starts, after initialization.
|
protected boolean |
stop
Set to true to stop the search loop
|
Modifier | Constructor and Description |
---|---|
protected |
Solver(Model aModel)
Create a resolver based for the model aModel.
|
Modifier and Type | Method and Description |
---|---|
void |
addStopCriterion(Criterion... criterion)
Adds a stop criterion, which, when met, stops the search loop.
|
protected void |
closeSearch()
Close the search:
- set satisfaction
- update statistics
|
protected void |
extend()
Search loop extend phase
|
long |
getBackTrackCount() |
Number |
getBestSolutionValue() |
IBoundsManager |
getBoundsManager() |
ContradictionException |
getContradictionException() |
long |
getCurrentDepth() |
long |
getDecisionCount() |
DecisionPath |
getDecisionPath() |
PropagationEngine |
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 boolean |
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.
|
protected void |
propagate(boolean left)
Search loop propagation phase.
|
Solver |
ref() |
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.
|
protected void |
repair()
Search loop repair phase
|
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
|
boolean |
searchLoop()
Executes the search loop
|
void |
setEngine(PropagationEngine 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.
|
protected boolean |
validate()
Search loop validate phase
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setCBJLearning, setDBTLearning, setNoLearning
setDDS, setDFS, setGeometricalRestart, setHBFS, setLDS, setLNS, setLNS, setLubyRestart, setRestartOnSolutions, setRestarts
limitBacktrack, limitFail, limitNode, limitSearch, limitSolution, limitTime, limitTime, setNoGoodRecordingFromRestarts, setNoGoodRecordingFromSolutions
eachSolutionWithMeasure, findAllOptimalSolutions, findAllSolutions, findLexOptimalSolution, findOptimalSolution, findParetoFront, findSolution, streamOptimalSolutions, streamSolutions
toArray, toCSV, toDimacsString, toMultiLineString, toOneLineString
printCSVStatistics, printFeatures, printShortFeatures, printShortStatistics, printStatistics, printVersion, showContradiction, showDashboard, showDashboard, showDecisions, showDecisions, showShortStatistics, showShortStatisticsOnShutdown, showSolutions, showSolutions, showStatistics, showStatisticsDuringResolution
protected Propagate P
protected Learn L
protected Move M
protected Model mModel
protected IObjectiveManager objectivemanager
protected Solver.Action action
protected MeasuresRecorder mMeasures
protected DecisionPath dpath
protected int rootWorldIndex
protected int searchWorldIndex
protected List<Criterion> criteria
protected boolean defaultSearch
protected boolean completeSearch
protected IExplanationEngine explainer
protected SearchMonitorList searchMonitors
protected PropagationEngine engine
protected final ContradictionException exception
protected ESat feasible
protected int jumpTo
protected boolean stop
protected boolean canBeRepaired
protected Solver(Model aModel)
aModel
- the target modelpublic void throwsException(ICause c, Variable v, String s) throws ContradictionException
ContradictionException
public ContradictionException getContradictionException()
public boolean solve()
public boolean searchLoop()
protected boolean initialize()
protected void propagate(boolean left)
propagate()
left
- true if we are branching on the left false otherwiseprotected void extend()
protected void repair()
protected boolean validate()
true
if a solution is foundprotected void closeSearch()
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()
.
rootWorldIndex
searchWorldIndex
to 0action
to initialize()
mMeasures
engine
dpath
to erase out-dated decisions, presumably all of themobjectivemanager
(calling IBoundsManager.resetBestBounds()
removeAllStopCriteria()
feasible
to ESat.UNDEFINED
hardReset()
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 MoveBinaryDFS
P
by PropagateBasic
ILearnFactory.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 PropagationEngine 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)
l
l
- the new learn to applypublic void setMove(Move... m)
m
m
- 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(PropagationEngine 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
- 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 IMeasures
public long getTimestamp()
getTimestamp
in interface IMeasures
public float getTimeCount()
getTimeCount
in interface IMeasures
public long getTimeCountInNanoSeconds()
getTimeCountInNanoSeconds
in interface IMeasures
public long getReadingTimeCountInNanoSeconds()
getReadingTimeCountInNanoSeconds
in interface IMeasures
public float getReadingTimeCount()
getReadingTimeCount
in interface IMeasures
public long getNodeCount()
getNodeCount
in interface IMeasures
public long getBackTrackCount()
getBackTrackCount
in interface IMeasures
public long getFailCount()
getFailCount
in interface IMeasures
public long getRestartCount()
getRestartCount
in interface IMeasures
public long getSolutionCount()
getSolutionCount
in interface IMeasures
public long getDecisionCount()
getDecisionCount
in interface IMeasures
public long getMaxDepth()
getMaxDepth
in interface IMeasures
public long getCurrentDepth()
getCurrentDepth
in interface IMeasures
public boolean hasObjective()
hasObjective
in interface IMeasures
public boolean isObjectiveOptimal()
isObjectiveOptimal
in interface IMeasures
public Number getBestSolutionValue()
getBestSolutionValue
in interface IMeasures
public SearchState getSearchState()
getSearchState
in interface IMeasures
public IBoundsManager getBoundsManager()
getBoundsManager
in interface IMeasures
public void setOut(PrintStream printStream)
IOutputFactory
setOut
in interface IOutputFactory
printStream
- a print streampublic PrintStream getOut()
getOut
in interface IOutputFactory
public void setErr(PrintStream printStream)
IOutputFactory
setErr
in interface IOutputFactory
printStream
- a print streampublic PrintStream getErr()
getErr
in interface IOutputFactory
Copyright © 2018. All rights reserved.