Changeset 13412 for branches/PTSP/HeuristicLab.Problems.PTSP/3.3/Moves/TwoPointFiveOpt/ExhaustiveTwoPointFiveMoveGenerator.cs
- Timestamp:
- 11/28/15 23:38:51 (9 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/PTSP/HeuristicLab.Problems.PTSP/3.3/Moves/TwoPointFiveOpt/ExhaustiveTwoPointFiveMoveGenerator.cs
r13408 r13412 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 using System.Linq; 4 25 using HeuristicLab.Common; 5 26 using HeuristicLab.Core; 27 using HeuristicLab.Encodings.PermutationEncoding; 6 28 using HeuristicLab.Optimization; 7 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 8 using HeuristicLab.Encodings.PermutationEncoding;9 using HeuristicLab.Parameters;10 using HeuristicLab.Operators;11 30 12 31 namespace HeuristicLab.Problems.PTSP { 13 [Item("Exhaustive 25MoveGenerator", "Generates all possible inversion and shift moves (2.5-opt) from a given permutation.")]32 [Item("Exhaustive 2.5-MoveGenerator", "Generates all possible inversion and shift moves (2.5-opt) from a given permutation.")] 14 33 [StorableClass] 15 class Exhaustive25MoveGenerator : TwoPointFiveMoveGenerator, IExhaustiveMoveGenerator { 16 public override bool CanChangeName { 17 get { return false; } 34 public sealed class ExhaustiveTwoPointFiveMoveGenerator : TwoPointFiveMoveGenerator, IExhaustiveMoveGenerator { 35 36 [StorableConstructor] 37 private ExhaustiveTwoPointFiveMoveGenerator(bool deserializing) : base(deserializing) { } 38 private ExhaustiveTwoPointFiveMoveGenerator(ExhaustiveTwoPointFiveMoveGenerator original, Cloner cloner) : base(original, cloner) { } 39 public ExhaustiveTwoPointFiveMoveGenerator() : base() { } 40 41 public override IDeepCloneable Clone(Cloner cloner) { 42 return new ExhaustiveTwoPointFiveMoveGenerator(this, cloner); 18 43 } 19 44 20 [StorableConstructor]21 protected Exhaustive25MoveGenerator(bool deserializing) : base(deserializing) { }22 protected Exhaustive25MoveGenerator(Exhaustive25MoveGenerator original, Cloner cloner) : base(original, cloner) { }23 public Exhaustive25MoveGenerator()24 : base() {25 }26 27 public override IDeepCloneable Clone(Cloner cloner) {28 return new Exhaustive25MoveGenerator(this, cloner);29 }30 31 45 public static TwoPointFiveMove[] Apply(Permutation permutation) { 32 46 return Generate(permutation).ToArray(); … … 35 49 public static IEnumerable<TwoPointFiveMove> Generate(Permutation permutation) { 36 50 int length = permutation.Length; 37 if (length == 1) throw new ArgumentException("Exhaustive 25MoveGenerator: There cannot be a 2.5 move given a permutation of length 1.", "permutation");51 if (length == 1) throw new ArgumentException("Exhaustive 2.5-MoveGenerator: There cannot be a 2.5 move given a permutation of length 1.", "permutation"); 38 52 int totalMoves = (length) * (length - 1) / 2; 39 53 … … 44 58 // doesn't make sense to inverse the whole permutation or the whole but one in case of relative undirected permutations 45 59 if (j - i >= length - 2) continue; 46 yield return new TwoPointFiveMove(i, j, true);60 yield return new TwoPointFiveMove(i, j, true); 47 61 yield return new TwoPointFiveMove(i, j, false); 48 62 } 49 63 } 50 64 } else { // when length is 3 or less, there's actually no difference, but for the sake of not crashing the algorithm create a dummy move 51 yield return new TwoPointFiveMove(0, 1, true);65 yield return new TwoPointFiveMove(0, 1, true); 52 66 } 53 67 } else { 54 68 for (int i = 0; i < length - 1; i++) 55 69 for (int j = i + 1; j < length; j++) { 56 yield return new TwoPointFiveMove(i, j, true);70 yield return new TwoPointFiveMove(i, j, true); 57 71 yield return new TwoPointFiveMove(i, j, false); 58 72 }
Note: See TracChangeset
for help on using the changeset viewer.