Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Manipulators/UniformDoubleValueManipulator.cs @ 5111

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

#1215

  • improved exchangeability of crossover and mutation operators for parameter values
File size: 1.7 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      var vector = new RealVector(new double[] { value.Value });
39      var bounds = new DoubleMatrix(1, 2);
40      bounds[0, 0] = range.LowerBound.Value;
41      bounds[0, 1] = range.UpperBound.Value;
42      UniformOnePositionManipulator.Apply(random, vector, bounds);
43      value.Value = vector[0];
44      range.Fix(value);
45    }
46  }
47}
Note: See TracBrowser for help on using the repository browser.