org.drools.planner.core.score.director
Class AbstractScoreDirector<F extends AbstractScoreDirectorFactory>

java.lang.Object
  extended by org.drools.planner.core.score.director.AbstractScoreDirector<F>
All Implemented Interfaces:
ScoreDirector
Direct Known Subclasses:
DroolsScoreDirector, IncrementalScoreDirector, SimpleScoreDirector

public abstract class AbstractScoreDirector<F extends AbstractScoreDirectorFactory>
extends Object
implements ScoreDirector

Abstract superclass for ScoreDirector.

Implementation note: Extending classes should follow these guidelines:

See Also:
ScoreDirector

Field Summary
protected  long calculateCount
           
protected  Map<PlanningVariableDescriptor,Map<Object,List<Object>>> chainedVariableToTrailingEntitiesMap
           
protected  boolean hasChainedVariables
           
protected  org.slf4j.Logger logger
           
protected  F scoreDirectorFactory
           
protected  Solution workingSolution
           
 
Constructor Summary
protected AbstractScoreDirector(F scoreDirectorFactory)
           
 
Method Summary
 void afterAllVariablesChanged(Object entity)
           
 void afterEntityAdded(Object entity)
           
 void afterEntityRemoved(Object entity)
           
 void afterProblemFactAdded(Object problemFact)
           
 void afterProblemFactChanged(Object problemFact)
           
 void afterProblemFactRemoved(Object problemFact)
           
 void afterVariableChanged(Object entity, String variableName)
           
 void assertWorkingScore(Score workingScore)
          Asserts that if the Score is calculated for the current workingSolution, it would be equal to the parameter workingScore.
 void beforeAllVariablesChanged(Object entity)
           
 void beforeEntityAdded(Object entity)
           
 void beforeEntityRemoved(Object entity)
           
 void beforeProblemFactAdded(Object problemFact)
           
 void beforeProblemFactChanged(Object problemFact)
           
 void beforeProblemFactRemoved(Object problemFact)
           
 void beforeVariableChanged(Object entity, String variableName)
           
protected  String buildScoreCorruptionAnalysis(ScoreDirector uncorruptedScoreDirector)
           
 void dispose()
          Needs to be called after use because some implementations needs to clean up their resources.
 long getCalculateCount()
           
 ScoreDefinition getScoreDefinition()
           
 F getScoreDirectorFactory()
           
 SolutionDescriptor getSolutionDescriptor()
           
 Object getTrailingEntity(PlanningVariableDescriptor chainedVariableDescriptor, Object planningValue)
           
 List<Object> getWorkingPlanningEntityList()
           
 Solution getWorkingSolution()
          The Solution that is used to calculate the Score.
 boolean isWorkingSolutionInitialized()
           
protected  void setCalculatedScore(Score score)
           
 void setWorkingSolution(Solution workingSolution)
          The workingSolution must never be the same instance as the bestSolution, it should be a (un)changed clone.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.drools.planner.core.score.director.ScoreDirector
calculateScore
 

Field Detail

logger

protected final transient org.slf4j.Logger logger

scoreDirectorFactory

protected final F extends AbstractScoreDirectorFactory scoreDirectorFactory

workingSolution

protected Solution workingSolution

hasChainedVariables

protected boolean hasChainedVariables

chainedVariableToTrailingEntitiesMap

protected Map<PlanningVariableDescriptor,Map<Object,List<Object>>> chainedVariableToTrailingEntitiesMap

calculateCount

protected long calculateCount
Constructor Detail

AbstractScoreDirector

protected AbstractScoreDirector(F scoreDirectorFactory)
Method Detail

getScoreDirectorFactory

public F getScoreDirectorFactory()
Specified by:
getScoreDirectorFactory in interface ScoreDirector
Returns:
never null

getSolutionDescriptor

public SolutionDescriptor getSolutionDescriptor()
Specified by:
getSolutionDescriptor in interface ScoreDirector
Returns:
never null

getScoreDefinition

public ScoreDefinition getScoreDefinition()
Specified by:
getScoreDefinition in interface ScoreDirector
Returns:
never null

getWorkingSolution

public Solution getWorkingSolution()
Description copied from interface: ScoreDirector
The Solution that is used to calculate the Score.

