org.optaplanner.core.impl.score.director.incremental

## Class IncrementalScoreDirector<Solution_>

- java.lang.Object
- - org.optaplanner.core.impl.score.director.AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>
  - - org.optaplanner.core.impl.score.director.incremental.IncrementalScoreDirector<Solution_>

- Type Parameters:
    `Solution_` - the solution type, the class with the `PlanningSolution` annotation
  All Implemented Interfaces:
    AutoCloseable, Cloneable, InnerScoreDirector<Solution_>, ScoreDirector<Solution_>

      public class IncrementalScoreDirector<Solution_>
      extends AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>

  Incremental java implementation of `ScoreDirector`, which only recalculates the `Score` of the part of the `working solution` that changed, instead of the going through the entire `PlanningSolution`. 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 and Description
    `IncrementalScoreDirector(IncrementalScoreDirectorFactory<Solution_> scoreDirectorFactory, boolean lookUpEnabled, boolean constraintMatchEnabledPreference, IncrementalScoreCalculator<Solution_> incrementalScoreCalculator)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and 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)`
    `void` | `beforeEntityAdded(EntityDescriptor<Solution_> entityDescriptor, Object entity)`
    `void` | `beforeEntityRemoved(EntityDescriptor<Solution_> entityDescriptor, Object entity)`
    `void` | `beforeProblemFactAdded(Object problemFact)`
    `void` | `beforeProblemFactRemoved(Object problemFact)`
    `void` | `beforeProblemPropertyChanged(Object problemFactOrEntity)`
    `void` | `beforeVariableChanged(VariableDescriptor variableDescriptor, Object entity)`
    `Score` | `calculateScore()` Calculates the `Score` and updates the `working solution` accordingly.
    `Map<String,ConstraintMatchTotal>` | `getConstraintMatchTotalMap()` Explains the `Score` of `ScoreDirector.calculateScore()` by splitting it up per constraint type (which is usually a score rule).
    `Collection<ConstraintMatchTotal>` | `getConstraintMatchTotals()` Explains the `Score` of `ScoreDirector.calculateScore()` by splitting it up per constraint type (which is usually a score rule).
    `IncrementalScoreCalculator<Solution_>` | `getIncrementalScoreCalculator()`
    `Map<Object,Indictment>` | `getIndictmentMap()` Explains the impact of each planning entity or problem fact on the `Score`.
    `boolean` | `isConstraintMatchEnabled()`
    `void` | `setWorkingSolution(Solution_ workingSolution)` The `working solution` must never be the same instance as the `best 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, beforeEntityRemoved, beforeVariableChanged, buildScoreCorruptionAnalysis, buildShadowVariableAnalysis, changeVariableFacade, clone, cloneSolution, cloneWorkingSolution, close, 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`

