Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2605_StackingProblems/HeuristicLab.Encodings.MoveVectorEncoding/3.3/Manipulators/SingleMoveChangeManipulator.cs @ 17432

Last change on this file since 17432 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.4 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Core;
3using HeuristicLab.Data;
4using HeuristicLab.Data.MoveVectorData;
5using HeuristicLab.Data.MoveVectorData.Interfaces;
6using HeuristicLab.Data.MoveVectorData.Moves;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8using HeuristicLab.PluginInfrastructure;
9using System;
10using System.Collections.Generic;
11using System.Linq;
12
13namespace HeuristicLab.Encodings.MoveVectorEncoding.Manipulators
14{
15    [Item("SingleMoveChangeManipulator", " Uniformly distributed change of a single position of a move.")]
16    [StorableClass]
17    public class SingleMoveChangeManipulator : BoundedMoveVectorManipulator
18    {
19        [StorableConstructor]
20        protected SingleMoveChangeManipulator(bool deserializing) : base(deserializing) { }
21        protected SingleMoveChangeManipulator(SingleMoveChangeManipulator original, Cloner cloner) : base(original, cloner) { }
22
23        public SingleMoveChangeManipulator() : base() { }
24
25        public override IDeepCloneable Clone(Cloner cloner)
26        {
27            return new SingleMoveChangeManipulator(this, cloner);
28        }
29
30        public static void Apply(IRandom random, MoveVector moves, IntMatrix bounds)
31        {
32            Manipulate(random, moves, bounds, random.Next(moves.Length));
33        }
34
35        public static void Manipulate(IRandom random, MoveVector moves, IntMatrix bounds, int index)
36        {
37            if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("SingleMoveChangeManipulator: Invalid bounds specified", "bounds");
38            int min = bounds[index % bounds.Rows, 0], max = bounds[index % bounds.Rows, 1], step = 1;
39            if (bounds.Columns > 2) step = bounds[index % bounds.Rows, 2];
40
41            Type type = moves.MoveTypes[random.Next(0, moves.MoveTypes.Count)];
42            IMove move = (IMove)Activator.CreateInstance(type);
43            move.Randomize(random, min, max, step);
44            moves[index] = move;
45        }
46
47        protected override void ManipulateBounded(IRandom random, MoveVector moves, IntMatrix bounds)
48        {
49            if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("SingleMoveChangeManipulator: Parameter " + BoundsParameter.ActualName + " could not be found.");
50            Apply(random, moves, bounds);
51        }
52    }
53}
Note: See TracBrowser for help on using the repository browser.