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

## Class TestGenDroolsScoreDirector<Solution_>

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

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

      public class TestGenDroolsScoreDirector<Solution_>
      extends DroolsScoreDirector<Solution_>

- - ### 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 and Description
    `TestGenDroolsScoreDirector(DroolsScoreDirectorFactory<Solution_> scoreDirectorFactory, boolean lookUpEnabled, boolean constraintMatchEnabledPreference, List<String> scoreDrlList, List<File> scoreDrlFileList)`

  - ### 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` | `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>` | `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).
    `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, assertPredictedScoreFromScratch, beforeEntityAdded, beforeEntityAdded, beforeEntityRemoved, beforeEntityRemoved, beforeProblemFactAdded, beforeProblemFactRemoved, beforeProblemPropertyChanged, beforeVariableChanged, buildScoreCorruptionAnalysis, buildShadowVariableAnalysis, changeVariableFacade, clone, cloneSolution, cloneWorkingSolution, 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

    - #### TestGenDroolsScoreDirector

          public TestGenDroolsScoreDirector(DroolsScoreDirectorFactory<Solution_> 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: `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 `DroolsScoreDirector<Solution_>`
      Parameters:
        `workingSolution` - never null

    - #### calculateScore

          public Score calculateScore()

      Description copied from interface: `ScoreDirector`
      Calculates the `Score` and updates the `working solution` accordingly.
      Specified by:
        `calculateScore` in interface `ScoreDirector<Solution_>`
      Overrides:
        `calculateScore` in class `DroolsScoreDirector<Solution_>`
      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_>`
      Overrides:
        `assertShadowVariablesAreNotStale` in class `AbstractScoreDirector<Solution_,DroolsScoreDirectorFactory<Solution_>>`
      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_>`
      Overrides:
        `assertWorkingScoreFromScratch` in class `AbstractScoreDirector<Solution_,DroolsScoreDirectorFactory<Solution_>>`
      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_)`

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

      Specified by:
        `getConstraintMatchTotals` in interface `ScoreDirector<Solution_>`
      Overrides:
        `getConstraintMatchTotals` in class `DroolsScoreDirector<Solution_>`
      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.

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

    - #### close

          public void close()

      Description copied from interface: `ScoreDirector`
      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 `ScoreDirector<Solution_>`
      Overrides:
        `close` in class `DroolsScoreDirector<Solution_>`

    - #### afterEntityAdded

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

      Overrides:
        `afterEntityAdded` in class `DroolsScoreDirector<Solution_>`

    - #### beforeVariableChanged

          public void beforeVariableChanged(VariableDescriptor variableDescriptor,
                                            Object entity)

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

    - #### afterVariableChanged

          public void afterVariableChanged(VariableDescriptor variableDescriptor,
                                           Object entity)

      Specified by:
        `afterVariableChanged` in interface `ScoreDirector<Solution_>`
      Overrides:
        `afterVariableChanged` in class `DroolsScoreDirector<Solution_>`

    - #### afterEntityRemoved

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

      Overrides:
        `afterEntityRemoved` in class `DroolsScoreDirector<Solution_>`

    - #### afterProblemFactAdded

          public void afterProblemFactAdded(Object problemFact)

      Specified by:
        `afterProblemFactAdded` in interface `ScoreDirector<Solution_>`
      Overrides:
        `afterProblemFactAdded` in class `DroolsScoreDirector<Solution_>`

    - #### afterProblemFactRemoved

          public void afterProblemFactRemoved(Object problemFact)

      Specified by:
        `afterProblemFactRemoved` in interface `ScoreDirector<Solution_>`
      Overrides:
        `afterProblemFactRemoved` in class `DroolsScoreDirector<Solution_>`

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