Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/28/15 23:38:51 (9 years ago)
Author:
abeham
Message:

#2221:

  • Completely refactored PTSP branch
    • Added two sets of problem instances based on TSPLIB: homogeneous and heterogeneous
    • Implemented missing EvaluateByCoordinates for 1-shift moves
    • Made it clear that move evaluators are for estimated PTSP only
    • Changed parameter realization from a rather strange list of list of ints to a list of bool arrays
    • Reusing code of the 2-opt and 1-shift move evaluators in 2.5 move evaluator
    • Introducing distance calculators to properly handle the case when no distance matrix is given (previous code only worked with distance matrix and without only with euclidean distance in some settings)
    • Fixed several smaller code issues: protected, static, method parameters, copy & paste, interfaces, naming, parameters, serialization hooks, license headers, doc comments, data types
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
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
    425using HeuristicLab.Common;
    526using HeuristicLab.Core;
     27using HeuristicLab.Encodings.PermutationEncoding;
    628using HeuristicLab.Optimization;
    729using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    8 using HeuristicLab.Encodings.PermutationEncoding;
    9 using HeuristicLab.Parameters;
    10 using HeuristicLab.Operators;
    1130
    1231namespace HeuristicLab.Problems.PTSP {
    13   [Item("Exhaustive25MoveGenerator", "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.")]
    1433  [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);
    1843    }
    1944
    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    
    3145    public static TwoPointFiveMove[] Apply(Permutation permutation) {
    3246      return Generate(permutation).ToArray();
     
    3549    public static IEnumerable<TwoPointFiveMove> Generate(Permutation permutation) {
    3650      int length = permutation.Length;
    37       if (length == 1) throw new ArgumentException("Exhaustive25MoveGenerator: 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");
    3852      int totalMoves = (length) * (length - 1) / 2;
    3953
     
    4458              // doesn't make sense to inverse the whole permutation or the whole but one in case of relative undirected permutations
    4559              if (j - i >= length - 2) continue;
    46               yield return new TwoPointFiveMove(i, j,true);
     60              yield return new TwoPointFiveMove(i, j, true);
    4761              yield return new TwoPointFiveMove(i, j, false);
    4862            }
    4963          }
    5064        } 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);
    5266        }
    5367      } else {
    5468        for (int i = 0; i < length - 1; i++)
    5569          for (int j = i + 1; j < length; j++) {
    56             yield return new TwoPointFiveMove(i, j,true);
     70            yield return new TwoPointFiveMove(i, j, true);
    5771            yield return new TwoPointFiveMove(i, j, false);
    5872          }
Note: See TracChangeset for help on using the changeset viewer.