Package org.optaplanner.core.impl.score.director.drools.testgen

## Class TestGenDroolsScoreDirector<Solution_,​Score_ extends Score<Score_>>

- java.lang.Object
- - org.optaplanner.core.impl.score.director.AbstractScoreDirector<Solution_,​Score_,​DroolsScoreDirectorFactory<Solution_,​Score_>>
  - - org.optaplanner.core.impl.score.director.drools.DroolsScoreDirector<Solution_,​Score_>
    - - org.optaplanner.core.impl.score.director.drools.testgen.TestGenDroolsScoreDirector<Solution_,​Score_>

- All Implemented Interfaces:
    `AutoCloseable`, `Cloneable`, `ScoreDirector<Solution_>`, `InnerScoreDirector<Solution_,​Score_>`

      public class TestGenDroolsScoreDirector<Solution_,​Score_ extends Score<Score_>>
      extends DroolsScoreDirector<Solution_,​Score_>

- - ### Field Summary

    - ### Fields inherited from class org.optaplanner.core.impl.score.director.drools.DroolsScoreDirector

      `GLOBAL_SCORE_HOLDER_KEY, kieSession, 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
    --- | ---
    `TestGenDroolsScoreDirector​(DroolsScoreDirectorFactory<Solution_,​Score_> scoreDirectorFactory, boolean lookUpEnabled, boolean constraintMatchEnabledPreference, List<String> scoreDrlList, List<File> scoreDrlFileList)` |

  - ### 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` | `afterVariableChanged​(VariableDescriptor variableDescriptor, Object entity)` |
    `void` | `assertShadowVariablesAreNotStale​(Score_ expectedWorkingScore, Object completedAction)` | Asserts that if all `VariableListener`s are forcibly triggered, and therefore all shadow variables are updated if needed, that none of the shadow variables of the `working solution` change, Then also asserts that the `Score` calculated for the `working solution` afterwards is equal to the parameter `expectedWorkingScore`.
    `void` | `assertWorkingScoreFromScratch​(Score_ workingScore, Object completedAction)` | Asserts that if the `Score` is calculated for the current `working solution` in a fresh `ScoreDirector` (with no incremental calculation residue), it is equal to the parameter `workingScore`.
    `void` | `beforeVariableChanged​(VariableDescriptor 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.
    `org.kie.api.runtime.KieSession` | `createKieSession()` |
    `Map<String,​ConstraintMatchTotal<Score_>>` | `getConstraintMatchTotalMap()` | Explains the `Score` of `InnerScoreDirector.calculateScore()` by splitting it up per `Constraint`.
    `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.drools.DroolsScoreDirector

      `afterProblemPropertyChanged, getIndictmentMap, getKieSession, getWorkingFacts, isConstraintMatchEnabled`

    - ### Methods inherited from class org.optaplanner.core.impl.score.director.AbstractScoreDirector

      `afterEntityAdded, afterEntityRemoved, afterVariableChanged, assertExpectedUndoMoveScore, assertExpectedWorkingScore, assertNonNullPlanningIds, assertPredictedScoreFromScratch, beforeEntityAdded, beforeEntityAdded, beforeEntityRemoved, beforeEntityRemoved, beforeProblemFactAdded, beforeProblemFactRemoved, beforeProblemPropertyChanged, beforeVariableChanged, buildScoreCorruptionAnalysis, buildShadowVariableAnalysis, changeVariableFacade, clone, cloneSolution, cloneWorkingSolution, createChildThreadScoreDirector, createShadowVariablesViolationMessage, doAndProcessMove, doAndProcessMove, 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`

