Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8665


Ignore:
Timestamp:
09/17/12 12:31:38 (12 years ago)
Author:
jkarder
Message:

#1853: fixed execution of crossovers and manipulators

Location:
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/Crossovers/ParameterConfigurationCrossover.cs

    r8590 r8665  
    2121
    2222using System;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    118119
    119120    public static void Cross(IRandom random, IOptimizable configuration, IOptimizable other, IIntValueCrossover intValueCrossover, IDoubleValueCrossover doubleValueCrossover) {
    120       var vc = configuration as RangeValueConfiguration;
    121       var pc = configuration as IParameterConfiguration;
    122       if (vc != null) {
    123         var value = vc.ActualValue.Value;
    124         var range = vc.RangeConstraint;
    125 
    126         if (value is IntValue) {
     121      if (configuration is ParameterizedValueConfiguration) {
     122        var configVc = (ParameterizedValueConfiguration)configuration;
     123        var otherVc = (ParameterizedValueConfiguration)other;
     124        for (int i = 0; i < configVc.ParameterConfigurations.Count; i++)
     125          Cross(random, configVc.ParameterConfigurations.ElementAt(i), otherVc.ParameterConfigurations.ElementAt(i), intValueCrossover, doubleValueCrossover);
     126      } else if (configuration is ParameterConfiguration) {
     127        var configPc = (IParameterConfiguration)configuration;
     128        if (configPc.Optimize) {
     129          var otherPc = (IParameterConfiguration)other;
     130          for (int i = 0; i < configPc.ValueConfigurations.Count; i++)
     131            if (configPc.ValueConfigurations.ItemChecked(configPc.ValueConfigurations[i]))
     132              if (configPc.ValueConfigurations[i].Optimize) Cross(random, configPc.ValueConfigurations[i], otherPc.ValueConfigurations[i], intValueCrossover, doubleValueCrossover);
     133          if (random.NextDouble() > 0.5) configPc.ActualValueConfigurationIndex = otherPc.ActualValueConfigurationIndex;
     134          configPc.ActualValue = configPc.ValueConfigurations[configPc.ActualValueConfigurationIndex].ActualValue;
     135        }
     136      } else if (configuration is RangeValueConfiguration) {
     137        var configVc = (RangeValueConfiguration)configuration;
     138        var value = configVc.ActualValue.Value;
     139        var range = configVc.RangeConstraint;
     140        if (value is IntValue)
    127141          intValueCrossover.Apply(random, (IntValue)value, (IntValue)other.ActualValue.Value, (IntValueRange)range);
    128         } else if (value is PercentValue) {
     142        else if (value is PercentValue)
    129143          doubleValueCrossover.Apply(random, (PercentValue)value, (DoubleValue)other.ActualValue.Value, ((PercentValueRange)range).AsDoubleValueRange());
    130         } else if (value is DoubleValue) {
     144        else if (value is DoubleValue)
    131145          doubleValueCrossover.Apply(random, (DoubleValue)value, (DoubleValue)other.ActualValue.Value, (DoubleValueRange)range);
    132         }
    133       } else if (pc != null) {
    134         if (random.NextDouble() > 0.5) {
    135           pc.ActualValueConfigurationIndex = ((ParameterConfiguration)other).ActualValueConfigurationIndex;
    136         }
    137         pc.ActualValue = pc.ValueConfigurations[pc.ActualValueConfigurationIndex].ActualValue;
    138146      }
    139147    }
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/Manipulators/ParameterConfigurationManipulator.cs

    r8574 r8665  
    7777
    7878    public static void Mutate(IRandom random, IOptimizable configuration, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator) {
    79       var vc = configuration as RangeValueConfiguration;
    80       var pc = configuration as IParameterConfiguration;
    81 
    82       if (vc != null) {
    83         var value = vc.ActualValue.Value;
    84         var range = vc.RangeConstraint;
    85         if (value is IntValue) {
     79      if (configuration is ParameterizedValueConfiguration) {
     80        var configVc = (ParameterizedValueConfiguration)configuration;
     81        for (int i = 0; i < configVc.ParameterConfigurations.Count; i++)
     82          Mutate(random, configVc.ParameterConfigurations.ElementAt(i), intValueManipulator, doubleValueManipulator);
     83      } else if (configuration is ParameterConfiguration) {
     84        var configPc = (IParameterConfiguration)configuration;
     85        if (configPc.Optimize) {
     86          foreach (var vc in configPc.ValueConfigurations)
     87            if (configPc.ValueConfigurations.ItemChecked(vc))
     88              if (vc.Optimize) Mutate(random, vc, intValueManipulator, doubleValueManipulator);
     89          do configPc.ActualValueConfigurationIndex = random.Next(configPc.ValueConfigurations.Count);
     90          while (!configPc.ValueConfigurations.ItemChecked(configPc.ValueConfigurations[configPc.ActualValueConfigurationIndex]));
     91          configPc.ActualValue = configPc.ValueConfigurations[configPc.ActualValueConfigurationIndex].ActualValue;
     92        }
     93      } else if (configuration is RangeValueConfiguration) {
     94        var configVc = (RangeValueConfiguration)configuration;
     95        var value = configVc.ActualValue.Value;
     96        var range = configVc.RangeConstraint;
     97        if (value is IntValue)
    8698          intValueManipulator.Apply(random, (IntValue)value, (IntValueRange)range);
    87         } else if (value is PercentValue) {
     99        else if (value is PercentValue)
    88100          doubleValueManipulator.Apply(random, (PercentValue)value, ((PercentValueRange)range).AsDoubleValueRange());
    89         } else if (value is DoubleValue) {
     101        else if (value is DoubleValue)
    90102          doubleValueManipulator.Apply(random, (DoubleValue)value, (DoubleValueRange)range);
    91         }
    92       } else if (pc != null) {
    93         do {
    94           pc.ActualValueConfigurationIndex = random.Next(pc.ValueConfigurations.Count());
    95         } while (!pc.ValueConfigurations.ItemChecked(pc.ValueConfigurations[pc.ActualValueConfigurationIndex]));
    96         pc.ActualValue = pc.ValueConfigurations[pc.ActualValueConfigurationIndex].ActualValue;
    97103      }
    98104    }
Note: See TracChangeset for help on using the changeset viewer.