Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Manipulators/UniformDoubleValueManipulator.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: 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 UniformDoubleValueManipulator : SingleSuccessorOperator, IDoubleValueManipulator, IStochasticOperator {
17
18    public ILookupParameter<IRandom> RandomParameter {
19      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
20    }
21
22    public UniformDoubleValueManipulator() { }
23    [StorableConstructor]
24    protected UniformDoubleValueManipulator(bool deserializing) : base(deserializing) { }
25    protected UniformDoubleValueManipulator(UniformDoubleValueManipulator original, Cloner cloner)
26      : base(original, cloner) {
27    }
28    public override IDeepCloneable Clone(Cloner cloner) {
29      return new UniformDoubleValueManipulator(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 vector = new RealVector(1);
40      var bounds = new DoubleMatrix(1, 2);
41      bounds[0, 0] = range.LowerBound.Value;
42      bounds[0, 1] = range.UpperBound.Value;
43      double val = value.Value;
44
45      while (!ok) {
46        vector[0] = val;
47        UniformOnePositionManipulator.Apply(random, vector, bounds);
48        value.Value = vector[0];
49        range.ApplyStepSize(value);
50        ok = range.IsInRange(value.Value);
51      }
52    }
53  }
54}
Note: See TracBrowser for help on using the repository browser.