Package org.optaplanner.core.impl.heuristic.selector.value.decorator

## Class ProbabilityValueSelector<Solution_>

- java.lang.Object
- - org.optaplanner.core.impl.heuristic.selector.AbstractSelector<Solution_>
  - - org.optaplanner.core.impl.heuristic.selector.value.AbstractValueSelector<Solution_>
    - - org.optaplanner.core.impl.heuristic.selector.value.decorator.ProbabilityValueSelector<Solution_>

- All Implemented Interfaces:
    `Iterable<Object>`, `EventListener`, `SelectionCacheLifecycleListener<Solution_>`, `IterableSelector<Solution_,​Object>`, `Selector<Solution_>`, `EntityIndependentValueSelector<Solution_>`, `ValueSelector<Solution_>`, `PhaseLifecycleListener<Solution_>`, `SolverLifecycleListener<Solution_>`

      public class ProbabilityValueSelector<Solution_>
      extends AbstractValueSelector<Solution_>
      implements EntityIndependentValueSelector<Solution_>, SelectionCacheLifecycleListener<Solution_>

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected NavigableMap<Double,​Object>` | `cachedEntityMap` |
    `protected SelectionCacheType` | `cacheType` |
    `protected EntityIndependentValueSelector<Solution_>` | `childValueSelector` |
    `protected SelectionProbabilityWeightFactory<Solution_,​Object>` | `probabilityWeightFactory` |
    `protected double` | `probabilityWeightTotal` |

    - ### Fields inherited from class org.optaplanner.core.impl.heuristic.selector.AbstractSelector

      `logger, phaseLifecycleSupport, workingRandom`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ProbabilityValueSelector​(EntityIndependentValueSelector<Solution_> childValueSelector, SelectionCacheType cacheType, SelectionProbabilityWeightFactory<Solution_,​Object> probabilityWeightFactory)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `constructCache​(SolverScope<Solution_> solverScope)` |
    `void` | `disposeCache​(SolverScope<Solution_> solverScope)` |
    `Iterator<Object>` | `endingIterator​(Object entity)` | If `Selector.isNeverEnding()` is true, then `ValueSelector.iterator(Object)` will never end.
    `SelectionCacheType` | `getCacheType()` | Unless this selector itself caches, this returns `SelectionCacheType.JUST_IN_TIME`, even if a selector child caches.
    `long` | `getSize()` | A random JIT `Selector` with `Selector.isNeverEnding()` true should return a size as if it would be able to return each distinct element only once, because the size can be used in `SelectionProbabilityWeightFactory`.
    `long` | `getSize​(Object entity)` | Similar to `IterableSelector.getSize()`, but requires an entity.
    `GenuineVariableDescriptor<Solution_>` | `getVariableDescriptor()` |
    `boolean` | `isCountable()` | If false, then `Selector.isNeverEnding()` is true.
    `boolean` | `isNeverEnding()` | Is true if `Selector.isCountable()` is false or if this selector is in random order (for most cases).
    `Iterator<Object>` | `iterator()` |
    `Iterator<Object>` | `iterator​(Object entity)` | Similar to `Iterable.iterator()`, but requires an entity.
    `String` | `toString()` |

    - ### Methods inherited from class org.optaplanner.core.impl.heuristic.selector.AbstractSelector

      `phaseEnded, phaseStarted, solvingEnded, solvingStarted, stepEnded, stepStarted`

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

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

    - ### Methods inherited from interface java.lang.Iterable

      `forEach`

    - ### Methods inherited from interface org.optaplanner.core.impl.heuristic.selector.IterableSelector

      `spliterator`

    - ### Methods inherited from interface org.optaplanner.core.impl.phase.event.PhaseLifecycleListener

      `phaseEnded, phaseStarted, stepEnded, stepStarted`

    - ### Methods inherited from interface org.optaplanner.core.impl.solver.event.SolverLifecycleListener

      `solvingEnded, solvingStarted`

- - ### Field Detail

    - #### childValueSelector

          protected final EntityIndependentValueSelector<Solution_> childValueSelector

    - #### cacheType

          protected final SelectionCacheType cacheType

    - #### probabilityWeightFactory

          protected final SelectionProbabilityWeightFactory<Solution_,​Object> probabilityWeightFactory

    - #### cachedEntityMap

          protected NavigableMap<Double,​Object> cachedEntityMap

    - #### probabilityWeightTotal

          protected double probabilityWeightTotal

  - ### Constructor Detail

    - #### ProbabilityValueSelector

          public ProbabilityValueSelector​(EntityIndependentValueSelector<Solution_> childValueSelector,
                                          SelectionCacheType cacheType,
                                          SelectionProbabilityWeightFactory<Solution_,​Object> probabilityWeightFactory)

  - ### Method Detail

    - #### getCacheType

          public SelectionCacheType getCacheType()

      Description copied from interface: `Selector`
      Unless this selector itself caches, this returns `SelectionCacheType.JUST_IN_TIME`, even if a selector child caches.
      Specified by:
        `getCacheType` in interface `Selector<Solution_>`
      Overrides:
        `getCacheType` in class `AbstractSelector<Solution_>`
      Returns:
        never null

    - #### constructCache

          public void constructCache​(SolverScope<Solution_> solverScope)

      Specified by:
        `constructCache` in interface `SelectionCacheLifecycleListener<Solution_>`

    - #### disposeCache

          public void disposeCache​(SolverScope<Solution_> solverScope)

      Specified by:
        `disposeCache` in interface `SelectionCacheLifecycleListener<Solution_>`

    - #### getVariableDescriptor

          public GenuineVariableDescriptor<Solution_> getVariableDescriptor()

      Specified by:
        `getVariableDescriptor` in interface `ValueSelector<Solution_>`
      Returns:
        never null

    - #### isCountable

          public boolean isCountable()

      Description copied from interface: `Selector`
      If false, then `Selector.isNeverEnding()` is true.
      Specified by:
        `isCountable` in interface `Selector<Solution_>`
      Returns:
        true if all the `ValueRange`s are countable (for example a double value range between 1.2 and 1.4 is not countable)

    - #### isNeverEnding

          public boolean isNeverEnding()

      Description copied from interface: `Selector`
      Is true if `Selector.isCountable()` is false or if this selector is in random order (for most cases). Is never true when this selector is in shuffled order (which is less scalable but more exact).
      Specified by:
        `isNeverEnding` in interface `Selector<Solution_>`
      Returns:
        true if the `Iterator.hasNext()` of the `Iterator` created by `Iterable.iterator()` never returns false (except when it's empty).

    - #### getSize

          public long getSize​(Object entity)

      Description copied from interface: `ValueSelector`
      Similar to `IterableSelector.getSize()`, but requires an entity.
      Specified by:
        `getSize` in interface `ValueSelector<Solution_>`
      Parameters:
        `entity` - never null
      Returns:
        the approximate number of elements generated by this `Selector`, always `>= 0`

    - #### getSize

          public long getSize()

      Description copied from interface: `IterableSelector`
      A random JIT `Selector` with `Selector.isNeverEnding()` true should return a size as if it would be able to return each distinct element only once, because the size can be used in `SelectionProbabilityWeightFactory`.
      Specified by:
        `getSize` in interface `IterableSelector<Solution_,​Object>`
      Returns:
        the approximate number of elements generated by this `Selector`, always `>= 0`

    - #### iterator

          public Iterator<Object> iterator​(Object entity)

      Description copied from interface: `ValueSelector`
      Similar to `Iterable.iterator()`, but requires an entity.
      Specified by:
        `iterator` in interface `ValueSelector<Solution_>`
      Parameters:
        `entity` - never null
      Returns:
        never null

    - #### iterator

          public Iterator<Object> iterator()

      Specified by:
        `iterator` in interface `Iterable<Solution_>`

    - #### endingIterator

          public Iterator<Object> endingIterator​(Object entity)

      Description copied from interface: `ValueSelector`
      If `Selector.isNeverEnding()` is true, then `ValueSelector.iterator(Object)` will never end. This returns an ending `Iterator`, that tries to match `ValueSelector.iterator(Object)` as much as possible, but return each distinct element only once and therefore it might not respect the configuration of this `ValueSelector` entirely.
      Specified by:
        `endingIterator` in interface `ValueSelector<Solution_>`
      Parameters:
        `entity` - never null
      Returns:
        never null
      See Also:
        `ValueSelector.iterator(Object)`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`