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/Crossovers/ParameterConfigurationCrossover.cs

    r5207 r5277  
    5858      ParameterConfigurationTree child2 = (ParameterConfigurationTree)ParentsParameter.ActualValue[1];
    5959
    60       child1.Cross(RandomParameter.ActualValue, child2, Cross, this);
     60      child1.Cross(RandomParameter.ActualValue, child2, Cross, IntValueCrossoverParameter.ActualValue, DoubleValueCrossoverParameter.ActualValue);
    6161      this.ChildParameter.ActualValue = child1;
    6262
     
    6464    }
    6565
    66     private static void Cross(IRandom random, IOptimizable configuartion, ParameterConfigurationCrossover pccross) {
    67       if (configuartion is IValueConfiguration) {
    68         var vc = configuartion as IValueConfiguration;
     66    public static void Apply(IRandom random, IOptimizable configuartion, IOptimizable other, IIntValueCrossover intValueCrossover, IDoubleValueCrossover doubleValueCrossover) {
     67      configuartion.Cross(random, other, Cross, intValueCrossover, doubleValueCrossover);
     68    }
     69
     70    private static void Cross(IRandom random, IOptimizable configuartion, IOptimizable other, IIntValueCrossover intValueCrossover, IDoubleValueCrossover doubleValueCrossover) {
     71      var vc = configuartion as IValueConfiguration;
     72      var pc = configuartion as IParameterConfiguration;
     73      if (vc != null) {
    6974        var value = vc.ActualValue.Value;
    7075        var range = vc.RangeConstraint;
    7176
    7277        if (value is IntValue) {
    73           pccross.IntValueCrossoverParameter.ActualValue.Apply(random, (IntValue)value, (IntValueRange)range);
     78          intValueCrossover.Apply(random, (IntValue)value, (IntValue)((IValueConfiguration)other).ActualValue.Value, (IntValueRange)range);
    7479        } else if (value is PercentValue) {
    75           pccross.DoubleValueCrossoverParameter.ActualValue.Apply(random, (PercentValue)value, ((PercentValueRange)range).AsDoubleValueRange());
     80          doubleValueCrossover.Apply(random, (PercentValue)value, (DoubleValue)((IValueConfiguration)other).ActualValue.Value, ((PercentValueRange)range).AsDoubleValueRange());
    7681        } else if (value is DoubleValue) {
    77           pccross.DoubleValueCrossoverParameter.ActualValue.Apply(random, (DoubleValue)value, (DoubleValueRange)range);
     82          doubleValueCrossover.Apply(random, (DoubleValue)value, (DoubleValue)((IValueConfiguration)other).ActualValue.Value, (DoubleValueRange)range);
    7883        }
    79       } else if (configuartion is IParameterConfiguration) {
    80 
     84      } else if (pc != null) {
     85        if (random.NextDouble() > 0.5) {
     86          pc.ActualValueConfigurationIndex = ((ParameterConfiguration)other).ActualValueConfigurationIndex;
     87        }
     88        pc.ActualValue = pc.ValueConfigurations[pc.ActualValueConfigurationIndex].ActualValue;
    8189      }
    8290    }
Note: See TracChangeset for help on using the changeset viewer.