Class DroolsScoreDirector<Solution_>
- java.lang.Object
-
- org.optaplanner.core.impl.score.director.AbstractScoreDirector<Solution_,DroolsScoreDirectorFactory<Solution_>>
-
- org.optaplanner.core.impl.score.director.drools.DroolsScoreDirector<Solution_>
-
- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotation
- All Implemented Interfaces:
AutoCloseable
,Cloneable
,InnerScoreDirector<Solution_>
,ScoreDirector<Solution_>
- Direct Known Subclasses:
TestGenDroolsScoreDirector
public class DroolsScoreDirector<Solution_> extends AbstractScoreDirector<Solution_,DroolsScoreDirectorFactory<Solution_>>
Drools implementation ofScoreDirector
, which directs the Rule Engine to calculate theScore
of theworking solution
.- See Also:
ScoreDirector
-
-
Field Summary
Fields Modifier and Type Field Description static String
GLOBAL_SCORE_HOLDER_KEY
protected org.kie.api.runtime.KieSession
kieSession
protected ScoreHolder
scoreHolder
-
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 DroolsScoreDirector(DroolsScoreDirectorFactory<Solution_> 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 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>
getConstraintMatchTotalMap()
Collection<ConstraintMatchTotal>
getConstraintMatchTotals()
Map<Object,Indictment>
getIndictmentMap()
Explains the impact of each planning entity or problem fact on theScore
.org.kie.api.runtime.KieSession
getKieSession()
Collection<Object>
getWorkingFacts()
boolean
isConstraintMatchEnabled()
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, assertPredictedScoreFromScratch, assertShadowVariablesAreNotStale, assertWorkingScoreFromScratch, beforeEntityAdded, beforeEntityAdded, beforeEntityRemoved, beforeEntityRemoved, beforeProblemFactAdded, beforeProblemFactRemoved, beforeProblemPropertyChanged, beforeVariableChanged, beforeVariableChanged, buildScoreCorruptionAnalysis, buildShadowVariableAnalysis, changeVariableFacade, clone, cloneSolution, cloneWorkingSolution, 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
-
-
-
-
Field Detail
-
GLOBAL_SCORE_HOLDER_KEY
public static final String GLOBAL_SCORE_HOLDER_KEY
- See Also:
- Constant Field Values
-
kieSession
protected org.kie.api.runtime.KieSession kieSession
-
scoreHolder
protected ScoreHolder scoreHolder
-
-
Constructor Detail
-
DroolsScoreDirector
public DroolsScoreDirector(DroolsScoreDirectorFactory<Solution_> scoreDirectorFactory, boolean lookUpEnabled, boolean constraintMatchEnabledPreference)
-
-
Method Detail
-
getKieSession
public org.kie.api.runtime.KieSession getKieSession()
-
setWorkingSolution
public void setWorkingSolution(Solution_ workingSolution)
Description copied from interface:ScoreDirector
Theworking solution
must never be the same instance as thebest solution
, it should be a (un)changed clone.Only call this method on a separate
ScoreDirector
instance, built bySolverFactory.getScoreDirectorFactory()
, not on the one used inside theSolver
itself.- Specified by:
setWorkingSolution
in interfaceScoreDirector<Solution_>
- Overrides:
setWorkingSolution
in classAbstractScoreDirector<Solution_,DroolsScoreDirectorFactory<Solution_>>
- Parameters:
workingSolution
- never null
-
getWorkingFacts
public Collection<Object> getWorkingFacts()
-
calculateScore
public Score calculateScore()
Description copied from interface:ScoreDirector
Calculates theScore
and updates theworking solution
accordingly.- Returns:
- never null, the
Score
of 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:ScoreDirector
Explains theScore
ofScoreDirector.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 lastPlanningVariable
changes.- Returns:
- never null
- See Also:
ScoreDirector.getConstraintMatchTotalMap()
,ScoreDirector.getIndictmentMap()
-
getConstraintMatchTotalMap
public Map<String,ConstraintMatchTotal> getConstraintMatchTotalMap()
Description copied from interface:ScoreDirector
Explains theScore
ofScoreDirector.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 lastPlanningVariable
changes.- 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:ScoreDirector
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 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 lastPlanningVariable
changes.- Returns:
- never null, the key is a
problem fact
or aplanning entity
- See Also:
ScoreDirector.getConstraintMatchTotalMap()
-
close
public void close()
Description copied from interface:ScoreDirector
Needs to be called after use because some implementations need to clean up their resources.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceScoreDirector<Solution_>
- Overrides:
close
in classAbstractScoreDirector<Solution_,DroolsScoreDirectorFactory<Solution_>>
-
afterEntityAdded
public void afterEntityAdded(EntityDescriptor<Solution_> entityDescriptor, Object entity)
- Overrides:
afterEntityAdded
in classAbstractScoreDirector<Solution_,DroolsScoreDirectorFactory<Solution_>>
-
afterVariableChanged
public void afterVariableChanged(VariableDescriptor variableDescriptor, Object entity)
- Specified by:
afterVariableChanged
in interfaceScoreDirector<Solution_>
- Overrides:
afterVariableChanged
in classAbstractScoreDirector<Solution_,DroolsScoreDirectorFactory<Solution_>>
-
afterEntityRemoved
public void afterEntityRemoved(EntityDescriptor<Solution_> entityDescriptor, Object entity)
- Overrides:
afterEntityRemoved
in classAbstractScoreDirector<Solution_,DroolsScoreDirectorFactory<Solution_>>
-
afterProblemFactAdded
public void afterProblemFactAdded(Object problemFact)
- Specified by:
afterProblemFactAdded
in interfaceScoreDirector<Solution_>
- Overrides:
afterProblemFactAdded
in classAbstractScoreDirector<Solution_,DroolsScoreDirectorFactory<Solution_>>
-
afterProblemPropertyChanged
public void afterProblemPropertyChanged(Object problemFactOrEntity)
- Specified by:
afterProblemPropertyChanged
in interfaceScoreDirector<Solution_>
- Overrides:
afterProblemPropertyChanged
in classAbstractScoreDirector<Solution_,DroolsScoreDirectorFactory<Solution_>>
-
afterProblemFactRemoved
public void afterProblemFactRemoved(Object problemFact)
- Specified by:
afterProblemFactRemoved
in interfaceScoreDirector<Solution_>
- Overrides:
afterProblemFactRemoved
in classAbstractScoreDirector<Solution_,DroolsScoreDirectorFactory<Solution_>>
-
-