Пример #1
0
  /**
   * @param environmentMode never null
   * @param solutionDescriptor never null
   * @param entityDescriptor never null
   * @param minimumCacheType never null, If caching is used (different from {@link
   *     SelectionCacheType#JUST_IN_TIME}), then it should be at least this {@link
   *     SelectionCacheType} because an ancestor already uses such caching and less would be
   *     pointless.
   * @param inheritedSelectionOrder never null
   * @return never null
   */
  public ValueSelector buildValueSelector(
      EnvironmentMode environmentMode,
      SolutionDescriptor solutionDescriptor,
      PlanningEntityDescriptor entityDescriptor,
      SelectionCacheType minimumCacheType,
      SelectionOrder inheritedSelectionOrder) {
    PlanningVariableDescriptor variableDescriptor =
        deduceVariableDescriptor(entityDescriptor, variableName);
    SelectionCacheType resolvedCacheType = SelectionCacheType.resolve(cacheType, minimumCacheType);
    SelectionOrder resolvedSelectionOrder =
        SelectionOrder.resolve(selectionOrder, inheritedSelectionOrder);

    validateCacheTypeVersusSelectionOrder(resolvedCacheType, resolvedSelectionOrder);
    //        validateSorting(resolvedSelectionOrder);
    validateProbability(resolvedSelectionOrder);

    // baseValueSelector and lower should be SelectionOrder.ORIGINAL if they are going to get cached
    // completely
    ValueSelector valueSelector =
        buildBaseValueSelector(
            environmentMode,
            variableDescriptor,
            SelectionCacheType.max(minimumCacheType, resolvedCacheType),
            determineBaseRandomSelection(
                variableDescriptor, resolvedCacheType, resolvedSelectionOrder));

    //        valueSelector = applyFiltering(variableDescriptor, resolvedCacheType,
    // resolvedSelectionOrder, valueSelector);
    //        valueSelector = applySorting(resolvedCacheType, resolvedSelectionOrder,
    // valueSelector);
    valueSelector = applyProbability(resolvedCacheType, resolvedSelectionOrder, valueSelector);
    valueSelector = applyShuffling(resolvedCacheType, resolvedSelectionOrder, valueSelector);
    valueSelector = applyCaching(resolvedCacheType, resolvedSelectionOrder, valueSelector);
    return valueSelector;
  }