Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11013


Ignore:
Timestamp:
06/12/14 14:35:16 (10 years ago)
Author:
bburlacu
Message:

#2143: Added missing check for population slice bounds, added PopulationSize parameter to get the number of individuals (instead of counting the subscopes of the current execution context).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs

    r10955 r11013  
    2727    private const string PruningOperatorParameterName = "PruningOperator";
    2828    private const string ResultsParameterName = "Results";
     29    private const string PopulationSizeParameterName = "PopulationSize";
    2930    #endregion
    3031    #region private members
     
    6263    public IValueParameter<DoubleValue> PruningProbabilityParameter {
    6364      get { return (IValueParameter<DoubleValue>)Parameters[PruningProbabilityParameterName]; }
     65    }
     66    public ILookupParameter<IntValue> PopulationSizeParameter {
     67      get { return (ILookupParameter<IntValue>)Parameters[PopulationSizeParameterName]; }
    6468    }
    6569    #endregion
     
    99103        this.resultsCollector = (ResultsCollector)original.resultsCollector.Clone();
    100104    }
     105
     106    [StorableHook(HookType.AfterDeserialization)]
     107    private void AfterDeserialization() {
     108      if (!Parameters.ContainsKey(PopulationSizeParameterName)) {
     109        Parameters.Add(new LookupParameter<IntValue>(PopulationSizeParameterName, "The population of individuals."));
     110      }
     111    }
     112
    101113    protected SymbolicDataAnalysisSingleObjectivePruningAnalyzer() {
    102114      #region add parameters
     
    109121      Parameters.Add(new FixedValueParameter<DoubleValue>(NodeImpactThresholdParameterName, new DoubleValue(0.0)));
    110122      Parameters.Add(new FixedValueParameter<BoolValue>(PruneOnlyZeroImpactNodesParameterName, new BoolValue(false)));
     123      Parameters.Add(new LookupParameter<IntValue>(PopulationSizeParameterName, "The population of individuals."));
    111124      #endregion
    112125    }
     
    143156    /// <returns>Returns an int range [start, end]</returns>
    144157    private IntRange GetSliceBounds() {
    145       var count = ExecutionContext.Scope.SubScopes.Count;
     158      if (PopulationSlice.Start < 0 || PopulationSlice.End < 0) throw new ArgumentOutOfRangeException("The slice bounds cannot be negative.");
     159      if (PopulationSlice.Start > 1 || PopulationSlice.End > 1) throw new ArgumentOutOfRangeException("The slice bounds should be expressed as unit percentages.");
     160      var count = PopulationSizeParameter.ActualValue.Value;
    146161      var start = (int)Math.Round(PopulationSlice.Start * count);
    147162      var end = (int)Math.Round(PopulationSlice.End * count);
    148163      if (end > count) end = count;
    149164
    150       if (PopulationSlice.Start > 1 || PopulationSlice.End > 1) throw new ArgumentOutOfRangeException("The slice bounds should be expressed as unit percentages.");
    151165      if (start >= end) throw new ArgumentOutOfRangeException("Invalid PopulationSlice bounds.");
    152166      return new IntRange(start, end);
Note: See TracChangeset for help on using the changeset viewer.