- - ### Constructor Detail

    - #### IncrementalScoreDirector

          public IncrementalScoreDirector(IncrementalScoreDirectorFactory<Solution_> scoreDirectorFactory,
                                          boolean lookUpEnabled,
                                          boolean constraintMatchEnabledPreference,
                                          IncrementalScoreCalculator<Solution_> incrementalScoreCalculator)

  - ### Method Detail

    - #### getIncrementalScoreCalculator

          public IncrementalScoreCalculator<Solution_> getIncrementalScoreCalculator()

    - #### setWorkingSolution

          public void setWorkingSolution(Solution_ workingSolution)

      Description copied from interface: `ScoreDirector`
      The `working solution` must never be the same instance as the `best solution`, it should be a (un)changed clone.

      Only call this method on a separate `ScoreDirector` instance, built by `SolverFactory.getScoreDirectorFactory()`, not on the one used inside the `Solver` itself.

      Specified by:
        `setWorkingSolution` in interface `ScoreDirector<Solution_>`
      Overrides:
        `setWorkingSolution` in class `AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>`
      Parameters:
        `workingSolution` - never null

    - #### calculateScore

          public Score calculateScore()

      Description copied from interface: `ScoreDirector`
      Calculates the `Score` and updates the `working solution` accordingly.
      Returns:
        never null, the `Score` of the `working solution`

    - #### isConstraintMatchEnabled

          public boolean isConstraintMatchEnabled()

      Returns:
        true if `ScoreDirector.getConstraintMatchTotals()`, `ScoreDirector.getConstraintMatchTotalMap()` and `ScoreDirector.getIndictmentMap()` can be called

    - #### getConstraintMatchTotals

          public Collection<ConstraintMatchTotal> getConstraintMatchTotals()

      Description copied from interface: `ScoreDirector`
      Explains the `Score` of `ScoreDirector.calculateScore()` by splitting it up per constraint type (which is usually a score rule).

      The sum of `ConstraintMatchTotal.getScore()` equals `ScoreDirector.calculateScore()`.

      Call `ScoreDirector.calculateScore()` before calling this method, unless that method has already been called since the last `PlanningVariable` changes.

      Returns:
        never null
      See Also:
        `ScoreDirector.getConstraintMatchTotalMap()`, `ScoreDirector.getIndictmentMap()`

    - #### getConstraintMatchTotalMap

          public Map<String,ConstraintMatchTotal> getConstraintMatchTotalMap()

      Description copied from interface: `ScoreDirector`
      Explains the `Score` of `ScoreDirector.calculateScore()` by splitting it up per constraint type (which is usually a score rule).

      The sum of `ConstraintMatchTotal.getScore()` equals `ScoreDirector.calculateScore()`.

      Call `ScoreDirector.calculateScore()` before calling this method, unless that method has already been called since the last `PlanningVariable` changes.

      Returns:
        never null, the key is the `constraintId` (to create one, use `ConstraintMatchTotal.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 the `Score`. An `Indictment` is basically the inverse of a `ConstraintMatchTotal`: it is a `Score` total for each justification `Object` in `ConstraintMatch.getJustificationList()`.

      Warning: In practice, it often doesn't include the full impact on the `Score`, for example in DRL score rules with accumulate, the accumulate elements won't be indicted.

      The sum of `ConstraintMatchTotal.getScore()` differs from `ScoreDirector.calculateScore()` because each `ConstraintMatch.getScore()` is counted for each justification in `ConstraintMatch.getJustificationList()`.

      Call `ScoreDirector.calculateScore()` before calling this method, unless that method has already been called since the last `PlanningVariable` changes.

      Returns:
        never null, the key is a `problem fact` or a `planning entity`
      See Also:
        `ScoreDirector.getConstraintMatchTotalMap()`

    - #### beforeEntityAdded

          public void beforeEntityAdded(EntityDescriptor<Solution_> entityDescriptor,
                                        Object entity)

      Overrides:
        `beforeEntityAdded` in class `AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>`

    - #### afterEntityAdded

          public void afterEntityAdded(EntityDescriptor<Solution_> entityDescriptor,
                                       Object entity)

      Overrides:
        `afterEntityAdded` in class `AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>`

    - #### beforeVariableChanged

          public void beforeVariableChanged(VariableDescriptor variableDescriptor,
                                            Object entity)

      Specified by:
        `beforeVariableChanged` in interface `ScoreDirector<Solution_>`
      Overrides:
        `beforeVariableChanged` in class `AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>`

    - #### afterVariableChanged

          public void afterVariableChanged(VariableDescriptor variableDescriptor,
                                           Object entity)

      Specified by:
        `afterVariableChanged` in interface `ScoreDirector<Solution_>`
      Overrides:
        `afterVariableChanged` in class `AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>`

    - #### beforeEntityRemoved

          public void beforeEntityRemoved(EntityDescriptor<Solution_> entityDescriptor,
                                          Object entity)

      Overrides:
        `beforeEntityRemoved` in class `AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>`

    - #### afterEntityRemoved

          public void afterEntityRemoved(EntityDescriptor<Solution_> entityDescriptor,
                                         Object entity)

      Overrides:
        `afterEntityRemoved` in class `AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>`

    - #### beforeProblemFactAdded

          public void beforeProblemFactAdded(Object problemFact)

      Specified by:
        `beforeProblemFactAdded` in interface `ScoreDirector<Solution_>`
      Overrides:
        `beforeProblemFactAdded` in class `AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>`

    - #### afterProblemFactAdded

          public void afterProblemFactAdded(Object problemFact)

      Specified by:
        `afterProblemFactAdded` in interface `ScoreDirector<Solution_>`
      Overrides:
        `afterProblemFactAdded` in class `AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>`

    - #### beforeProblemPropertyChanged

          public void beforeProblemPropertyChanged(Object problemFactOrEntity)

      Specified by:
        `beforeProblemPropertyChanged` in interface `ScoreDirector<Solution_>`
      Overrides:
        `beforeProblemPropertyChanged` in class `AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>`

    - #### afterProblemPropertyChanged

          public void afterProblemPropertyChanged(Object problemFactOrEntity)

      Specified by:
        `afterProblemPropertyChanged` in interface `ScoreDirector<Solution_>`
      Overrides:
        `afterProblemPropertyChanged` in class `AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>`

    - #### beforeProblemFactRemoved

          public void beforeProblemFactRemoved(Object problemFact)

      Specified by:
        `beforeProblemFactRemoved` in interface `ScoreDirector<Solution_>`
      Overrides:
        `beforeProblemFactRemoved` in class `AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>`

    - #### afterProblemFactRemoved

          public void afterProblemFactRemoved(Object problemFact)

      Specified by:
        `afterProblemFactRemoved` in interface `ScoreDirector<Solution_>`
      Overrides:
        `afterProblemFactRemoved` in class `AbstractScoreDirector<Solution_,IncrementalScoreDirectorFactory<Solution_>>`

Copyright © 2006–2019 JBoss by Red Hat. All rights reserved.