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
VariableListener s 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, wait
calculateScore, getConstraintMatchTotals, isConstraintMatchEnabled
protected 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 InnerScoreDirector
public SolutionDescriptor getSolutionDescriptor()
getSolutionDescriptor
in interface InnerScoreDirector
public ScoreDefinition getScoreDefinition()
getScoreDefinition
in interface InnerScoreDirector
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 getWorkingEntityListRevision()
getWorkingEntityListRevision
in interface InnerScoreDirector
InnerScoreDirector.isWorkingEntityListDirty(long)
later onpublic boolean isAllChangesWillBeUndoneBeforeStepEnds()
public void setAllChangesWillBeUndoneBeforeStepEnds(boolean allChangesWillBeUndoneBeforeStepEnds)
InnerScoreDirector
setAllChangesWillBeUndoneBeforeStepEnds
in interface InnerScoreDirector
allChangesWillBeUndoneBeforeStepEnds
- true if all changes will be undonepublic long getCalculateCount()
getCalculateCount
in interface InnerScoreDirector
public void resetCalculateCount()
resetCalculateCount
in interface InnerScoreDirector
public SupplyManager getSupplyManager()
getSupplyManager
in interface InnerScoreDirector
public void setWorkingSolution(Solution workingSolution)
ScoreDirector
workingSolution
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 ScoreDirector
workingSolution
- never nullpublic boolean isWorkingEntityListDirty(long expectedWorkingEntityListRevision)
isWorkingEntityListDirty
in interface InnerScoreDirector
expectedWorkingEntityListRevision
- anprotected void setWorkingEntityListDirty()
public Solution cloneWorkingSolution()
cloneWorkingSolution
in interface InnerScoreDirector
public Solution cloneSolution(Solution originalSolution)
cloneSolution
in interface InnerScoreDirector
originalSolution
- never nullpublic int getWorkingEntityCount()
getWorkingEntityCount
in interface InnerScoreDirector
>= 0
public List<Object> getWorkingEntityList()
getWorkingEntityList
in interface InnerScoreDirector
public int getWorkingValueCount()
getWorkingValueCount
in interface InnerScoreDirector
>= 0
public int countWorkingSolutionUninitializedVariables()
countWorkingSolutionUninitializedVariables
in interface InnerScoreDirector
public void triggerVariableListeners()
triggerVariableListeners
in interface ScoreDirector
protected void setCalculatedScore(Score score)
public AbstractScoreDirector clone()
InnerScoreDirector
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 InnerScoreDirector
clone
in class Object
public void dispose()
ScoreDirector
dispose
in interface ScoreDirector
public 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(EntityDescriptor entityDescriptor, Object entity)
public void afterEntityAdded(EntityDescriptor entityDescriptor, Object entity)
public void beforeVariableChanged(VariableDescriptor variableDescriptor, Object entity)
beforeVariableChanged
in interface ScoreDirector
public void afterVariableChanged(VariableDescriptor variableDescriptor, Object entity)
afterVariableChanged
in interface ScoreDirector
public void changeVariableFacade(VariableDescriptor variableDescriptor, Object entity, Object newValue)
changeVariableFacade
in interface ScoreDirector
public void beforeEntityRemoved(EntityDescriptor entityDescriptor, Object entity)
public void afterEntityRemoved(EntityDescriptor 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)
InnerScoreDirector
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 InnerScoreDirector
expectedWorkingScore
- 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)
InnerScoreDirector
VariableListener
s 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 InnerScoreDirector
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)
InnerScoreDirector
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 InnerScoreDirector
workingScore
- 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.