Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Manipulators/IntValue/NormalIntValueManipulator.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.IntegerVectorEncoding;
12using HeuristicLab.Data;
13using HeuristicLab.Encodings.RealVectorEncoding;
14
15namespace HeuristicLab.Problems.MetaOptimization {
16  [StorableClass]
17  public class NormalIntValueManipulator : SingleSuccessorOperator, IIntValueManipulator, IStochasticOperator {
18
19    public ILookupParameter<IRandom> RandomParameter {
20      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
21    }
22
23    public NormalIntValueManipulator() { }
24    [StorableConstructor]
25    protected NormalIntValueManipulator(bool deserializing) : base(deserializing) { }
26    protected NormalIntValueManipulator(NormalIntValueManipulator original, Cloner cloner)
27      : base(original, cloner) {
28    }
29    public override IDeepCloneable Clone(Cloner cloner) {
30      return new NormalIntValueManipulator(this, cloner);
31    }
32
33    // todo: override apply
34   
35    public void Apply(IRandom random, IntValue value, IntValueRange range) {
36      ApplyStatic(random, value, range);
37    }
38
39    public static void ApplyStatic(IRandom random, IntValue value, IntValueRange range) {
40      bool ok = false;
41      var strategy = new RealVector(new double[] { (range.UpperBound.Value - range.LowerBound.Value) / 10 }); // todo: add strategy parameter
42      var vector = new RealVector(new double[] { value.Value });
43      int val = value.Value;
44
45      while (!ok) {
46        vector[0] = val;
47        NormalAllPositionsManipulator.Apply(random, vector, strategy);
48        value.Value = (int)vector[0];
49        value.Value = range.ApplyStepSize(value.Value);
50        ok = range.IsInRange(value.Value);
51      }
52    }
53  }
54}
Note: See TracBrowser for help on using the repository browser.