Because a Score is best calculated incrementally (by delta's), the ScoreDirector needs to be notified when it's workingSolution changes.

If the Solution has been changed since ScoreDirector.calculateScore() has been called, the Solution.getScore() of this Solution won't be correct.

Specified by:
getWorkingSolution in interface ScoreDirector
Returns:
never null

getCalculateCount

public long getCalculateCount()
Specified by:
getCalculateCount in interface ScoreDirector
Returns:
at least 0L

setWorkingSolution

public void setWorkingSolution(Solution workingSolution)
Description copied from interface: ScoreDirector
The workingSolution must never be the same instance as the bestSolution, it should be a (un)changed clone.

Specified by:
setWorkingSolution in interface ScoreDirector
Parameters:
workingSolution - never null

beforeEntityAdded

public void beforeEntityAdded(Object entity)
Specified by:
beforeEntityAdded in interface ScoreDirector

afterEntityAdded

public void afterEntityAdded(Object entity)
Specified by:
afterEntityAdded in interface ScoreDirector

beforeAllVariablesChanged

public void beforeAllVariablesChanged(Object entity)
Specified by:
beforeAllVariablesChanged in interface ScoreDirector

afterAllVariablesChanged

public void afterAllVariablesChanged(Object entity)
Specified by:
afterAllVariablesChanged in interface ScoreDirector

beforeVariableChanged

public void beforeVariableChanged(Object entity,
                                  String variableName)
Specified by:
beforeVariableChanged in interface ScoreDirector

afterVariableChanged

public void afterVariableChanged(Object entity,
                                 String variableName)
Specified by:
afterVariableChanged in interface ScoreDirector

beforeEntityRemoved

public void beforeEntityRemoved(Object entity)
Specified by:
beforeEntityRemoved in interface ScoreDirector

afterEntityRemoved

public void afterEntityRemoved(Object entity)
Specified by:
afterEntityRemoved in interface ScoreDirector

beforeProblemFactAdded

public void beforeProblemFactAdded(Object problemFact)
Specified by:
beforeProblemFactAdded in interface ScoreDirector

afterProblemFactAdded

public void afterProblemFactAdded(Object problemFact)
Specified by:
afterProblemFactAdded in interface ScoreDirector

beforeProblemFactChanged

public void beforeProblemFactChanged(Object problemFact)
Specified by:
beforeProblemFactChanged in interface ScoreDirector

afterProblemFactChanged

public void afterProblemFactChanged(Object problemFact)
Specified by:
afterProblemFactChanged in interface ScoreDirector

beforeProblemFactRemoved

public void beforeProblemFactRemoved(Object problemFact)
Specified by:
beforeProblemFactRemoved in interface ScoreDirector

afterProblemFactRemoved

public void afterProblemFactRemoved(Object problemFact)
Specified by:
afterProblemFactRemoved in interface ScoreDirector

getWorkingPlanningEntityList

public List<Object> getWorkingPlanningEntityList()
Specified by:
getWorkingPlanningEntityList in interface ScoreDirector
Returns:
never null: an empty list if there are none

isWorkingSolutionInitialized

public boolean isWorkingSolutionInitialized()
Specified by:
isWorkingSolutionInitialized in interface ScoreDirector
Returns:
true if the workingSolution is initialized

setCalculatedScore

protected void setCalculatedScore(Score score)

getTrailingEntity

public Object getTrailingEntity(PlanningVariableDescriptor chainedVariableDescriptor,
                                Object planningValue)
Specified by:
getTrailingEntity in interface ScoreDirector
Parameters:
chainedVariableDescriptor - never null, must be PlanningVariableDescriptor.isChained() true and known to the SolutionDescriptor
planningValue - sometimes null
Returns:
never null

assertWorkingScore

public void assertWorkingScore(Score workingScore)
Description copied from interface: ScoreDirector
Asserts that if the Score is calculated for the current workingSolution, it would be equal to the parameter workingScore.

Furthermore, if the assert fails, a score corruption analysis might be included in the exception message.

Specified by:
assertWorkingScore in interface ScoreDirector
Parameters:
workingScore - never null
See Also:
ScoreDirectorFactory.assertScore(Solution)

buildScoreCorruptionAnalysis

protected String buildScoreCorruptionAnalysis(ScoreDirector uncorruptedScoreDirector)

dispose

public void dispose()
Description copied from interface: ScoreDirector
Needs to be called after use because some implementations needs to clean up their resources.

Specified by:
dispose in interface ScoreDirector

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2001-2014 JBoss by Red Hat. All Rights Reserved.