[5653] | 1 | using System.Linq;
|
---|
| 2 | using HeuristicLab.Common;
|
---|
| 3 | using HeuristicLab.Core;
|
---|
| 4 | using HeuristicLab.Data;
|
---|
[5112] | 5 | using HeuristicLab.Operators;
|
---|
| 6 | using HeuristicLab.Optimization;
|
---|
| 7 | using HeuristicLab.Parameters;
|
---|
[16574] | 8 | using HEAL.Attic;
|
---|
[5112] | 9 |
|
---|
| 10 | namespace HeuristicLab.Problems.MetaOptimization {
|
---|
| 11 | // todo: item name/descr...
|
---|
[16574] | 12 | [StorableType("ACFF1652-4E03-4A30-9A93-331F32FC13EF")]
|
---|
[5303] | 13 | public abstract class ParameterConfigurationManipulator : SingleSuccessorOperator, IParameterConfigurationManipulator, IStochasticOperator {
|
---|
[5112] | 14 | public override bool CanChangeName {
|
---|
| 15 | get { return false; }
|
---|
| 16 | }
|
---|
| 17 | public ILookupParameter<IRandom> RandomParameter {
|
---|
| 18 | get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
|
---|
| 19 | }
|
---|
| 20 | public IValueLookupParameter<ParameterConfigurationTree> ParameterConfigurationTreeParameter {
|
---|
| 21 | get { return (IValueLookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; }
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | public IValueLookupParameter<IIntValueManipulator> IntValueManipulatorParameter {
|
---|
| 25 | get { return (IValueLookupParameter<IIntValueManipulator>)Parameters[MetaOptimizationProblem.IntValueManipulatorParameterName]; }
|
---|
| 26 | }
|
---|
| 27 | public IValueLookupParameter<IDoubleValueManipulator> DoubleValueManipulatorParameter {
|
---|
| 28 | get { return (IValueLookupParameter<IDoubleValueManipulator>)Parameters[MetaOptimizationProblem.DoubleValueManipulatorParameterName]; }
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | public ParameterConfigurationManipulator() {
|
---|
| 32 | Parameters.Add(new ValueLookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
|
---|
| 33 | Parameters.Add(new ValueLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "The parameter configuration which should be manipulated."));
|
---|
| 34 |
|
---|
| 35 | Parameters.Add(new ValueLookupParameter<IIntValueManipulator>(MetaOptimizationProblem.IntValueManipulatorParameterName, ""));
|
---|
| 36 | Parameters.Add(new ValueLookupParameter<IDoubleValueManipulator>(MetaOptimizationProblem.DoubleValueManipulatorParameterName, ""));
|
---|
| 37 | }
|
---|
| 38 | [StorableConstructor]
|
---|
[16574] | 39 | protected ParameterConfigurationManipulator(StorableConstructorFlag _) : base(_) { }
|
---|
[5112] | 40 | protected ParameterConfigurationManipulator(ParameterConfigurationManipulator original, Cloner cloner)
|
---|
| 41 | : base(original, cloner) {
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[5303] | 44 | public override IOperation Apply() {
|
---|
[5277] | 45 | Apply(RandomParameter.ActualValue, ParameterConfigurationTreeParameter.ActualValue, IntValueManipulatorParameter.ActualValue, DoubleValueManipulatorParameter.ActualValue);
|
---|
[5112] | 46 | return base.Apply();
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[5277] | 49 | public static void Apply(IRandom random, IValueConfiguration configuration, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator) {
|
---|
| 50 | configuration.Mutate(random, Mutate, intValueManipulator, doubleValueManipulator);
|
---|
[5112] | 51 | }
|
---|
| 52 |
|
---|
[6017] | 53 | public static void Mutate(IRandom random, IOptimizable configuration, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator) {
|
---|
[5653] | 54 | var vc = configuration as RangeValueConfiguration;
|
---|
[5277] | 55 | var pc = configuration as IParameterConfiguration;
|
---|
| 56 |
|
---|
| 57 | if (vc != null) {
|
---|
[5112] | 58 | var value = vc.ActualValue.Value;
|
---|
| 59 | var range = vc.RangeConstraint;
|
---|
| 60 | if (value is IntValue) {
|
---|
[5277] | 61 | intValueManipulator.Apply(random, (IntValue)value, (IntValueRange)range);
|
---|
[5112] | 62 | } else if (value is PercentValue) {
|
---|
[5277] | 63 | doubleValueManipulator.Apply(random, (PercentValue)value, ((PercentValueRange)range).AsDoubleValueRange());
|
---|
[5112] | 64 | } else if (value is DoubleValue) {
|
---|
[5277] | 65 | doubleValueManipulator.Apply(random, (DoubleValue)value, (DoubleValueRange)range);
|
---|
[5112] | 66 | }
|
---|
[5277] | 67 | } else if (pc != null) {
|
---|
| 68 | do {
|
---|
| 69 | pc.ActualValueConfigurationIndex = random.Next(pc.ValueConfigurations.Count());
|
---|
| 70 | } while (!pc.ValueConfigurations.ItemChecked(pc.ValueConfigurations[pc.ActualValueConfigurationIndex]));
|
---|
| 71 | pc.ActualValue = pc.ValueConfigurations[pc.ActualValueConfigurationIndex].ActualValue;
|
---|
[5112] | 72 | }
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | } |
---|