Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Manipulators/DoubleValue/NormalDoubleValueManipulator.cs @ 6017

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

#1215

  • fixed import of existing algorithm
  • moved operators in subfolders
  • extended tests for SymbolicExpressionGrammar
File size: 1.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Operators;
6using HeuristicLab.Optimization;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8using HeuristicLab.Core;
9using HeuristicLab.Parameters;
10using HeuristicLab.Common;
11using HeuristicLab.Encodings.RealVectorEncoding;
12using HeuristicLab.Data;
13
14namespace HeuristicLab.Problems.MetaOptimization {
15  [StorableClass]
16  public class NormalDoubleValueManipulator : SingleSuccessorOperator, IDoubleValueManipulator, IStochasticOperator {
17
18    public ILookupParameter<IRandom> RandomParameter {
19      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
20    }
21
22    public NormalDoubleValueManipulator() { }
23    [StorableConstructor]
24    protected NormalDoubleValueManipulator(bool deserializing) : base(deserializing) { }
25    protected NormalDoubleValueManipulator(NormalDoubleValueManipulator original, Cloner cloner)
26      : base(original, cloner) {
27    }
28    public override IDeepCloneable Clone(Cloner cloner) {
29      return new NormalDoubleValueManipulator(this, cloner);
30    }
31   
32    // todo: override apply
33    public void Apply(IRandom random, DoubleValue value, DoubleValueRange range) {
34      ApplyStatic(random, value, range);
35    }
36
37    public static void ApplyStatic(IRandom random, DoubleValue value, DoubleValueRange range) {
38      bool ok = false;
39      var strategy = new RealVector(new double[] { (range.UpperBound.Value - range.LowerBound.Value) / 10}); // todo: add strategy parameter
40      var vector = new RealVector(1);
41      double val = value.Value;
42
43      while (!ok) {
44        vector[0] = val;
45        NormalAllPositionsManipulator.Apply(random, vector, strategy);
46        value.Value = vector[0];
47        value.Value = range.ApplyStepSize(value.Value);
48        ok = range.IsInRange(value.Value);
49      }
50    }
51  }
52}
Note: See TracBrowser for help on using the repository browser.