Class ConstraintStreamScoreDirector<Solution_,Score_ extends Score<Score_>>
- java.lang.Object
-
- org.optaplanner.core.impl.score.director.AbstractScoreDirector<Solution_,Score_,ConstraintStreamScoreDirectorFactory<Solution_,Score_>>
-
- org.optaplanner.core.impl.score.director.stream.ConstraintStreamScoreDirector<Solution_,Score_>
-
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation
- All Implemented Interfaces:
AutoCloseable,Cloneable,ScoreDirector<Solution_>,InnerScoreDirector<Solution_,Score_>
public class ConstraintStreamScoreDirector<Solution_,Score_ extends Score<Score_>> extends AbstractScoreDirector<Solution_,Score_,ConstraintStreamScoreDirectorFactory<Solution_,Score_>>
FP streams 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 Modifier and Type Field Description protected ConstraintSession<Solution_,Score_>session-
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 ConstraintStreamScoreDirector(ConstraintStreamScoreDirectorFactory<Solution_,Score_> scoreDirectorFactory, boolean lookUpEnabled, boolean constraintMatchEnabledPreference)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterEntityAdded(EntityDescriptor<Solution_> entityDescriptor, Object entity)voidafterEntityRemoved(EntityDescriptor<Solution_> entityDescriptor, Object entity)voidafterProblemFactAdded(Object problemFact)voidafterProblemFactRemoved(Object problemFact)voidafterProblemPropertyChanged(Object problemFactOrEntity)voidafterVariableChanged(VariableDescriptor<Solution_> variableDescriptor, Object entity)Score_calculateScore()Calculates theScoreand updates theworking solutionaccordingly.voidclose()Needs to be called after use because some implementations need to clean up their resources.Map<String,ConstraintMatchTotal<Score_>>getConstraintMatchTotalMap()Map<Object,Indictment<Score_>>getIndictmentMap()Explains the impact of each planning entity or problem fact on theScore.ConstraintSession<Solution_,Score_>getSession()booleanisConstraintMatchEnabled()voidsetWorkingSolution(Solution_ workingSolution)Theworking solutionmust never be the same instance as thebest solution, it should be a (un)changed clone.-
Methods inherited from class org.optaplanner.core.impl.score.director.AbstractScoreDirector
afterEntityAdded, afterEntityRemoved, afterVariableChanged, assertExpectedUndoMoveScore, assertExpectedWorkingScore, assertNonNullPlanningIds, assertPredictedScoreFromScratch, assertShadowVariablesAreNotStale, assertWorkingScoreFromScratch, beforeEntityAdded, beforeEntityAdded, beforeEntityRemoved, beforeEntityRemoved, beforeProblemFactAdded, beforeProblemFactRemoved, beforeProblemPropertyChanged, beforeVariableChanged, beforeVariableChanged, buildScoreCorruptionAnalysis, buildShadowVariableAnalysis, changeVariableFacade, clone, cloneSolution, cloneWorkingSolution, createChildThreadScoreDirector, createShadowVariablesViolationMessage, doAndProcessMove, doAndProcessMove, getCalculationCount, getScoreDefinition, getScoreDirectorFactory, getSolutionDescriptor, getSupplyManager, getWorkingEntityCount, getWorkingEntityList, getWorkingEntityListRevision, getWorkingSolution, getWorkingValueCount, isAllChangesWillBeUndoneBeforeStepEnds, isConstraintMatchEnabledPreference, isLookUpEnabled, isWorkingEntityListDirty, lookUpWorkingObject, lookUpWorkingObjectOrReturnNull, overwriteConstraintMatchEnabledPreference, resetCalculationCount, setAllChangesWillBeUndoneBeforeStepEnds, setCalculatedScore, setWorkingEntityListDirty, toString, triggerVariableListeners
-
-
-
-
Field Detail
-
session
protected ConstraintSession<Solution_,Score_ extends Score<Score_>> session
-
-
Constructor Detail
-
ConstraintStreamScoreDirector
public ConstraintStreamScoreDirector(ConstraintStreamScoreDirectorFactory<Solution_,Score_> scoreDirectorFactory, boolean lookUpEnabled, boolean constraintMatchEnabledPreference)
-
-
Method Detail
-
setWorkingSolution
public void setWorkingSolution(Solution_ workingSolution)
Description copied from interface:InnerScoreDirectorTheworking solutionmust never be the same instance as thebest solution, it should be a (un)changed clone.- Specified by:
setWorkingSolutionin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Overrides:
setWorkingSolutionin classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>,ConstraintStreamScoreDirectorFactory<Solution_,Score_ extends Score<Score_>>>- Parameters:
workingSolution- never null
-
calculateScore
public Score_ calculateScore()
Description copied from interface:InnerScoreDirectorCalculates theScoreand updates theworking solutionaccordingly.- Returns:
- never null, the
Scoreof theworking solution
-
isConstraintMatchEnabled
public boolean isConstraintMatchEnabled()
- Returns:
- true if
InnerScoreDirector.getConstraintMatchTotalMap()andInnerScoreDirector.getIndictmentMap()can be called
-
getConstraintMatchTotalMap
public Map<String,ConstraintMatchTotal<Score_>> getConstraintMatchTotalMap()
Description copied from interface:InnerScoreDirectorExplains theScoreofInnerScoreDirector.calculateScore()by splitting it up perConstraint.The sum of
ConstraintMatchTotal.getScore()equalsInnerScoreDirector.calculateScore().Call
InnerScoreDirector.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:
InnerScoreDirector.getIndictmentMap()
-
getIndictmentMap
public Map<Object,Indictment<Score_>> getIndictmentMap()
Description copied from interface:InnerScoreDirectorExplains 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 fromInnerScoreDirector.calculateScore()because eachConstraintMatch.getScore()is counted for each justification inConstraintMatch.getJustificationList().Call
InnerScoreDirector.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:
InnerScoreDirector.getConstraintMatchTotalMap()
-
close
public void close()
Description copied from interface:InnerScoreDirectorNeeds to be called after use because some implementations need to clean up their resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Overrides:
closein classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>,ConstraintStreamScoreDirectorFactory<Solution_,Score_ extends Score<Score_>>>
-
afterEntityAdded
public void afterEntityAdded(EntityDescriptor<Solution_> entityDescriptor, Object entity)
- Overrides:
afterEntityAddedin classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>,ConstraintStreamScoreDirectorFactory<Solution_,Score_ extends Score<Score_>>>
-
afterVariableChanged
public void afterVariableChanged(VariableDescriptor<Solution_> variableDescriptor, Object entity)
- Specified by:
afterVariableChangedin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Overrides:
afterVariableChangedin classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>,ConstraintStreamScoreDirectorFactory<Solution_,Score_ extends Score<Score_>>>
-
afterEntityRemoved
public void afterEntityRemoved(EntityDescriptor<Solution_> entityDescriptor, Object entity)
- Overrides:
afterEntityRemovedin classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>,ConstraintStreamScoreDirectorFactory<Solution_,Score_ extends Score<Score_>>>
-
afterProblemFactAdded
public void afterProblemFactAdded(Object problemFact)
- Specified by:
afterProblemFactAddedin interfaceScoreDirector<Solution_>- Overrides:
afterProblemFactAddedin classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>,ConstraintStreamScoreDirectorFactory<Solution_,Score_ extends Score<Score_>>>
-
afterProblemPropertyChanged
public void afterProblemPropertyChanged(Object problemFactOrEntity)
- Specified by:
afterProblemPropertyChangedin interfaceScoreDirector<Solution_>- Overrides:
afterProblemPropertyChangedin classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>,ConstraintStreamScoreDirectorFactory<Solution_,Score_ extends Score<Score_>>>
-
afterProblemFactRemoved
public void afterProblemFactRemoved(Object problemFact)
- Specified by:
afterProblemFactRemovedin interfaceScoreDirector<Solution_>- Overrides:
afterProblemFactRemovedin classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>,ConstraintStreamScoreDirectorFactory<Solution_,Score_ extends Score<Score_>>>
-
getSession
public ConstraintSession<Solution_,Score_> getSession()
-
-