Class IncrementalScoreDirector<Solution_>
- java.lang.Object
-
- org.optaplanner.core.impl.score.director.AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>
-
- org.optaplanner.core.impl.score.director.incremental.IncrementalScoreDirector<Solution_>
-
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation
- All Implemented Interfaces:
AutoCloseable,Cloneable,InnerScoreDirector<Solution_>,ScoreDirector<Solution_>
public class IncrementalScoreDirector<Solution_> extends AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>
Incremental java implementation ofScoreDirector, which only recalculates theScoreof the part of theworking solutionthat changed, instead of the going through the entirePlanningSolution. This is incremental calculation, which is fast.- See Also:
ScoreDirector
-
-
Field Summary
-
Fields inherited from class org.optaplanner.core.impl.score.director.AbstractScoreDirector
allChangesWillBeUndoneBeforeStepEnds, calculationCount, constraintMatchEnabledPreference, logger, lookUpEnabled, lookUpManager, scoreDirectorFactory, variableListenerSupport, workingEntityListRevision, workingInitScore, workingSolution
-
-
Constructor Summary
Constructors Constructor Description IncrementalScoreDirector(IncrementalScoreDirectorFactory<Solution_> scoreDirectorFactory, boolean lookUpEnabled, boolean constraintMatchEnabledPreference, IncrementalScoreCalculator<Solution_,?> incrementalScoreCalculator)
-
Method Summary
-
Methods inherited from class org.optaplanner.core.impl.score.director.AbstractScoreDirector
afterEntityAdded, afterEntityRemoved, afterVariableChanged, assertExpectedUndoMoveScore, assertExpectedWorkingScore, assertPredictedScoreFromScratch, assertShadowVariablesAreNotStale, assertWorkingScoreFromScratch, beforeEntityAdded, beforeEntityRemoved, beforeVariableChanged, buildScoreCorruptionAnalysis, buildShadowVariableAnalysis, changeVariableFacade, clone, cloneSolution, cloneWorkingSolution, close, createChildThreadScoreDirector, createShadowVariablesViolationMessage, doAndProcessMove, doAndProcessMove, explainScore, getCalculationCount, getScoreDefinition, getScoreDirectorFactory, getSolutionDescriptor, getSupplyManager, getWorkingEntityCount, getWorkingEntityList, getWorkingEntityListRevision, getWorkingSolution, getWorkingValueCount, isAllChangesWillBeUndoneBeforeStepEnds, isConstraintMatchEnabledPreference, isLookUpEnabled, isWorkingEntityListDirty, lookUpWorkingObject, lookUpWorkingObjectOrReturnNull, overwriteConstraintMatchEnabledPreference, resetCalculationCount, setAllChangesWillBeUndoneBeforeStepEnds, setCalculatedScore, setWorkingEntityListDirty, toString, triggerVariableListeners
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.optaplanner.core.impl.score.director.ScoreDirector
dispose
-
-
-
-
Constructor Detail
-
IncrementalScoreDirector
public IncrementalScoreDirector(IncrementalScoreDirectorFactory<Solution_> scoreDirectorFactory, boolean lookUpEnabled, boolean constraintMatchEnabledPreference, IncrementalScoreCalculator<Solution_,?> incrementalScoreCalculator)
-
-
Method Detail
-
getIncrementalScoreCalculator
public IncrementalScoreCalculator<Solution_,?> getIncrementalScoreCalculator()
-
setWorkingSolution
public void setWorkingSolution(Solution_ workingSolution)
Description copied from interface:ScoreDirectorTheworking solutionmust never be the same instance as thebest solution, it should be a (un)changed clone.Only call this method on a separate
ScoreDirectorinstance, built bySolverFactory.getScoreDirectorFactory(), not on the one used inside theSolveritself.- Specified by:
setWorkingSolutionin interfaceScoreDirector<Solution_>- Overrides:
setWorkingSolutionin classAbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>- Parameters:
workingSolution- never null
-
calculateScore
public Score calculateScore()
Description copied from interface:ScoreDirectorCalculates theScoreand updates theworking solutionaccordingly.- Returns:
- never null, the
Scoreof theworking solution
-
isConstraintMatchEnabled
public boolean isConstraintMatchEnabled()
- Returns:
- true if
ScoreDirector.getConstraintMatchTotals(),ScoreDirector.getConstraintMatchTotalMap()andScoreDirector.getIndictmentMap()can be called
-
getConstraintMatchTotals
public Collection<ConstraintMatchTotal> getConstraintMatchTotals()
Description copied from interface:ScoreDirectorExplains theScoreofScoreDirector.calculateScore()by splitting it up perConstraint.The sum of
ConstraintMatchTotal.getScore()equalsScoreDirector.calculateScore().Call
ScoreDirector.calculateScore()before calling this method, unless that method has already been called since the lastPlanningVariablechanges.- Returns:
- never null
- See Also:
ScoreDirector.getConstraintMatchTotalMap(),ScoreDirector.getIndictmentMap()
-
getConstraintMatchTotalMap
public Map<String,ConstraintMatchTotal> getConstraintMatchTotalMap()
Description copied from interface:ScoreDirectorExplains theScoreofScoreDirector.calculateScore()by splitting it up perConstraint.The sum of
ConstraintMatchTotal.getScore()equalsScoreDirector.calculateScore().Call
ScoreDirector.calculateScore()before calling this method, unless that method has already been called since the lastPlanningVariablechanges.- Returns:
- never null, the key is the
constraintId(to create one, useConstraintMatchTotal.composeConstraintId(String, String)). - See Also:
ScoreDirector.getIndictmentMap()
-
getIndictmentMap
public Map<Object,Indictment> getIndictmentMap()
Description copied from interface:ScoreDirectorExplains the impact of each planning entity or problem fact on theScore. AnIndictmentis basically the inverse of aConstraintMatchTotal: it is aScoretotal for each justificationObjectinConstraintMatch.getJustificationList().The sum of
ConstraintMatchTotal.getScore()differs fromScoreDirector.calculateScore()because eachConstraintMatch.getScore()is counted for each justification inConstraintMatch.getJustificationList().Call
ScoreDirector.calculateScore()before calling this method, unless that method has already been called since the lastPlanningVariablechanges.- Returns:
- never null, the key is a
problem factor aplanning entity - See Also:
ScoreDirector.getConstraintMatchTotalMap()
-
beforeEntityAdded
public void beforeEntityAdded(EntityDescriptor<Solution_> entityDescriptor, Object entity)
- Overrides:
beforeEntityAddedin classAbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>
-
afterEntityAdded
public void afterEntityAdded(EntityDescriptor<Solution_> entityDescriptor, Object entity)
- Overrides:
afterEntityAddedin classAbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>
-
beforeVariableChanged
public void beforeVariableChanged(VariableDescriptor variableDescriptor, Object entity)
- Specified by:
beforeVariableChangedin interfaceScoreDirector<Solution_>- Overrides:
beforeVariableChangedin classAbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>
-
afterVariableChanged
public void afterVariableChanged(VariableDescriptor variableDescriptor, Object entity)
- Specified by:
afterVariableChangedin interfaceScoreDirector<Solution_>- Overrides:
afterVariableChangedin classAbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>
-
beforeEntityRemoved
public void beforeEntityRemoved(EntityDescriptor<Solution_> entityDescriptor, Object entity)
- Overrides:
beforeEntityRemovedin classAbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>
-
afterEntityRemoved
public void afterEntityRemoved(EntityDescriptor<Solution_> entityDescriptor, Object entity)
- Overrides:
afterEntityRemovedin classAbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>
-
beforeProblemFactAdded
public void beforeProblemFactAdded(Object problemFact)
- Specified by:
beforeProblemFactAddedin interfaceScoreDirector<Solution_>- Overrides:
beforeProblemFactAddedin classAbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>
-
afterProblemFactAdded
public void afterProblemFactAdded(Object problemFact)
- Specified by:
afterProblemFactAddedin interfaceScoreDirector<Solution_>- Overrides:
afterProblemFactAddedin classAbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>
-
beforeProblemPropertyChanged
public void beforeProblemPropertyChanged(Object problemFactOrEntity)
- Specified by:
beforeProblemPropertyChangedin interfaceScoreDirector<Solution_>- Overrides:
beforeProblemPropertyChangedin classAbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>
-
afterProblemPropertyChanged
public void afterProblemPropertyChanged(Object problemFactOrEntity)
- Specified by:
afterProblemPropertyChangedin interfaceScoreDirector<Solution_>- Overrides:
afterProblemPropertyChangedin classAbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>
-
beforeProblemFactRemoved
public void beforeProblemFactRemoved(Object problemFact)
- Specified by:
beforeProblemFactRemovedin interfaceScoreDirector<Solution_>- Overrides:
beforeProblemFactRemovedin classAbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>
-
afterProblemFactRemoved
public void afterProblemFactRemoved(Object problemFact)
- Specified by:
afterProblemFactRemovedin interfaceScoreDirector<Solution_>- Overrides:
afterProblemFactRemovedin classAbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>
-
-