Free cookie consent management tool by TermsFeed Policy Generator

source: branches/StackingProblems/HeuristicLab.Encodings.MoveVectorEncoding/3.3/Manipulators/SingleMoveManipulator.cs @ 14278

Last change on this file since 14278 was 14278, checked in by mzehetho, 8 years ago

Initial Commit for ticket #2605

Implemented:

  • Encoding
  • Moves
  • Views
  • Blocks World Problem
  • Blocks Relocation Problem
  • Stacking Problem
File size: 2.0 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Core;
3using HeuristicLab.Data;
4using HeuristicLab.Data.MoveVectorData;
5using HeuristicLab.Data.MoveVectorData.Moves;
6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7using System;
8
9namespace 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}
Note: See TracBrowser for help on using the repository browser.