Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Manipulators/UniformIntValueManipulator.cs @ 5337

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

#1215

  • made all IAlgorithm types compatible to be loaded into MetaOptimization.
  • valid problem types are now automatically set
File size: 1.8 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;
13
14namespace HeuristicLab.Problems.MetaOptimization {
15  [StorableClass]
16  public class UniformIntValueManipulator : SingleSuccessorOperator, IIntValueManipulator, IStochasticOperator {
17
18    public ILookupParameter<IRandom> RandomParameter {
19      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
20    }
21
22    public UniformIntValueManipulator() { }
23    [StorableConstructor]
24    protected UniformIntValueManipulator(bool deserializing) : base(deserializing) { }
25    protected UniformIntValueManipulator(UniformIntValueManipulator original, Cloner cloner)
26      : base(original, cloner) {
27    }
28    public override IDeepCloneable Clone(Cloner cloner) {
29      return new UniformIntValueManipulator(this, cloner);
30    }
31
32    // todo: override apply
33   
34    public void Apply(IRandom random, IntValue value, IntValueRange range) {
35      ApplyStatic(random, value, range);
36    }
37
38    public static void ApplyStatic(IRandom random, IntValue value, IntValueRange range) {
39      bool ok = false;
40      var vector = new IntegerVector(new int[] { value.Value });
41      int val = value.Value;
42
43      while (!ok) {
44        vector[0] = val;
45        UniformOnePositionManipulator.Apply(random, vector, range.LowerBound, new IntValue(range.UpperBound.Value + 1));
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.