org.optaplanner.core.impl.score.director
public abstract class AbstractScoreDirector<F extends AbstractScoreDirectorFactory> extends Object implements ScoreDirector, Cloneable
ScoreDirector
.
Implementation note: Extending classes should follow these guidelines:
ScoreDirector
Modifier and Type | Field and Description |
---|---|
protected long |
calculateCount |
protected boolean |
constraintMatchEnabledPreference |
protected org.slf4j.Logger |
logger |
protected F |
scoreDirectorFactory |
protected TrailingEntityMapSupport |
trailingEntityMapSupport |
protected PlanningVariableListenerSupport |
variableListenerSupport |
protected Solution |
workingSolution |
Modifier | Constructor and Description |
---|---|
protected |
AbstractScoreDirector(F scoreDirectorFactory) |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
calculateScore
protected final transient org.slf4j.Logger logger
protected final F extends AbstractScoreDirectorFactory scoreDirectorFactory
protected boolean constraintMatchEnabledPreference
protected TrailingEntityMapSupport trailingEntityMapSupport
protected PlanningVariableListenerSupport variableListenerSupport
protected Solution workingSolution
protected long calculateCount
protected AbstractScoreDirector(F scoreDirectorFactory)
public F getScoreDirectorFactory()
getScoreDirectorFactory
in interface ScoreDirector
public SolutionDescriptor getSolutionDescriptor()
getSolutionDescriptor
in interface ScoreDirector
public ScoreDefinition getScoreDefinition()
getScoreDefinition
in interface ScoreDirector
public Solution getWorkingSolution()
ScoreDirector
Solution
that is used to calculate the Score
.
Because a Score
is best calculated incrementally (by delta's),
the ScoreDirector
needs to be notified when it's workingSolution
changes.
If the Solution
has been changed since ScoreDirector.calculateScore()
has been called,
the Solution.getScore()
of this Solution
won't be correct.getWorkingSolution
in interface ScoreDirector
public long getCalculateCount()
getCalculateCount
in interface ScoreDirector
public void setWorkingSolution(Solution workingSolution)
ScoreDirector
workingSolution
must never be the same instance as the bestSolution
,
it should be a (un)changed clone.setWorkingSolution
in interface ScoreDirector
workingSolution
- never nullpublic Solution cloneWorkingSolution()
cloneWorkingSolution
in interface ScoreDirector
public int getWorkingEntityCount()
getWorkingEntityCount
in interface ScoreDirector
public List<Object> getWorkingEntityList()
getWorkingEntityList
in interface ScoreDirector
public int getWorkingValueCount()
getWorkingValueCount
in interface ScoreDirector
public int countWorkingSolutionUninitializedVariables()
countWorkingSolutionUninitializedVariables
in interface ScoreDirector
public boolean isWorkingSolutionInitialized()
isWorkingSolutionInitialized
in interface ScoreDirector
workingSolution
is initializedprotected void setCalculatedScore(Score score)
public boolean isConstraintMatchEnabled()
isConstraintMatchEnabled
in interface ScoreDirector
ScoreDirector.getConstraintMatchTotals()
can be calledpublic Collection<ConstraintMatchTotal> getConstraintMatchTotals()
getConstraintMatchTotals
in interface ScoreDirector
public AbstractScoreDirector clone()
ScoreDirector
ScoreDirector
and its workingSolution
.
Use ScoreDirector.getWorkingSolution()
to retrieve the workingSolution
of that clone.
This is heavy method, because it usually breaks incremental score calculation. Use it sparingly.
Therefore it's best to clone lazily by delaying the clone call as long as possible.clone
in interface ScoreDirector
clone
in class Object
public void dispose()
ScoreDirector
dispose
in interface ScoreDirector
public Object getTrailingEntity(PlanningVariableDescriptor chainedVariableDescriptor, Object planningValue)
getTrailingEntity
in interface ScoreDirector
chainedVariableDescriptor
- never null, must be PlanningVariableDescriptor.isChained()
true
and known to the SolutionDescriptor
planningValue
- sometimes nullpublic final void beforeEntityAdded(Object entity)
beforeEntityAdded
in interface ScoreDirector
public final void afterEntityAdded(Object entity)
afterEntityAdded
in interface ScoreDirector
public final void beforeVariableChanged(Object entity, String variableName)
beforeVariableChanged
in interface ScoreDirector
public final void afterVariableChanged(Object entity, String variableName)
afterVariableChanged
in interface ScoreDirector
public final void beforeEntityRemoved(Object entity)
beforeEntityRemoved
in interface ScoreDirector
public final void afterEntityRemoved(Object entity)
afterEntityRemoved
in interface ScoreDirector
public void beforeEntityAdded(PlanningEntityDescriptor entityDescriptor, Object entity)
public void afterEntityAdded(PlanningEntityDescriptor entityDescriptor, Object entity)
public void beforeVariableChanged(PlanningVariableDescriptor variableDescriptor, Object entity)
public void afterVariableChanged(PlanningVariableDescriptor variableDescriptor, Object entity)
public void beforeShadowVariableChanged(Object entity, String variableName)
public void afterShadowVariableChanged(Object entity, String variableName)
public void beforeEntityRemoved(PlanningEntityDescriptor entityDescriptor, Object entity)
public void afterEntityRemoved(PlanningEntityDescriptor entityDescriptor, Object entity)
public void beforeProblemFactAdded(Object problemFact)
beforeProblemFactAdded
in interface ScoreDirector
public void afterProblemFactAdded(Object problemFact)
afterProblemFactAdded
in interface ScoreDirector
public void beforeProblemFactChanged(Object problemFact)
beforeProblemFactChanged
in interface ScoreDirector
public void afterProblemFactChanged(Object problemFact)
afterProblemFactChanged
in interface ScoreDirector
public void beforeProblemFactRemoved(Object problemFact)
beforeProblemFactRemoved
in interface ScoreDirector
public void afterProblemFactRemoved(Object problemFact)
afterProblemFactRemoved
in interface ScoreDirector
public void assertExpectedWorkingScore(Score expectedWorkingScore, Object completedAction)
ScoreDirector
Score
is calculated for the current workingSolution
in the current ScoreDirector
(with possibly incremental calculation residue),
it is equal to the parameter expectedWorkingScore
.
Used to assert that skipping ScoreDirector.calculateScore()
(when the score is otherwise determined) is correct,assertExpectedWorkingScore
in interface ScoreDirector
expectedWorkingScore
- never nullcompletedAction
- sometimes null, when assertion fails then the completedAction's Object.toString()
is included in the exception messagepublic void assertWorkingScoreFromScratch(Score workingScore, Object completedAction)
ScoreDirector
Score
is calculated for the current workingSolution
in a fresh ScoreDirector
(with no incremental calculation residue),
it is equal to the parameter workingScore
.
Furthermore, if the assert fails, a score corruption analysis might be included in the exception message.assertWorkingScoreFromScratch
in interface ScoreDirector
workingScore
- never nullcompletedAction
- sometimes null, when assertion fails then the completedAction's Object.toString()
is included* in the exception messageScoreDirectorFactory.assertScoreFromScratch(Solution)
protected String buildScoreCorruptionAnalysis(ScoreDirector uncorruptedScoreDirector)
uncorruptedScoreDirector
- never null@Deprecated protected void appendLegacyConstraintOccurrences(StringBuilder analysis, ScoreDirector corruptedScoreDirector, ScoreDirector uncorruptedScoreDirector)
Copyright © 2006-2013 JBoss by Red Hat. All Rights Reserved.