Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/Crossovers/ParameterConfigurationCrossover.cs @ 5207

Last change on this file since 5207 was 5207, checked in by cneumuel, 13 years ago

#1215

  • lots of memory-consumption improvements
  • validValues -> validTypes (this saves memory!)
  • changed manipulators; modifications are less significant, out-of-bound-values are resampled instead of set to lower or upper bound
  • changed the way a base-level algorithm gets executed -> introduced AlgorithmExecutor
File size: 4.6 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Core;
3using HeuristicLab.Data;
4using HeuristicLab.Encodings.IntegerVectorEncoding;
5using HeuristicLab.Encodings.RealVectorEncoding;
6using HeuristicLab.Operators;
7using HeuristicLab.Optimization;
8using HeuristicLab.Parameters;
9using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
10using System;
11
12namespace HeuristicLab.Problems.MetaOptimization {
13  /// <summary>
14  ///
15  /// </summary>
16  [Item("ParameterConfigurationCrossover", "TODO")]
17  [StorableClass]
18  public class ParameterConfigurationCrossover : SingleSuccessorOperator, IParameterConfigurationOperator, IParameterConfigurationCrossover {
19    public override bool CanChangeName {
20      get { return false; }
21    }
22
23    public ILookupParameter<IRandom> RandomParameter {
24      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
25    }
26    public ILookupParameter<ItemArray<ParameterConfigurationTree>> ParentsParameter {
27      get { return (ScopeTreeLookupParameter<ParameterConfigurationTree>)Parameters["Parents"]; }
28    }
29    public ILookupParameter<ParameterConfigurationTree> ChildParameter {
30      get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["Child"]; }
31    }
32
33    public IValueLookupParameter<IIntValueCrossover> IntValueCrossoverParameter {
34      get { return (IValueLookupParameter<IIntValueCrossover>)Parameters[MetaOptimizationProblem.IntValueCrossoverParameterName]; }
35    }
36    public IValueLookupParameter<IDoubleValueCrossover> DoubleValueCrossoverParameter {
37      get { return (IValueLookupParameter<IDoubleValueCrossover>)Parameters[MetaOptimizationProblem.DoubleValueCrossoverParameterName]; }
38    }
39
40    [StorableConstructor]
41    protected ParameterConfigurationCrossover(bool deserializing) : base(deserializing) { }
42    protected ParameterConfigurationCrossover(ParameterConfigurationCrossover original, Cloner cloner) : base(original, cloner) { }
43    public ParameterConfigurationCrossover()
44      : base() {
45      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic crossover operators."));
46      Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("Parents", "The parent vectors which should be crossed."));
47      Parameters.Add(new LookupParameter<ParameterConfigurationTree>("Child", "The child vector resulting from the crossover."));
48
49      Parameters.Add(new ValueLookupParameter<IIntValueCrossover>(MetaOptimizationProblem.IntValueCrossoverParameterName, ""));
50      Parameters.Add(new ValueLookupParameter<IDoubleValueCrossover>(MetaOptimizationProblem.DoubleValueCrossoverParameterName, ""));
51    }
52    public override IDeepCloneable Clone(Cloner cloner) {
53      return new ParameterConfigurationCrossover(this, cloner);
54    }
55
56    public override IOperation Apply() {
57      ParameterConfigurationTree child1 = (ParameterConfigurationTree)ParentsParameter.ActualValue[0].Clone();
58      ParameterConfigurationTree child2 = (ParameterConfigurationTree)ParentsParameter.ActualValue[1];
59
60      child1.Cross(RandomParameter.ActualValue, child2, Cross, this);
61      this.ChildParameter.ActualValue = child1;
62
63      return base.Apply();
64    }
65
66    private static void Cross(IRandom random, IOptimizable configuartion, ParameterConfigurationCrossover pccross) {
67      if (configuartion is IValueConfiguration) {
68        var vc = configuartion as IValueConfiguration;
69        var value = vc.ActualValue.Value;
70        var range = vc.RangeConstraint;
71
72        if (value is IntValue) {
73          pccross.IntValueCrossoverParameter.ActualValue.Apply(random, (IntValue)value, (IntValueRange)range);
74        } else if (value is PercentValue) {
75          pccross.DoubleValueCrossoverParameter.ActualValue.Apply(random, (PercentValue)value, ((PercentValueRange)range).AsDoubleValueRange());
76        } else if (value is DoubleValue) {
77          pccross.DoubleValueCrossoverParameter.ActualValue.Apply(random, (DoubleValue)value, (DoubleValueRange)range);
78        }
79      } else if (configuartion is IParameterConfiguration) {
80
81      }
82    }
83
84    private IntValue CrossInteger(IParameterConfiguration parameter1, IParameterConfiguration parameter2) {
85      IntegerVector integerChild = HeuristicLab.Encodings.IntegerVectorEncoding.DiscreteCrossover.Apply(
86        RandomParameter.ActualValue,
87        new IntegerVector(new IntArray(new int[] { ((IntValue)parameter1.ActualValue.Value).Value })),
88        new IntegerVector(new IntArray(new int[] { ((IntValue)parameter2.ActualValue.Value).Value })));
89      return new IntValue(integerChild[0]);
90    }
91
92  }
93}
Note: See TracBrowser for help on using the repository browser.