1 | using HeuristicLab.Common;
|
---|
2 | using HeuristicLab.Core;
|
---|
3 | using HeuristicLab.Data;
|
---|
4 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
5 | using HeuristicLab.Operators;
|
---|
6 | using HeuristicLab.Optimization;
|
---|
7 | using HeuristicLab.Parameters;
|
---|
8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
9 |
|
---|
10 | namespace HeuristicLab.Problems.MetaOptimization {
|
---|
11 | [StorableClass]
|
---|
12 | public class UniformIntValueManipulator : SingleSuccessorOperator, IIntValueManipulator, IStochasticOperator {
|
---|
13 |
|
---|
14 | public ILookupParameter<IRandom> RandomParameter {
|
---|
15 | get { return (LookupParameter<IRandom>)Parameters["Random"]; }
|
---|
16 | }
|
---|
17 |
|
---|
18 | public UniformIntValueManipulator() { }
|
---|
19 | [StorableConstructor]
|
---|
20 | protected UniformIntValueManipulator(bool deserializing) : base(deserializing) { }
|
---|
21 | protected UniformIntValueManipulator(UniformIntValueManipulator original, Cloner cloner)
|
---|
22 | : base(original, cloner) {
|
---|
23 | }
|
---|
24 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
25 | return new UniformIntValueManipulator(this, cloner);
|
---|
26 | }
|
---|
27 |
|
---|
28 | // todo: override apply
|
---|
29 |
|
---|
30 | public void Apply(IRandom random, IntValue value, IntValueRange range) {
|
---|
31 | ApplyStatic(random, value, range);
|
---|
32 | }
|
---|
33 |
|
---|
34 | public static void ApplyStatic(IRandom random, IntValue value, IntValueRange range) {
|
---|
35 | var vector = new IntegerVector(new int[] { value.Value });
|
---|
36 | int val = value.Value;
|
---|
37 |
|
---|
38 | do {
|
---|
39 | vector[0] = val;
|
---|
40 | UniformOnePositionManipulator.Apply(random, vector, range.LowerBound, new IntValue(range.UpperBound.Value + 1));
|
---|
41 | value.Value = vector[0];
|
---|
42 | value.Value = range.ApplyStepSize(value.Value);
|
---|
43 | } while (!range.IsInRange(value.Value));
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|