Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.TravelingSalesman/3.3/MoveEvaluators/ThreeOpt/TSPTranslocationMoveDistanceMatrixEvaluator.cs @ 17564

Last change on this file since 17564 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 3.7 KB
RevLine 
[3209]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3209]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
[12978]22using System;
[4722]23using HeuristicLab.Common;
[3209]24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.PermutationEncoding;
27using HeuristicLab.Parameters;
[16565]28using HEAL.Attic;
[3209]29
30namespace HeuristicLab.Problems.TravelingSalesman {
31  /// <summary>
[3232]32  /// An operator to evaluate inversion moves (2-opt).
[3209]33  /// </summary>
[12978]34  [Item("TSPTranslocationMoveDistanceMatrixEvaluator", "Evaluates a translocation or insertion move (3-opt).")]
[16565]35  [StorableType("895EF1F3-6FE0-43C0-A6D4-7EEAB7B06841")]
[12978]36  public class TSPTranslocationMoveDistanceMatrixEvaluator : TSPMoveEvaluator, IPermutationTranslocationMoveOperator {
37    public override Type EvaluatorType {
38      get { return typeof(TSPDistanceMatrixEvaluator); }
[3209]39    }
40
[12978]41    public ILookupParameter<Permutation> PermutationParameter {
42      get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; }
43    }
44    public ILookupParameter<DistanceMatrix> DistanceMatrixParameter {
45      get { return (ILookupParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; }
46    }
47    public ILookupParameter<TranslocationMove> TranslocationMoveParameter {
48      get { return (ILookupParameter<TranslocationMove>)Parameters["TranslocationMove"]; }
49    }
50
[4722]51    [StorableConstructor]
[16565]52    protected TSPTranslocationMoveDistanceMatrixEvaluator(StorableConstructorFlag _) : base(_) { }
[12978]53    protected TSPTranslocationMoveDistanceMatrixEvaluator(TSPTranslocationMoveDistanceMatrixEvaluator original, Cloner cloner) : base(original, cloner) { }
54    public TSPTranslocationMoveDistanceMatrixEvaluator()
[3209]55      : base() {
[12978]56      Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation."));
57      Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities."));
58      Parameters.Add(new LookupParameter<TranslocationMove>("TranslocationMove", "The move to evaluate."));
[3209]59    }
60
[12978]61    public override IDeepCloneable Clone(Cloner cloner) {
62      return new TSPTranslocationMoveDistanceMatrixEvaluator(this, cloner);
[3209]63    }
64
[12978]65    public override IOperation Apply() {
66      var permutation = PermutationParameter.ActualValue;
67      double relativeQualityDifference = 0;
68      var distanceMatrix = DistanceMatrixParameter.ActualValue;
69      if (distanceMatrix == null) throw new InvalidOperationException("The distance matrix is not given.");
70      var move = TranslocationMoveParameter.ActualValue;
71      relativeQualityDifference = TSPTranslocationMovePathEvaluator.EvaluateByDistanceMatrix(permutation, move, distanceMatrix);
[7743]72
[12978]73      var moveQuality = MoveQualityParameter.ActualValue;
74      if (moveQuality == null) MoveQualityParameter.ActualValue = new DoubleValue(QualityParameter.ActualValue.Value + relativeQualityDifference);
75      else moveQuality.Value = QualityParameter.ActualValue.Value + relativeQualityDifference;
76      return base.Apply();
[7743]77    }
[3209]78  }
79}
Note: See TracBrowser for help on using the repository browser.