- - ### Constructor Detail

    - #### TestGenDroolsScoreDirector

          public TestGenDroolsScoreDirector​(DroolsScoreDirectorFactory<Solution_,​Score_> scoreDirectorFactory,
                                            boolean lookUpEnabled,
                                            boolean constraintMatchEnabledPreference,
                                            List<String> scoreDrlList,
                                            List<File> scoreDrlFileList)

  - ### Method Detail

    - #### createKieSession

          public org.kie.api.runtime.KieSession createKieSession()

    - #### 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 `DroolsScoreDirector<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.
      Specified by:
        `calculateScore` in interface `InnerScoreDirector<Solution_,​Score_ extends Score<Score_>>`
      Overrides:
        `calculateScore` in class `DroolsScoreDirector<Solution_,​Score_ extends Score<Score_>>`
      Returns:
        never null, the `Score` of the `working solution`

    - #### assertShadowVariablesAreNotStale

          public void assertShadowVariablesAreNotStale​(Score_ expectedWorkingScore,
                                                       Object completedAction)

      Description copied from interface: `InnerScoreDirector`
      Asserts that if all `VariableListener`s are forcibly triggered, and therefore all shadow variables are updated if needed, that none of the shadow variables of the `working solution` change, Then also asserts that the `Score` calculated for the `working solution` afterwards is equal to the parameter `expectedWorkingScore`.

      Used to assert that the shadow variables' state is consistent with the genuine variables' state.

      Specified by:
        `assertShadowVariablesAreNotStale` in interface `InnerScoreDirector<Solution_,​Score_ extends Score<Score_>>`
      Overrides:
        `assertShadowVariablesAreNotStale` in class `AbstractScoreDirector<Solution_,​Score_ extends Score<Score_>,​DroolsScoreDirectorFactory<Solution_,​Score_ extends Score<Score_>>>`
      Parameters:
        `expectedWorkingScore` - never null
        `completedAction` - sometimes null, when assertion fails then the completedAction's `Object.toString()` is included in the exception message

    - #### assertWorkingScoreFromScratch

          public void assertWorkingScoreFromScratch​(Score_ workingScore,
                                                    Object completedAction)

      Description copied from interface: `InnerScoreDirector`
      Asserts that if the `Score` is calculated for the current `working solution` in a fresh `ScoreDirector` (with no incremental calculation residue), it is equal to the parameter `workingScore`.

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

      Specified by:
        `assertWorkingScoreFromScratch` in interface `InnerScoreDirector<Solution_,​Score_ extends Score<Score_>>`
      Overrides:
        `assertWorkingScoreFromScratch` in class `AbstractScoreDirector<Solution_,​Score_ extends Score<Score_>,​DroolsScoreDirectorFactory<Solution_,​Score_ extends Score<Score_>>>`
      Parameters:
        `workingScore` - never null
        `completedAction` - sometimes null, when assertion fails then the completedAction's `Object.toString()` is included in the exception message
      See Also:
        `InnerScoreDirectorFactory.assertScoreFromScratch(Solution_)`

    - #### 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.

      Specified by:
        `getConstraintMatchTotalMap` in interface `InnerScoreDirector<Solution_,​Score_ extends Score<Score_>>`
      Overrides:
        `getConstraintMatchTotalMap` in class `DroolsScoreDirector<Solution_,​Score_ extends Score<Score_>>`
      Returns:
        never null, the key is the `constraintId` (to create one, use `ConstraintMatchTotal.composeConstraintId(String, String)`).
      See Also:
        `InnerScoreDirector.getIndictmentMap()`

    - #### 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 `DroolsScoreDirector<Solution_,​Score_ extends Score<Score_>>`

    - #### afterEntityAdded

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

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

    - #### beforeVariableChanged

          public void beforeVariableChanged​(VariableDescriptor variableDescriptor,
                                            Object entity)

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

    - #### afterVariableChanged

          public void afterVariableChanged​(VariableDescriptor variableDescriptor,
                                           Object entity)

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

    - #### afterEntityRemoved

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

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

    - #### afterProblemFactAdded

          public void afterProblemFactAdded​(Object problemFact)

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

    - #### afterProblemFactRemoved

          public void afterProblemFactRemoved​(Object problemFact)

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