- java.lang.Object
-
- org.chocosolver.solver.search.strategy.decision.DecisionMaker
-
- org.chocosolver.solver.search.strategy.decision.DecisionPath
-
- All Implemented Interfaces:
Serializable
public class DecisionPath extends DecisionMaker implements Serializable
To handle set of decisions.Decisions are added to this set of decisions with a call to
pushDecision(Decision)
, Decisions are then applied in a call tobuildNext()
andapply()
, and removed in a call tosynchronize()
. Only one decision can be added at the same level. The last declared will erased the previous ones. Only one decision is applied/removed at a time. First decision is alwaysRootDecision.ROOT
, so,size()
returns at least 1.Project: choco-solver.
- Since:
- 11/03/2016.
- Author:
- Charles Prud'homme
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DecisionPath(IEnvironment environment)
Create a decision path
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
apply()
Apply decision pushed since the last call to this method.void
buildNext()
Prepare the last decision pushed since the last call to this method to be applied.Decision
getDecision(int i)
Return the decision in position i in this decision path, or null if no decision exists at that position.Decision
getLastDecision()
Retrieves, but not removes, the last decision of the decision path.String
lastDecisionToString()
void
pushDecision(Decision decision)
Add a decision at the decision path.int
size()
Return the number of decision in this decision path.void
synchronize()
Synchronizes the decision path after a backtrack.void
synchronize(boolean free)
Synchronizes the decision path after a backtrack.String
toString()
void
transferInto(Collection<Decision> aList, boolean includeRootDecision)
Add all decisions of this decision path into a list of decision-
Methods inherited from class org.chocosolver.solver.search.strategy.decision.DecisionMaker
makeIntDecision, makeRealDecision, makeSetDecision
-
-
-
-
Constructor Detail
-
DecisionPath
public DecisionPath(IEnvironment environment)
Create a decision path- Parameters:
environment
- backtracking environment
-
-
Method Detail
-
buildNext
public void buildNext()
Prepare the last decision pushed since the last call to this method to be applied.
-
apply
public void apply() throws ContradictionException
Apply decision pushed since the last call to this method. This call should always be preceded by a call tobuildNext()
.- Throws:
ContradictionException
- if one decision application fails
-
pushDecision
public void pushDecision(Decision decision)
Add a decision at the decision path.- Parameters:
decision
- the decision to add
-
synchronize
public void synchronize()
Synchronizes the decision path after a backtrack. Removes and frees all decisions with level greater or equal to the current level. Recall that the very first decision,RootDecision.ROOT
, can not be removed from this.
-
synchronize
public void synchronize(boolean free)
Synchronizes the decision path after a backtrack. Removes all decisions with level greater or equal to the current level. Recall that the very first decision,RootDecision.ROOT
, can not be removed from this.- Parameters:
free
- set to true to synchronize and free out-dated decisions
-
getLastDecision
public Decision getLastDecision()
Retrieves, but not removes, the last decision of the decision path. Recall that the very first decision of this decision path isRootDecision.ROOT
.- Returns:
- the last decision of the decision path.
-
size
public int size()
Return the number of decision in this decision path. Recall that this decisions path contains at least one decision:RootDecision.ROOT
.- Returns:
- the size of the decision path
-
getDecision
public Decision getDecision(int i)
Return the decision in position i in this decision path, or null if no decision exists at that position.- Parameters:
i
- index of the decision to return- Returns:
- the decision in position i in this decision path
- Throws:
IndexOutOfBoundsException
- if the index is out of range (index < 0 || index >= size())
-
transferInto
public void transferInto(Collection<Decision> aList, boolean includeRootDecision)
Add all decisions of this decision path into a list of decision- Parameters:
aList
- list to populateincludeRootDecision
- set to true to include the very first fake decision, ROOT, in the list.
-
lastDecisionToString
public String lastDecisionToString()
- Returns:
- a pretty print of the downmost decision(s)
-
-