Class DroolsConstraintStreamScoreDirector<Solution_,Score_ extends Score<Score_>>
- java.lang.Object
-
- org.optaplanner.core.impl.score.director.AbstractScoreDirector<Solution_,Score_,DroolsConstraintStreamScoreDirectorFactory<Solution_,Score_>>
-
- org.optaplanner.core.impl.score.director.stream.DroolsConstraintStreamScoreDirector<Solution_,Score_>
-
- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotation
- All Implemented Interfaces:
AutoCloseable
,Cloneable
,ScoreDirector<Solution_>
,InnerScoreDirector<Solution_,Score_>
public final class DroolsConstraintStreamScoreDirector<Solution_,Score_ extends Score<Score_>> extends AbstractScoreDirector<Solution_,Score_,DroolsConstraintStreamScoreDirectorFactory<Solution_,Score_>>
FP streams implementation ofScoreDirector
, which only recalculates theScore
of the part of theworking solution
that 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 DroolsConstraintStreamScoreDirector(DroolsConstraintStreamScoreDirectorFactory<Solution_,Score_> scoreDirectorFactory, boolean lookUpEnabled, boolean constraintMatchEnabledPreference)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterEntityAdded(EntityDescriptor<Solution_> entityDescriptor, Object entity)
void
afterEntityRemoved(EntityDescriptor<Solution_> entityDescriptor, Object entity)
void
afterProblemFactAdded(Object problemFact)
void
afterProblemFactRemoved(Object problemFact)
void
afterProblemPropertyChanged(Object problemFactOrEntity)
void
afterVariableChanged(VariableDescriptor<Solution_> variableDescriptor, Object entity)
Score_
calculateScore()
Calculates theScore
and updates theworking solution
accordingly.void
close()
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
.boolean
isConstraintMatchEnabled()
boolean
requiresFlushing()
Some score directors (such as the Drools-based) keep a set of changes that they only apply whenInnerScoreDirector.calculateScore()
is called.void
setWorkingSolution(Solution_ workingSolution)
Theworking solution
must 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, getWorkingEntityListRevision, getWorkingSolution, isAllChangesWillBeUndoneBeforeStepEnds, isConstraintConfiguration, isConstraintMatchEnabledPreference, isLookUpEnabled, isWorkingEntityListDirty, lookUpWorkingObject, lookUpWorkingObjectOrReturnNull, overwriteConstraintMatchEnabledPreference, resetCalculationCount, setAllChangesWillBeUndoneBeforeStepEnds, setCalculatedScore, setWorkingEntityListDirty, toString, triggerVariableListeners
-
-
-
-
Constructor Detail
-
DroolsConstraintStreamScoreDirector
public DroolsConstraintStreamScoreDirector(DroolsConstraintStreamScoreDirectorFactory<Solution_,Score_> scoreDirectorFactory, boolean lookUpEnabled, boolean constraintMatchEnabledPreference)
-
-
Method Detail
-
setWorkingSolution
public void setWorkingSolution(Solution_ workingSolution)
Description copied from interface:InnerScoreDirector
Theworking solution
must never be the same instance as thebest solution
, it should be a (un)changed clone.- Specified by:
setWorkingSolution
in interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>
- Overrides:
setWorkingSolution
in classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>,DroolsConstraintStreamScoreDirectorFactory<Solution_,Score_ extends Score<Score_>>>
- Parameters:
workingSolution
- never null
-
calculateScore
public Score_ calculateScore()
Description copied from interface:InnerScoreDirector
Calculates theScore
and updates theworking solution
accordingly.- Returns:
- never null, the
Score
of 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:InnerScoreDirector
Explains theScore
ofInnerScoreDirector.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 lastPlanningVariable
changes.- 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:InnerScoreDirector
Explains the impact of each planning entity or problem fact on theScore
. AnIndictment
is basically the inverse of aConstraintMatchTotal
: it is aScore
total for each justificationObject
inConstraintMatch.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 lastPlanningVariable
changes.- Returns:
- never null, the key is a
problem fact
or aplanning entity
- See Also:
InnerScoreDirector.getConstraintMatchTotalMap()
-
requiresFlushing
public boolean requiresFlushing()
Description copied from interface:InnerScoreDirector
Some score directors (such as the Drools-based) keep a set of changes that they only apply whenInnerScoreDirector.calculateScore()
is called. Until that happens, this set accumulates and could possibly act as a memory leak.- Returns:
- true if the score director can potentially cause a memory leak due to unflushed changes.
-
close
public void close()
Description copied from interface:InnerScoreDirector
Needs to be called after use because some implementations need to clean up their resources.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>
- Overrides:
close
in classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>,DroolsConstraintStreamScoreDirectorFactory<Solution_,Score_ extends Score<Score_>>>
-
afterEntityAdded
public void afterEntityAdded(EntityDescriptor<Solution_> entityDescriptor, Object entity)
- Overrides:
afterEntityAdded
in classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>,DroolsConstraintStreamScoreDirectorFactory<Solution_,Score_ extends Score<Score_>>>
-
afterVariableChanged
public void afterVariableChanged(VariableDescriptor<Solution_> variableDescriptor, Object entity)
- Specified by:
afterVariableChanged
in interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>
- Overrides:
afterVariableChanged
in classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>,DroolsConstraintStreamScoreDirectorFactory<Solution_,Score_ extends Score<Score_>>>
-
afterEntityRemoved
public void afterEntityRemoved(EntityDescriptor<Solution_> entityDescriptor, Object entity)
- Overrides:
afterEntityRemoved
in classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>,DroolsConstraintStreamScoreDirectorFactory<Solution_,Score_ extends Score<Score_>>>
-
afterProblemFactAdded
public void afterProblemFactAdded(Object problemFact)
- Specified by:
afterProblemFactAdded
in interfaceScoreDirector<Solution_>
- Overrides:
afterProblemFactAdded
in classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>,DroolsConstraintStreamScoreDirectorFactory<Solution_,Score_ extends Score<Score_>>>
-
afterProblemPropertyChanged
public void afterProblemPropertyChanged(Object problemFactOrEntity)
- Specified by:
afterProblemPropertyChanged
in interfaceScoreDirector<Solution_>
- Overrides:
afterProblemPropertyChanged
in classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>,DroolsConstraintStreamScoreDirectorFactory<Solution_,Score_ extends Score<Score_>>>
-
afterProblemFactRemoved
public void afterProblemFactRemoved(Object problemFact)
- Specified by:
afterProblemFactRemoved
in interfaceScoreDirector<Solution_>
- Overrides:
afterProblemFactRemoved
in classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>,DroolsConstraintStreamScoreDirectorFactory<Solution_,Score_ extends Score<Score_>>>
-
-