コード例 #1
0
        private void AfterDeserialization()
        {
            #region conversion of old NSM parameters
            if (Parameters.ContainsKey(SelectorParameterName)) // change SelectorParameter type from ISelector to ISingleObjectiveSelector
            {
                ValueParameter <ISelector> param = Parameters[SelectorParameterName] as ValueParameter <ISelector>;
                if (param != null)
                {
                    ISingleObjectiveSelector selector = param.Value as ISingleObjectiveSelector;
                    if (selector == null)
                    {
                        selector = new TournamentSelector();
                    }
                    Parameters.Remove(SelectorParameterName);
                    Parameters.Add(new ValueParameter <ISingleObjectiveSelector>(SelectorParameterName, "The inner selection operator to select the parents.", selector));
                }
            }
            // FixedValueParameter for quality difference percentage, max attempts, use range
            if (Parameters.ContainsKey(QualityDifferencePercentageParameterName))
            {
                ValueParameter <PercentValue> param = Parameters[QualityDifferencePercentageParameterName] as ValueParameter <PercentValue>;
                if (!(param is FixedValueParameter <PercentValue>))
                {
                    PercentValue diff = param != null ? param.Value as PercentValue : null;
                    if (diff == null)
                    {
                        diff = new PercentValue(0.05);
                    }
                    Parameters.Remove(QualityDifferencePercentageParameterName);
                    Parameters.Add(new FixedValueParameter <PercentValue>(QualityDifferencePercentageParameterName, "The minimum quality difference from parent1 to parent2 to accept the selection.", diff));
                }
            }
            if (Parameters.ContainsKey(QualityDifferenceMaxAttemptsParameterName))
            {
                ValueParameter <IntValue> param = Parameters[QualityDifferenceMaxAttemptsParameterName] as ValueParameter <IntValue>;
                if (!(param is FixedValueParameter <IntValue>))
                {
                    IntValue attempts = param != null ? param.Value as IntValue : null;
                    if (attempts == null)
                    {
                        attempts = new IntValue(5);
                    }
                    Parameters.Remove(QualityDifferenceMaxAttemptsParameterName);
                    Parameters.Add(new FixedValueParameter <IntValue>(QualityDifferenceMaxAttemptsParameterName, "The maximum number of attempts to find parents which differ in quality.", attempts));
                }
            }
            if (Parameters.ContainsKey(QualityDifferenceUseRangeParameterName))
            {
                ValueParameter <BoolValue> param = Parameters[QualityDifferenceUseRangeParameterName] as ValueParameter <BoolValue>;
                if (!(param is FixedValueParameter <BoolValue>))
                {
                    BoolValue range = param != null ? param.Value as BoolValue : null;
                    if (range == null)
                    {
                        range = new BoolValue(true);
                    }
                    Parameters.Remove(QualityDifferenceUseRangeParameterName);
                    Parameters.Add(new FixedValueParameter <BoolValue>(QualityDifferenceUseRangeParameterName, "Use the range from minimum to maximum quality as basis for QualityDifferencePercentage.", range));
                }
            }
            if (!Parameters.ContainsKey(QualityDifferenceUseRangeParameterName)) // add use range parameter
            {
                Parameters.Add(new FixedValueParameter <BoolValue>(QualityDifferenceUseRangeParameterName, "Use the range from minimum to maximum quality as basis for QualityDifferencePercentage.", new BoolValue(true)));
            }
            #endregion

            RegisterParameterEventHandlers();
        }
コード例 #2
0
    private void AfterDeserialization() {
      #region conversion of old NSM parameters
      if (Parameters.ContainsKey(SelectorParameterName)) { // change SelectorParameter type from ISelector to ISingleObjectiveSelector
        ValueParameter<ISelector> param = Parameters[SelectorParameterName] as ValueParameter<ISelector>;
        if (param != null) {
          ISingleObjectiveSelector selector = param.Value as ISingleObjectiveSelector;
          if (selector == null) selector = new TournamentSelector();
          Parameters.Remove(SelectorParameterName);
          Parameters.Add(new ValueParameter<ISingleObjectiveSelector>(SelectorParameterName, "The inner selection operator to select the parents.", selector));
        }
      }
      // FixedValueParameter for quality difference percentage, max attempts, use range
      if (Parameters.ContainsKey(QualityDifferencePercentageParameterName)) {
        ValueParameter<PercentValue> param = Parameters[QualityDifferencePercentageParameterName] as ValueParameter<PercentValue>;
        if (!(param is FixedValueParameter<PercentValue>)) {
          PercentValue diff = param != null ? param.Value as PercentValue : null;
          if (diff == null) diff = new PercentValue(0.05);
          Parameters.Remove(QualityDifferencePercentageParameterName);
          Parameters.Add(new FixedValueParameter<PercentValue>(QualityDifferencePercentageParameterName, "The minimum quality difference from parent1 to parent2 to accept the selection.", diff));
        }
      }
      if (Parameters.ContainsKey(QualityDifferenceMaxAttemptsParameterName)) {
        ValueParameter<IntValue> param = Parameters[QualityDifferenceMaxAttemptsParameterName] as ValueParameter<IntValue>;
        if (!(param is FixedValueParameter<IntValue>)) {
          IntValue attempts = param != null ? param.Value as IntValue : null;
          if (attempts == null) attempts = new IntValue(5);
          Parameters.Remove(QualityDifferenceMaxAttemptsParameterName);
          Parameters.Add(new FixedValueParameter<IntValue>(QualityDifferenceMaxAttemptsParameterName, "The maximum number of attempts to find parents which differ in quality.", attempts));
        }
      }
      if (Parameters.ContainsKey(QualityDifferenceUseRangeParameterName)) {
        ValueParameter<BoolValue> param = Parameters[QualityDifferenceUseRangeParameterName] as ValueParameter<BoolValue>;
        if (!(param is FixedValueParameter<BoolValue>)) {
          BoolValue range = param != null ? param.Value as BoolValue : null;
          if (range == null) range = new BoolValue(true);
          Parameters.Remove(QualityDifferenceUseRangeParameterName);
          Parameters.Add(new FixedValueParameter<BoolValue>(QualityDifferenceUseRangeParameterName, "Use the range from minimum to maximum quality as basis for QualityDifferencePercentage.", range));
        }
      }
      if (!Parameters.ContainsKey(QualityDifferenceUseRangeParameterName)) // add use range parameter
        Parameters.Add(new FixedValueParameter<BoolValue>(QualityDifferenceUseRangeParameterName, "Use the range from minimum to maximum quality as basis for QualityDifferencePercentage.", new BoolValue(true)));
      #endregion

      RegisterParameterEventHandlers();
    }
コード例 #3
0
 private TournamentSelector(TournamentSelector original, Cloner cloner) : base(original, cloner)
 {
 }
コード例 #4
0
 private TournamentSelector(TournamentSelector original, Cloner cloner) : base(original, cloner) { }