Package org.optaplanner.core.impl.score.director.stream

## 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 the `PlanningSolution` 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 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
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected ScoreInliner<Score_>` | `scoreInliner` |
    `protected org.kie.api.runtime.KieSession` | `session` |

    - ### 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 the `Score` and updates the `working solution` accordingly.
    `void` | `close()` | Needs to be called after use because some implementations need to clean up their resources.
    `Map<String,​ConstraintMatchTotal<Score_>>` | `getConstraintMatchTotalMap()` | Explains the `Score` of `InnerScoreDirector.calculateScore()` by splitting it up per `Constraint`.
    `Map<Object,​Indictment<Score_>>` | `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, 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, getWorkingEntityCount, getWorkingEntityList, getWorkingEntityListRevision, getWorkingSolution, getWorkingValueCount, isAllChangesWillBeUndoneBeforeStepEnds, isConstraintConfiguration, 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`

- - ### Field Detail

    - #### session

          protected org.kie.api.runtime.KieSession session

    - #### scoreInliner

          protected ScoreInliner<Score_ extends Score<Score_>> scoreInliner

  - ### 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`
      The `working solution` must never be the same instance as the `best solution`, it should be a (un)changed clone.
      Specified by:
        `setWorkingSolution` in interface `InnerScoreDirector<Solution_,​Score_ extends Score<Score_>>`
      Overrides:
        `setWorkingSolution` in class `AbstractScoreDirector<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 the `Score` and updates the `working solution` accordingly.
      Returns:
        never null, the `Score` of the `working solution`

    - #### isConstraintMatchEnabled

          public boolean isConstraintMatchEnabled()

      Returns:
        true if `InnerScoreDirector.getConstraintMatchTotalMap()` and `InnerScoreDirector.getIndictmentMap()` can be called

    - #### getConstraintMatchTotalMap

          public Map<String,​ConstraintMatchTotal<Score_>> getConstraintMatchTotalMap()

      Description copied from interface: `InnerScoreDirector`
      Explains the `Score` of `InnerScoreDirector.calculateScore()` by splitting it up per `Constraint`.

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

      Call `InnerScoreDirector.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:
        `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 the `Score`. An `Indictment` is basically the inverse of a `ConstraintMatchTotal`: it is a `Score` total for each justification `Object` in `ConstraintMatch.getJustificationList()`.

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

      Call `InnerScoreDirector.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:
        `InnerScoreDirector.getConstraintMatchTotalMap()`

    - #### 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 interface `AutoCloseable`
      Specified by:
        `close` in interface `InnerScoreDirector<Solution_,​Score_ extends Score<Score_>>`
      Overrides:
        `close` in class `AbstractScoreDirector<Solution_,​Score_ extends Score<Score_>,​DroolsConstraintStreamScoreDirectorFactory<Solution_,​Score_ extends Score<Score_>>>`

    - #### afterEntityAdded

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

      Overrides:
        `afterEntityAdded` in class `AbstractScoreDirector<Solution_,​Score_ extends Score<Score_>,​DroolsConstraintStreamScoreDirectorFactory<Solution_,​Score_ extends Score<Score_>>>`

    - #### afterVariableChanged

          public void afterVariableChanged​(VariableDescriptor<Solution_> variableDescriptor,
                                           Object entity)

      Specified by:
        `afterVariableChanged` in interface `InnerScoreDirector<Solution_,​Score_ extends Score<Score_>>`
      Overrides:
        `afterVariableChanged` in class `AbstractScoreDirector<Solution_,​Score_ extends Score<Score_>,​DroolsConstraintStreamScoreDirectorFactory<Solution_,​Score_ extends Score<Score_>>>`

    - #### afterEntityRemoved

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

      Overrides:
        `afterEntityRemoved` in class `AbstractScoreDirector<Solution_,​Score_ extends Score<Score_>,​DroolsConstraintStreamScoreDirectorFactory<Solution_,​Score_ extends Score<Score_>>>`

    - #### afterProblemFactAdded

          public void afterProblemFactAdded​(Object problemFact)

      Specified by:
        `afterProblemFactAdded` in interface `ScoreDirector<Solution_>`
      Overrides:
        `afterProblemFactAdded` in class `AbstractScoreDirector<Solution_,​Score_ extends Score<Score_>,​DroolsConstraintStreamScoreDirectorFactory<Solution_,​Score_ extends Score<Score_>>>`

    - #### afterProblemPropertyChanged

          public void afterProblemPropertyChanged​(Object problemFactOrEntity)

      Specified by:
        `afterProblemPropertyChanged` in interface `ScoreDirector<Solution_>`
      Overrides:
        `afterProblemPropertyChanged` in class `AbstractScoreDirector<Solution_,​Score_ extends Score<Score_>,​DroolsConstraintStreamScoreDirectorFactory<Solution_,​Score_ extends Score<Score_>>>`

    - #### afterProblemFactRemoved

          public void afterProblemFactRemoved​(Object problemFact)

      Specified by:
        `afterProblemFactRemoved` in interface `ScoreDirector<Solution_>`
      Overrides:
        `afterProblemFactRemoved` in class `AbstractScoreDirector<Solution_,​Score_ extends Score<Score_>,​DroolsConstraintStreamScoreDirectorFactory<Solution_,​Score_ extends Score<Score_>>>`