Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/11/11 16:00:17 (14 years ago)
Author:
cneumuel
Message:

#1215

  • implemented crossover and manipulator operators for int and double values
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/Manipulators/ParameterConfigurationManipulator.cs

    r5112 r5277  
    4949
    5050    public sealed override IOperation Apply() {
    51       Apply(RandomParameter.ActualValue, ParameterConfigurationTreeParameter.ActualValue, this);
     51      Apply(RandomParameter.ActualValue, ParameterConfigurationTreeParameter.ActualValue, IntValueManipulatorParameter.ActualValue, DoubleValueManipulatorParameter.ActualValue);
    5252      return base.Apply();
    5353    }
    5454
    55     public static void Apply(IRandom random, IValueConfiguration configuration, ParameterConfigurationManipulator pcmanip) {
    56       configuration.Mutate(random, Mutate, pcmanip);
     55    public static void Apply(IRandom random, IValueConfiguration configuration, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator) {
     56      configuration.Mutate(random, Mutate, intValueManipulator, doubleValueManipulator);
    5757    }
    5858
    59     private static void Mutate(IRandom random, IOptimizable configuration, ParameterConfigurationManipulator pcmanip) {
    60       if (configuration is IValueConfiguration) {
    61         var vc = configuration as IValueConfiguration;
     59    private static void Mutate(IRandom random, IOptimizable configuration, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator) {
     60      var vc = configuration as IValueConfiguration;
     61      var pc = configuration as IParameterConfiguration;
     62
     63      if (vc != null) {
    6264        var value = vc.ActualValue.Value;
    6365        var range = vc.RangeConstraint;
    6466        if (value is IntValue) {
    65           pcmanip.IntValueManipulatorParameter.ActualValue.Apply(random, (IntValue)value, (IntValueRange)range);
     67          intValueManipulator.Apply(random, (IntValue)value, (IntValueRange)range);
    6668        } else if (value is PercentValue) {
    67           pcmanip.DoubleValueManipulatorParameter.ActualValue.Apply(random, (PercentValue)value, ((PercentValueRange)range).AsDoubleValueRange());
     69          doubleValueManipulator.Apply(random, (PercentValue)value, ((PercentValueRange)range).AsDoubleValueRange());
    6870        } else if (value is DoubleValue) {
    69           pcmanip.DoubleValueManipulatorParameter.ActualValue.Apply(random, (DoubleValue)value, (DoubleValueRange)range);
     71          doubleValueManipulator.Apply(random, (DoubleValue)value, (DoubleValueRange)range);
    7072        }
    71       } else if (configuration is IParameterConfiguration) {
    72         var pc = configuration as IParameterConfiguration;
    73         pc.ActualValueConfigurationIndex = random.Next(pc.ValueConfigurations.CheckedItems.Count());
    74         pc.ActualValue = pc.ValueConfigurations.CheckedItems.ElementAt(pc.ActualValueConfigurationIndex).ActualValue;
     73      } else if (pc != null) {
     74        do {
     75          pc.ActualValueConfigurationIndex = random.Next(pc.ValueConfigurations.Count());
     76        } while (!pc.ValueConfigurations.ItemChecked(pc.ValueConfigurations[pc.ActualValueConfigurationIndex]));
     77        pc.ActualValue = pc.ValueConfigurations[pc.ActualValueConfigurationIndex].ActualValue;
    7578      }
    7679    }
Note: See TracChangeset for help on using the changeset viewer.