Changeset 8665 for branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/Crossovers
- Timestamp:
- 09/17/12 12:31:38 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/Crossovers/ParameterConfigurationCrossover.cs
r8590 r8665 21 21 22 22 using System; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 118 119 119 120 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) 127 141 intValueCrossover.Apply(random, (IntValue)value, (IntValue)other.ActualValue.Value, (IntValueRange)range); 128 } else if (value is PercentValue) {142 else if (value is PercentValue) 129 143 doubleValueCrossover.Apply(random, (PercentValue)value, (DoubleValue)other.ActualValue.Value, ((PercentValueRange)range).AsDoubleValueRange()); 130 } else if (value is DoubleValue) {144 else if (value is DoubleValue) 131 145 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;138 146 } 139 147 }
Note: See TracChangeset
for help on using the changeset viewer.