Interface ScoreDirector<Solution_>
-
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation
- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
InnerScoreDirector<Solution_>
- All Known Implementing Classes:
AbstractScoreDirector,ConstraintStreamScoreDirector,DroolsScoreDirector,EasyScoreDirector,IncrementalScoreDirector,TestGenDroolsScoreDirector
public interface ScoreDirector<Solution_> extends AutoCloseable
The ScoreDirector holds theworking solutionand calculates theScorefor it.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description voidafterEntityAdded(Object entity)voidafterEntityRemoved(Object entity)voidafterProblemFactAdded(Object problemFact)voidafterProblemFactRemoved(Object problemFact)voidafterProblemPropertyChanged(Object problemFactOrEntity)voidafterVariableChanged(Object entity, String variableName)voidafterVariableChanged(VariableDescriptor variableDescriptor, Object entity)voidbeforeEntityAdded(Object entity)voidbeforeEntityRemoved(Object entity)voidbeforeProblemFactAdded(Object problemFact)voidbeforeProblemFactRemoved(Object problemFact)voidbeforeProblemPropertyChanged(Object problemFactOrEntity)voidbeforeVariableChanged(Object entity, String variableName)voidbeforeVariableChanged(VariableDescriptor variableDescriptor, Object entity)ScorecalculateScore()Calculates theScoreand updates theworking solutionaccordingly.voidchangeVariableFacade(VariableDescriptor variableDescriptor, Object entity, Object newValue)voidclose()Needs to be called after use because some implementations need to clean up their resources.default voiddispose()Deprecated.in favor ofclose()StringexplainScore()Returns a diagnostic text that explains theScorethrough theConstraintMatchAPI to identify which constraints or planning entities cause that score quality.Map<String,ConstraintMatchTotal>getConstraintMatchTotalMap()Collection<ConstraintMatchTotal>getConstraintMatchTotals()Map<Object,Indictment>getIndictmentMap()Explains the impact of each planning entity or problem fact on theScore.Solution_getWorkingSolution()ThePlanningSolutionthat is used to calculate theScore.booleanisConstraintMatchEnabled()<E> ElookUpWorkingObject(E externalObject)Translates an entity or fact instance (often from anotherThreador JVM) to thisScoreDirector's internal working instance.<E> ElookUpWorkingObjectOrReturnNull(E externalObject)As defined bylookUpWorkingObject(Object), but doesn't fail fast if no workingObject was ever added for the externalObject.voidsetWorkingSolution(Solution_ workingSolution)Theworking solutionmust never be the same instance as thebest solution, it should be a (un)changed clone.voidtriggerVariableListeners()
-
-
-
Method Detail
-
getWorkingSolution
Solution_ getWorkingSolution()
ThePlanningSolutionthat is used to calculate theScore.Because a
Scoreis best calculated incrementally (by deltas), theScoreDirectorneeds to be notified when itsworking solutionchanges.If the
working solutionhas been changed sincecalculateScore()was called, itsScorewon't be correct.- Returns:
- never null
-
setWorkingSolution
void setWorkingSolution(Solution_ workingSolution)
Theworking 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.- Parameters:
workingSolution- never null
-
calculateScore
Score calculateScore()
Calculates theScoreand updates theworking solutionaccordingly.- Returns:
- never null, the
Scoreof theworking solution
-
isConstraintMatchEnabled
boolean isConstraintMatchEnabled()
- Returns:
- true if
getConstraintMatchTotals(),getConstraintMatchTotalMap()andgetIndictmentMap()can be called
-
getConstraintMatchTotals
Collection<ConstraintMatchTotal> getConstraintMatchTotals()
Explains theScoreofcalculateScore()by splitting it up perConstraint.The sum of
ConstraintMatchTotal.getScore()equalscalculateScore().Call
calculateScore()before calling this method, unless that method has already been called since the lastPlanningVariablechanges.- Returns:
- never null
- Throws:
IllegalStateException- ifisConstraintMatchEnabled()returns false- See Also:
getConstraintMatchTotalMap(),getIndictmentMap()
-
getConstraintMatchTotalMap
Map<String,ConstraintMatchTotal> getConstraintMatchTotalMap()
Explains theScoreofcalculateScore()by splitting it up perConstraint.The sum of
ConstraintMatchTotal.getScore()equalscalculateScore().Call
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)). - Throws:
IllegalStateException- ifisConstraintMatchEnabled()returns false- See Also:
getIndictmentMap()
-
getIndictmentMap
Map<Object,Indictment> getIndictmentMap()
Explains 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 fromcalculateScore()because eachConstraintMatch.getScore()is counted for each justification inConstraintMatch.getJustificationList().Call
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 - Throws:
IllegalStateException- ifisConstraintMatchEnabled()returns false- See Also:
getConstraintMatchTotalMap()
-
explainScore
String explainScore()
Returns a diagnostic text that explains theScorethrough theConstraintMatchAPI to identify which constraints or planning entities cause that score quality. In case of aninfeasiblesolution, this can help diagnose the cause of that.Do not parse this string. Instead, to provide this information in a UI or a service, use
getConstraintMatchTotalMap()andgetIndictmentMap()and convert those into a domain specific API.This automatically calls
calculateScore()first.- Returns:
- never null
- Throws:
IllegalStateException- ifisConstraintMatchEnabled()returns false
-
beforeEntityAdded
void beforeEntityAdded(Object entity)
-
afterEntityAdded
void afterEntityAdded(Object entity)
-
triggerVariableListeners
void triggerVariableListeners()
-
beforeEntityRemoved
void beforeEntityRemoved(Object entity)
-
afterEntityRemoved
void afterEntityRemoved(Object entity)
-
beforeProblemFactAdded
void beforeProblemFactAdded(Object problemFact)
-
afterProblemFactAdded
void afterProblemFactAdded(Object problemFact)
-
beforeProblemPropertyChanged
void beforeProblemPropertyChanged(Object problemFactOrEntity)
-
afterProblemPropertyChanged
void afterProblemPropertyChanged(Object problemFactOrEntity)
-
beforeProblemFactRemoved
void beforeProblemFactRemoved(Object problemFact)
-
afterProblemFactRemoved
void afterProblemFactRemoved(Object problemFact)
-
lookUpWorkingObject
<E> E lookUpWorkingObject(E externalObject)
Translates an entity or fact instance (often from anotherThreador JVM) to thisScoreDirector's internal working instance. Useful forMove.rebase(ScoreDirector)and in aProblemFactChange.Matching is determined by the
LookUpStrategyTypeonPlanningSolution. Matching uses aPlanningIdby default.- Type Parameters:
E- the object type- Parameters:
externalObject- sometimes null- Returns:
- null if externalObject is null
- Throws:
IllegalArgumentException- if there is no workingObject for externalObject, if it cannot be looked up or if the externalObject's class is not supportedIllegalStateException- if it cannot be looked up
-
lookUpWorkingObjectOrReturnNull
<E> E lookUpWorkingObjectOrReturnNull(E externalObject)
As defined bylookUpWorkingObject(Object), but doesn't fail fast if no workingObject was ever added for the externalObject. It's recommended to uselookUpWorkingObject(Object)instead, especially in aMove.rebase(ScoreDirector)code.- Type Parameters:
E- the object type- Parameters:
externalObject- sometimes null- Returns:
- null if externalObject is null or if there is no workingObject for externalObject
- Throws:
IllegalArgumentException- if it cannot be looked up or if the externalObject's class is not supportedIllegalStateException- if it cannot be looked up
-
close
void close()
Needs to be called after use because some implementations need to clean up their resources.- Specified by:
closein interfaceAutoCloseable
-
dispose
@Deprecated default void dispose()
Deprecated.in favor ofclose()
-
beforeVariableChanged
void beforeVariableChanged(VariableDescriptor variableDescriptor, Object entity)
-
afterVariableChanged
void afterVariableChanged(VariableDescriptor variableDescriptor, Object entity)
-
changeVariableFacade
void changeVariableFacade(VariableDescriptor variableDescriptor, Object entity, Object newValue)
-
-