1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Operators;
|
---|
6 | using HeuristicLab.Optimization;
|
---|
7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
8 | using HeuristicLab.Core;
|
---|
9 | using HeuristicLab.Parameters;
|
---|
10 | using HeuristicLab.Common;
|
---|
11 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
12 | using HeuristicLab.Data;
|
---|
13 |
|
---|
14 | namespace 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 | } |
---|