Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/Manipulators/ParameterConfigurationManipulator.cs @ 5303

Last change on this file since 5303 was 5303, checked in by cneumuel, 14 years ago

#1215

  • manipulators for one and all parameters
  • SolutionCache to avoid multiple evaluations of equal solutions
  • RunsAnalyzer which stores all base level runs
  • ItemDictionaryView for runs
File size: 4.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Operators;
6using HeuristicLab.Optimization;
7using HeuristicLab.Core;
8using HeuristicLab.Parameters;
9using HeuristicLab.Common;
10using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
11using HeuristicLab.Data;
12
13namespace HeuristicLab.Problems.MetaOptimization {
14  // todo: item name/descr...
15  [StorableClass]
16  public abstract class ParameterConfigurationManipulator : SingleSuccessorOperator, IParameterConfigurationManipulator, IStochasticOperator {
17    public override bool CanChangeName {
18      get { return false; }
19    }
20    public ILookupParameter<IRandom> RandomParameter {
21      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
22    }
23    public IValueLookupParameter<ParameterConfigurationTree> ParameterConfigurationTreeParameter {
24      get { return (IValueLookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; }
25    }
26
27    public IValueLookupParameter<IIntValueManipulator> IntValueManipulatorParameter {
28      get { return (IValueLookupParameter<IIntValueManipulator>)Parameters[MetaOptimizationProblem.IntValueManipulatorParameterName]; }
29    }
30    public IValueLookupParameter<IDoubleValueManipulator> DoubleValueManipulatorParameter {
31      get { return (IValueLookupParameter<IDoubleValueManipulator>)Parameters[MetaOptimizationProblem.DoubleValueManipulatorParameterName]; }
32    }
33
34    public ParameterConfigurationManipulator() {
35      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
36      Parameters.Add(new ValueLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "The parameter configuration which should be manipulated."));
37
38      Parameters.Add(new ValueLookupParameter<IIntValueManipulator>(MetaOptimizationProblem.IntValueManipulatorParameterName, ""));
39      Parameters.Add(new ValueLookupParameter<IDoubleValueManipulator>(MetaOptimizationProblem.DoubleValueManipulatorParameterName, ""));
40    }
41    [StorableConstructor]
42    protected ParameterConfigurationManipulator(bool deserializing) : base(deserializing) { }
43    protected ParameterConfigurationManipulator(ParameterConfigurationManipulator original, Cloner cloner)
44      : base(original, cloner) {
45    }
46
47    public override IOperation Apply() {
48      Apply(RandomParameter.ActualValue, ParameterConfigurationTreeParameter.ActualValue, IntValueManipulatorParameter.ActualValue, DoubleValueManipulatorParameter.ActualValue);
49      return base.Apply();
50    }
51
52    public static void Apply(IRandom random, IValueConfiguration configuration, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator) {
53      configuration.Mutate(random, Mutate, intValueManipulator, doubleValueManipulator);
54    }
55
56    protected static void Mutate(IRandom random, IOptimizable configuration, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator) {
57      var vc = configuration as IValueConfiguration;
58      var pc = configuration as IParameterConfiguration;
59
60      if (vc != null) {
61        var value = vc.ActualValue.Value;
62        var range = vc.RangeConstraint;
63        if (value is IntValue) {
64          intValueManipulator.Apply(random, (IntValue)value, (IntValueRange)range);
65        } else if (value is PercentValue) {
66          doubleValueManipulator.Apply(random, (PercentValue)value, ((PercentValueRange)range).AsDoubleValueRange());
67        } else if (value is DoubleValue) {
68          doubleValueManipulator.Apply(random, (DoubleValue)value, (DoubleValueRange)range);
69        }
70      } else if (pc != null) {
71        do {
72          pc.ActualValueConfigurationIndex = random.Next(pc.ValueConfigurations.Count());
73        } while (!pc.ValueConfigurations.ItemChecked(pc.ValueConfigurations[pc.ActualValueConfigurationIndex]));
74        pc.ActualValue = pc.ValueConfigurations[pc.ActualValueConfigurationIndex].ActualValue;
75      }
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.