org.optaplanner.core.api.score.buildin.hardsoft

## Class HardSoftScoreHolder

- java.lang.Object
- - org.optaplanner.core.api.score.holder.AbstractScoreHolder<HardSoftScore>
  - - org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScoreHolder

- All Implemented Interfaces:
    Serializable, ScoreHolder<HardSoftScore>

      public class HardSoftScoreHolder
      extends AbstractScoreHolder<HardSoftScore>

  See Also:
    `HardSoftScore`, Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.optaplanner.core.api.score.holder.AbstractScoreHolder

      `AbstractScoreHolder.ConstraintActivationUnMatchListener`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `hardScore`
    `protected Map<org.kie.api.definition.rule.Rule,BiConsumer<org.kie.api.runtime.rule.RuleContext,Integer>>` | `matchExecutorByNumberMap`
    `protected Map<org.kie.api.definition.rule.Rule,BiConsumer<org.kie.api.runtime.rule.RuleContext,HardSoftScore>>` | `matchExecutorByScoreMap` Slower than `matchExecutorByNumberMap`
    `protected int` | `softScore`

    - ### Fields inherited from class org.optaplanner.core.api.score.holder.AbstractScoreHolder

      `constraintMatchEnabled, constraintMatchTotalMap, indictmentMap, zeroScore`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HardSoftScoreHolder(boolean constraintMatchEnabled)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addHardConstraintMatch(org.kie.api.runtime.rule.RuleContext kcontext, int hardWeight)`
    `void` | `addMultiConstraintMatch(org.kie.api.runtime.rule.RuleContext kcontext, int hardWeight, int softWeight)`
    `void` | `addSoftConstraintMatch(org.kie.api.runtime.rule.RuleContext kcontext, int softWeight)`
    `void` | `configureConstraintWeight(org.kie.api.definition.rule.Rule rule, HardSoftScore constraintWeight)` Sets up a `ConstraintWeight` from the `ConstraintConfiguration` during initialization.
    `HardSoftScore` | `extractScore(int initScore)` Extracts the `Score`, calculated by the `KieSession` for `DroolsScoreDirector`.
    `int` | `getHardScore()`
    `int` | `getSoftScore()`
    `void` | `impactScore(org.kie.api.runtime.rule.RuleContext kcontext)` For internal use only, use penalize() or reward() instead.
    `void` | `impactScore(org.kie.api.runtime.rule.RuleContext kcontext, int weightMultiplier)` For internal use only, use penalize() or reward() instead.
    `void` | `penalize(org.kie.api.runtime.rule.RuleContext kcontext)` Penalize a match by the `ConstraintWeight` negated.
    `void` | `penalize(org.kie.api.runtime.rule.RuleContext kcontext, int weightMultiplier)` Penalize a match by the `ConstraintWeight` negated and multiplied with the weightMultiplier for all score levels.
    `void` | `penalize(org.kie.api.runtime.rule.RuleContext kcontext, int hardWeightMultiplier, int softWeightMultiplier)` Penalize a match by the `ConstraintWeight` negated and multiplied with the specific weightMultiplier per score level.
    `void` | `reward(org.kie.api.runtime.rule.RuleContext kcontext)` Reward a match by the `ConstraintWeight`.
    `void` | `reward(org.kie.api.runtime.rule.RuleContext kcontext, int weightMultiplier)` Reward a match by the `ConstraintWeight` multiplied with the weightMultiplier for all score levels.
    `void` | `reward(org.kie.api.runtime.rule.RuleContext kcontext, int hardWeightMultiplier, int softWeightMultiplier)` Reward a match by the `ConstraintWeight` multiplied with the specific weightMultiplier per score level.

    - ### Methods inherited from class org.optaplanner.core.api.score.holder.AbstractScoreHolder

      `extractJustificationList, getConstraintMatchTotalMap, getConstraintMatchTotals, getIndictmentMap, impactScore, impactScore, isConstraintMatchEnabled, registerConstraintMatch, setJustificationListConverter`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### matchExecutorByNumberMap

          protected final Map<org.kie.api.definition.rule.Rule,BiConsumer<org.kie.api.runtime.rule.RuleContext,Integer>> matchExecutorByNumberMap

    - #### matchExecutorByScoreMap

          protected final Map<org.kie.api.definition.rule.Rule,BiConsumer<org.kie.api.runtime.rule.RuleContext,HardSoftScore>> matchExecutorByScoreMap

      Slower than `matchExecutorByNumberMap`

    - #### hardScore

          protected int hardScore

    - #### softScore

          protected int softScore

  - ### Constructor Detail

    - #### HardSoftScoreHolder

          public HardSoftScoreHolder(boolean constraintMatchEnabled)

  - ### Method Detail

    - #### getHardScore

          public int getHardScore()

    - #### getSoftScore

          public int getSoftScore()

    - #### configureConstraintWeight

          public void configureConstraintWeight(org.kie.api.definition.rule.Rule rule,
                                                HardSoftScore constraintWeight)

      Description copied from interface: `ScoreHolder`
      Sets up a `ConstraintWeight` from the `ConstraintConfiguration` during initialization.
      Specified by:
        `configureConstraintWeight` in interface `ScoreHolder<HardSoftScore>`
      Overrides:
        `configureConstraintWeight` in class `AbstractScoreHolder<HardSoftScore>`
      Parameters:
        `rule` - never null
        `constraintWeight` - never null, with `Score.getInitScore()` equal to 0.

    - #### penalize

          public void penalize(org.kie.api.runtime.rule.RuleContext kcontext)

      Penalize a match by the `ConstraintWeight` negated.
      Parameters:
        `kcontext` - never null, the magic variable in DRL

    - #### penalize

          public void penalize(org.kie.api.runtime.rule.RuleContext kcontext,
                               int weightMultiplier)

      Penalize a match by the `ConstraintWeight` negated and multiplied with the weightMultiplier for all score levels.
      Parameters:
        `kcontext` - never null, the magic variable in DRL
        `weightMultiplier` - at least 0

    - #### penalize

          public void penalize(org.kie.api.runtime.rule.RuleContext kcontext,
                               int hardWeightMultiplier,
                               int softWeightMultiplier)

      Penalize a match by the `ConstraintWeight` negated and multiplied with the specific weightMultiplier per score level. Slower than `penalize(RuleContext, int)`.
      Parameters:
        `kcontext` - never null, the magic variable in DRL
        `hardWeightMultiplier` - at least 0
        `softWeightMultiplier` - at least 0

    - #### reward

          public void reward(org.kie.api.runtime.rule.RuleContext kcontext)

      Reward a match by the `ConstraintWeight`.
      Parameters:
        `kcontext` - never null, the magic variable in DRL

    - #### reward

          public void reward(org.kie.api.runtime.rule.RuleContext kcontext,
                             int weightMultiplier)

      Reward a match by the `ConstraintWeight` multiplied with the weightMultiplier for all score levels.
      Parameters:
        `kcontext` - never null, the magic variable in DRL
        `weightMultiplier` - at least 0

    - #### reward

          public void reward(org.kie.api.runtime.rule.RuleContext kcontext,
                             int hardWeightMultiplier,
                             int softWeightMultiplier)

      Reward a match by the `ConstraintWeight` multiplied with the specific weightMultiplier per score level. Slower than `reward(RuleContext, int)`.
      Parameters:
        `kcontext` - never null, the magic variable in DRL
        `hardWeightMultiplier` - at least 0
        `softWeightMultiplier` - at least 0

    - #### impactScore

          public void impactScore(org.kie.api.runtime.rule.RuleContext kcontext)

      Description copied from class: `AbstractScoreHolder`
      For internal use only, use penalize() or reward() instead.
      Overrides:
        `impactScore` in class `AbstractScoreHolder<HardSoftScore>`
      Parameters:
        `kcontext` - never null

    - #### impactScore

          public void impactScore(org.kie.api.runtime.rule.RuleContext kcontext,
                                  int weightMultiplier)

      Description copied from class: `AbstractScoreHolder`
      For internal use only, use penalize() or reward() instead.
      Overrides:
        `impactScore` in class `AbstractScoreHolder<HardSoftScore>`
      Parameters:
        `kcontext` - never null
        `weightMultiplier` - any

    - #### addHardConstraintMatch

          public void addHardConstraintMatch(org.kie.api.runtime.rule.RuleContext kcontext,
                                             int hardWeight)

      Parameters:
        `kcontext` - never null, the magic variable in DRL
        `hardWeight` - higher is better, negative for a penalty, positive for a reward

    - #### addSoftConstraintMatch

          public void addSoftConstraintMatch(org.kie.api.runtime.rule.RuleContext kcontext,
                                             int softWeight)

      Parameters:
        `kcontext` - never null, the magic variable in DRL
        `softWeight` - higher is better, negative for a penalty, positive for a reward

    - #### addMultiConstraintMatch

          public void addMultiConstraintMatch(org.kie.api.runtime.rule.RuleContext kcontext,
                                              int hardWeight,
                                              int softWeight)

      Parameters:
        `kcontext` - never null, the magic variable in DRL
        `hardWeight` - higher is better, negative for a penalty, positive for a reward
        `softWeight` - higher is better, negative for a penalty, positive for a reward

    - #### extractScore

          public HardSoftScore extractScore(int initScore)

      Description copied from interface: `ScoreHolder`
      Extracts the `Score`, calculated by the `KieSession` for `DroolsScoreDirector`.

      Should not be called directly, use `ScoreDirector.calculateScore()` instead.

      Parameters:
        `initScore` - `<= 0`, managed by OptaPlanner, needed as a parameter in the `Score`'s creation method, see `Score.getInitScore()`
      Returns:
        never null, the `Score` of the working `PlanningSolution`

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