using HeuristicLab.Core; using HeuristicLab.Data.MoveVectorData.Interfaces; using System; using System.Collections.Generic; using System.Text; namespace HeuristicLab.Data.MoveVectorData.Moves { public struct TwoPointMove : IMove { public bool Enabled { get; set; } public int pickup; public int putdown; public override string ToString() { StringBuilder sb = new StringBuilder(); if (Enabled) sb.Append("("); else sb.Append("<"); sb.Append(pickup.ToString() + "," + putdown.ToString()); if (Enabled) sb.Append(")"); else sb.Append(">"); return sb.ToString(); } public bool TryParse(string s) { bool enable = false; if (s.StartsWith("(") && s.EndsWith(")")) { enable = true; } else if (s.StartsWith("<") && s.EndsWith(">")) { enable = false; } else { return false; } string s1 = s.Substring(1, s.Length - 1); string[] valueStrings = s1.Split(','); if (valueStrings.Length != 2) { return false; } int valPickup; if (!int.TryParse(valueStrings[0], out valPickup)) { return false; } int valPutdown; if (!int.TryParse(valueStrings[1], out valPutdown)) { return false; } this.Enabled = enable; this.pickup = valPickup; this.putdown = valPutdown; return true; } public void Randomize(IRandom random, int min, int max, int step = 1) { int numbers = (int)Math.Floor((max - min) / (double)step); do { pickup = random.Next(numbers) * step + min; putdown = random.Next(numbers) * step + min; } while (pickup == putdown); Enabled = true; } public int Apply(ref StackingArea area, ref Stack inputStack, out int realMoves) { if (!Enabled) { realMoves = 0; return 0; } if (area[putdown].CurrentHeight < area[putdown].Length && area[pickup].CurrentHeight > 0) { int pick = area[pickup].Pop(); area[putdown].Push(pick); realMoves = 1; return 2; } realMoves = 0; return 1; } public IEnumerable GenerateNeighbours(IRandom random, int min, int max, int step = 1) { var moves = new List(); moves.Add(new TwoPointMove() { Enabled = !this.Enabled, putdown = this.putdown, pickup = this.pickup }); /* int numbers = (int)Math.Floor((max - min) / (double)step); int newPickup; int newPutdown; do { newPickup = random.Next(numbers) * step + min; putdown = random.Next(numbers) * step + min; } while (newPickup == putdown); do { pickup = random.Next(numbers) * step + min; newPutdown = random.Next(numbers) * step + min; } while (pickup == newPutdown); moves.Add(new TwoPointMove() { Enabled = true, putdown = newPutdown, pickup = this.pickup }); moves.Add(new TwoPointMove() { Enabled = true, putdown = this.putdown, pickup = newPickup }); */ for(int i = min; i < max; i++) { moves.Add(new TwoPointMove() { Enabled = true, putdown = i, pickup = this.pickup }); moves.Add(new TwoPointMove() { Enabled = true, putdown = this.putdown, pickup = i }); } /* if (putdown + step <= max) moves.Add(new TwoPointMove() { Enabled = true, putdown = this.putdown + step, pickup = this.pickup }); if (putdown - step >= min) moves.Add(new TwoPointMove() { Enabled = true, putdown = this.putdown - step, pickup = this.pickup }); if (pickup + step <= max) moves.Add(new TwoPointMove() { Enabled = true, putdown = this.putdown, pickup = this.pickup + step }); if (pickup - step >= min) moves.Add(new TwoPointMove() { Enabled = true, putdown = this.putdown, pickup = this.pickup - step });*/ return moves; } } }