public abstract class AbstractScoreDirector<Factory_ extends AbstractScoreDirectorFactory> extends Object implements InnerScoreDirector, Cloneable
ScoreDirector.
Implementation note: Extending classes should follow these guidelines:
ScoreDirector| Modifier and Type | Field and Description |
|---|---|
protected boolean |
allChangesWillBeUndoneBeforeStepEnds |
protected long |
calculateCount |
protected boolean |
constraintMatchEnabledPreference |
protected org.slf4j.Logger |
logger |
protected Factory_ |
scoreDirectorFactory |
protected VariableListenerSupport |
variableListenerSupport |
protected long |
workingEntityListRevision |
protected Solution |
workingSolution |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractScoreDirector(Factory_ scoreDirectorFactory,
boolean constraintMatchEnabledPreference) |
| Modifier and Type | Method and Description |
|---|---|
void |
afterEntityAdded(EntityDescriptor entityDescriptor,
Object entity) |
void |
afterEntityAdded(Object entity) |
void |
afterEntityRemoved(EntityDescriptor entityDescriptor,
Object entity) |
void |
afterEntityRemoved(Object entity) |
void |
afterProblemFactAdded(Object problemFact) |
void |
afterProblemFactChanged(Object problemFact) |
void |
afterProblemFactRemoved(Object problemFact) |
void |
afterVariableChanged(Object entity,
String variableName) |
void |
afterVariableChanged(VariableDescriptor variableDescriptor,
Object entity) |
void |
assertExpectedWorkingScore(Score expectedWorkingScore,
Object completedAction)
Asserts that if the
Score is calculated for the current workingSolution
in the current ScoreDirector (with possibly incremental calculation residue),
it is equal to the parameter expectedWorkingScore. |
void |
assertShadowVariablesAreNotStale(Score expectedWorkingScore,
Object completedAction)
Asserts that if all
VariableListeners are forcibly triggered,
and therefore all shadow variables are updated if needed,
that none of the shadow variables of the workingSolution change,
Then also asserts that the Score calculated for the workingSolution afterwards
is equal to the parameter expectedWorkingScore. |
void |
assertWorkingScoreFromScratch(Score workingScore,
Object completedAction)
Asserts that if the
Score is calculated for the current workingSolution
in a fresh ScoreDirector (with no incremental calculation residue),
it is equal to the parameter workingScore. |
void |
beforeEntityAdded(EntityDescriptor entityDescriptor,
Object entity) |
void |
beforeEntityAdded(Object entity) |
void |
beforeEntityRemoved(EntityDescriptor entityDescriptor,
Object entity) |
void |
beforeEntityRemoved(Object entity) |
void |
beforeProblemFactAdded(Object problemFact) |
void |
beforeProblemFactChanged(Object problemFact) |
void |
beforeProblemFactRemoved(Object problemFact) |
void |
beforeVariableChanged(Object entity,
String variableName) |
void |
beforeVariableChanged(VariableDescriptor variableDescriptor,
Object entity) |
protected String |
buildScoreCorruptionAnalysis(ScoreDirector uncorruptedScoreDirector) |
void |
changeVariableFacade(VariableDescriptor variableDescriptor,
Object entity,
Object newValue) |
AbstractScoreDirector |
clone()
Clones this
ScoreDirector and its workingSolution. |
Solution |
cloneSolution(Solution originalSolution) |
Solution |
cloneWorkingSolution() |
int |
countWorkingSolutionUninitializedVariables() |
void |
dispose()
Needs to be called after use because some implementations needs to clean up their resources.
|
long |
getCalculateCount() |
ScoreDefinition |
getScoreDefinition() |
Factory_ |
getScoreDirectorFactory() |
SolutionDescriptor |
getSolutionDescriptor() |
SupplyManager |
getSupplyManager() |
int |
getWorkingEntityCount() |
List<Object> |
getWorkingEntityList() |
long |
getWorkingEntityListRevision() |
Solution |
getWorkingSolution()
|
int |
getWorkingValueCount() |
boolean |
isAllChangesWillBeUndoneBeforeStepEnds() |
boolean |
isWorkingEntityListDirty(long expectedWorkingEntityListRevision) |
void |
resetCalculateCount() |
void |
setAllChangesWillBeUndoneBeforeStepEnds(boolean allChangesWillBeUndoneBeforeStepEnds)
Do not waste performance by propagating changes to step (or higher) mechanisms.
|
protected void |
setCalculatedScore(Score score) |
protected void |
setWorkingEntityListDirty() |
void |
setWorkingSolution(Solution workingSolution)
The
workingSolution must never be the same instance as the bestSolution,
it should be a (un)changed clone. |
String |
toString() |
void |
triggerVariableListeners() |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcalculateScore, getConstraintMatchTotals, isConstraintMatchEnabledprotected final transient org.slf4j.Logger logger
protected final Factory_ extends AbstractScoreDirectorFactory scoreDirectorFactory
protected final boolean constraintMatchEnabledPreference
protected final VariableListenerSupport variableListenerSupport
protected Solution workingSolution
protected long workingEntityListRevision
protected boolean allChangesWillBeUndoneBeforeStepEnds
protected long calculateCount
protected AbstractScoreDirector(Factory_ scoreDirectorFactory, boolean constraintMatchEnabledPreference)
public Factory_ getScoreDirectorFactory()
getScoreDirectorFactory in interface InnerScoreDirectorpublic SolutionDescriptor getSolutionDescriptor()
getSolutionDescriptor in interface InnerScoreDirectorpublic ScoreDefinition getScoreDefinition()
getScoreDefinition in interface InnerScoreDirectorpublic Solution getWorkingSolution()
ScoreDirectorSolution 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 ScoreDirectorpublic long getWorkingEntityListRevision()
getWorkingEntityListRevision in interface InnerScoreDirectorInnerScoreDirector.isWorkingEntityListDirty(long) later onpublic boolean isAllChangesWillBeUndoneBeforeStepEnds()
public void setAllChangesWillBeUndoneBeforeStepEnds(boolean allChangesWillBeUndoneBeforeStepEnds)
InnerScoreDirectorsetAllChangesWillBeUndoneBeforeStepEnds in interface InnerScoreDirectorallChangesWillBeUndoneBeforeStepEnds - true if all changes will be undonepublic long getCalculateCount()
getCalculateCount in interface InnerScoreDirectorpublic void resetCalculateCount()
resetCalculateCount in interface InnerScoreDirectorpublic SupplyManager getSupplyManager()
getSupplyManager in interface InnerScoreDirectorpublic void setWorkingSolution(Solution workingSolution)
ScoreDirectorworkingSolution must never be the same instance as the bestSolution,
it should be a (un)changed clone.
Only call this method on a separate ScoreDirector instance,
build by Solver.getScoreDirectorFactory(),
not on the one used inside the Solver itself.
setWorkingSolution in interface ScoreDirectorworkingSolution - never nullpublic boolean isWorkingEntityListDirty(long expectedWorkingEntityListRevision)
isWorkingEntityListDirty in interface InnerScoreDirectorexpectedWorkingEntityListRevision - anprotected void setWorkingEntityListDirty()
public Solution cloneWorkingSolution()
cloneWorkingSolution in interface InnerScoreDirectorpublic Solution cloneSolution(Solution originalSolution)
cloneSolution in interface InnerScoreDirectororiginalSolution - never nullpublic int getWorkingEntityCount()
getWorkingEntityCount in interface InnerScoreDirector>= 0public List<Object> getWorkingEntityList()
getWorkingEntityList in interface InnerScoreDirectorpublic int getWorkingValueCount()
getWorkingValueCount in interface InnerScoreDirector>= 0public int countWorkingSolutionUninitializedVariables()
countWorkingSolutionUninitializedVariables in interface InnerScoreDirectorpublic void triggerVariableListeners()
triggerVariableListeners in interface ScoreDirectorprotected void setCalculatedScore(Score score)
public AbstractScoreDirector clone()
InnerScoreDirectorScoreDirector 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 InnerScoreDirectorclone in class Objectpublic void dispose()
ScoreDirectordispose in interface ScoreDirectorpublic final void beforeEntityAdded(Object entity)
beforeEntityAdded in interface ScoreDirectorpublic final void afterEntityAdded(Object entity)
afterEntityAdded in interface ScoreDirectorpublic final void beforeVariableChanged(Object entity, String variableName)
beforeVariableChanged in interface ScoreDirectorpublic final void afterVariableChanged(Object entity, String variableName)
afterVariableChanged in interface ScoreDirectorpublic final void beforeEntityRemoved(Object entity)
beforeEntityRemoved in interface ScoreDirectorpublic final void afterEntityRemoved(Object entity)
afterEntityRemoved in interface ScoreDirectorpublic void beforeEntityAdded(EntityDescriptor entityDescriptor, Object entity)
public void afterEntityAdded(EntityDescriptor entityDescriptor, Object entity)
public void beforeVariableChanged(VariableDescriptor variableDescriptor, Object entity)
beforeVariableChanged in interface ScoreDirectorpublic void afterVariableChanged(VariableDescriptor variableDescriptor, Object entity)
afterVariableChanged in interface ScoreDirectorpublic void changeVariableFacade(VariableDescriptor variableDescriptor, Object entity, Object newValue)
changeVariableFacade in interface ScoreDirectorpublic void beforeEntityRemoved(EntityDescriptor entityDescriptor, Object entity)
public void afterEntityRemoved(EntityDescriptor entityDescriptor, Object entity)
public void beforeProblemFactAdded(Object problemFact)
beforeProblemFactAdded in interface ScoreDirectorpublic void afterProblemFactAdded(Object problemFact)
afterProblemFactAdded in interface ScoreDirectorpublic void beforeProblemFactChanged(Object problemFact)
beforeProblemFactChanged in interface ScoreDirectorpublic void afterProblemFactChanged(Object problemFact)
afterProblemFactChanged in interface ScoreDirectorpublic void beforeProblemFactRemoved(Object problemFact)
beforeProblemFactRemoved in interface ScoreDirectorpublic void afterProblemFactRemoved(Object problemFact)
afterProblemFactRemoved in interface ScoreDirectorpublic void assertExpectedWorkingScore(Score expectedWorkingScore, Object completedAction)
InnerScoreDirectorScore 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 InnerScoreDirectorexpectedWorkingScore - never nullcompletedAction - sometimes null, when assertion fails then the completedAction's Object.toString()
is included in the exception messagepublic void assertShadowVariablesAreNotStale(Score expectedWorkingScore, Object completedAction)
InnerScoreDirectorVariableListeners are forcibly triggered,
and therefore all shadow variables are updated if needed,
that none of the shadow variables of the workingSolution change,
Then also asserts that the Score calculated for the workingSolution afterwards
is equal to the parameter expectedWorkingScore.
Used to assert that the shadow variables' state is consistent with the genuine variables' state.
assertShadowVariablesAreNotStale in interface InnerScoreDirectorexpectedWorkingScore - 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)
InnerScoreDirectorScore 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 InnerScoreDirectorworkingScore - never nullcompletedAction - sometimes null, when assertion fails then the completedAction's Object.toString()
is included in the exception messageInnerScoreDirectorFactory.assertScoreFromScratch(Solution)protected String buildScoreCorruptionAnalysis(ScoreDirector uncorruptedScoreDirector)
uncorruptedScoreDirector - never nullCopyright © 2006–2016 JBoss by Red Hat. All rights reserved.