1 | using HeuristicLab.Common;
|
---|
2 | using HeuristicLab.Core;
|
---|
3 | using HeuristicLab.Data;
|
---|
4 | using HeuristicLab.Data.MoveVectorData;
|
---|
5 | using HeuristicLab.Data.MoveVectorData.Moves;
|
---|
6 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
7 | using System;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Encodings.MoveVectorEncoding.Manipulators
|
---|
10 | {
|
---|
11 | [Item("SingleMoveManipulator", " Uniformly distributed change of a single position of a move.")]
|
---|
12 | [StorableClass]
|
---|
13 | public class SingleMoveManipulator : BoundedMoveVectorManipulator
|
---|
14 | {
|
---|
15 |
|
---|
16 | [StorableConstructor]
|
---|
17 | protected SingleMoveManipulator(bool deserializing) : base(deserializing) { }
|
---|
18 | protected SingleMoveManipulator(SingleMoveManipulator original, Cloner cloner) : base(original, cloner) { }
|
---|
19 |
|
---|
20 | public SingleMoveManipulator() : base() { }
|
---|
21 |
|
---|
22 | public override IDeepCloneable Clone(Cloner cloner)
|
---|
23 | {
|
---|
24 | return new SingleMoveManipulator(this, cloner);
|
---|
25 | }
|
---|
26 |
|
---|
27 | public static void Apply(IRandom random, MoveVector moves, IntMatrix bounds)
|
---|
28 | {
|
---|
29 | Manipulate(random, moves, bounds, random.Next(moves.Length));
|
---|
30 | }
|
---|
31 |
|
---|
32 | public static void Manipulate(IRandom random, MoveVector moves, IntMatrix bounds, int index)
|
---|
33 | {
|
---|
34 | if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("SingleMoveManipulator: Invalid bounds specified", "bounds");
|
---|
35 | int min = bounds[index % bounds.Rows, 0], max = bounds[index % bounds.Rows, 1], step = 1;
|
---|
36 | if (bounds.Columns > 2) step = bounds[index % bounds.Rows, 2];
|
---|
37 |
|
---|
38 | moves[index].Randomize(random, min, max, step);
|
---|
39 | }
|
---|
40 |
|
---|
41 | protected override void ManipulateBounded(IRandom random, MoveVector moves, IntMatrix bounds)
|
---|
42 | {
|
---|
43 | if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("SingleMoveManipulator: Parameter " + BoundsParameter.ActualName + " could not be found.");
|
---|
44 | Apply(random, moves, bounds);
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|