#region License Information /* HeuristicLab * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Encodings.PermutationEncoding; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.PTSP { [Item("PTSP 2.5-MoveEvaluator", "Operator that evaluates 2.5-p-opt moves of PTSP")] [StorableClass] public class PTSPTwoPointFiveMoveEvaluator : EstimatedPTSPMoveEvaluator, ITwoPointFiveMoveOperator { public ILookupParameter TwoPointFiveMoveParameter { get { return (ILookupParameter)Parameters["TwoPointFiveMove"]; } } [StorableConstructor] protected PTSPTwoPointFiveMoveEvaluator(bool deserializing) : base(deserializing) { } protected PTSPTwoPointFiveMoveEvaluator(PTSPTwoPointFiveMoveEvaluator original, Cloner cloner) : base(original, cloner) { } public PTSPTwoPointFiveMoveEvaluator() : base() { Parameters.Add(new LookupParameter("TwoPointFiveMove", "The move to evaluate.")); } public override IDeepCloneable Clone(Cloner cloner) { return new PTSPTwoPointFiveMoveEvaluator(this, cloner); } protected override double EvaluateByCoordinates(Permutation permutation, DoubleMatrix coordinates, DistanceCalculator distanceCalculator) { var move = TwoPointFiveMoveParameter.ActualValue; var realizations = RealizationsParameter.ActualValue; return EvaluateByCoordinates(permutation, coordinates, distanceCalculator, move, realizations); } public static double EvaluateByCoordinates(Permutation permutation, DoubleMatrix coordinates, DistanceCalculator distanceCalculator, TwoPointFiveMove move, ItemList realizations) { if (move.IsInvert) { return PTSPEstimatedInversionMoveEvaluator.EvaluateByCoordinates(permutation, new InversionMove(move.Index1, move.Index2, move.Permutation), coordinates, distanceCalculator, realizations); } else { return PTSPEstimatedInsertionMoveEvaluator.EvaluateByCoordinates(permutation, new TranslocationMove(move.Index1, move.Index1, move.Index2), coordinates, distanceCalculator, realizations); } } protected override double EvaluateByDistanceMatrix(Permutation permutation, DistanceMatrix distanceMatrix) { var move = TwoPointFiveMoveParameter.ActualValue; var realizations = RealizationsParameter.ActualValue; return EvaluateByDistanceMatrix(permutation, distanceMatrix, move, realizations); } public static double EvaluateByDistanceMatrix(Permutation permutation, DistanceMatrix distanceMatrix, TwoPointFiveMove move, ItemList realizations) { if (move.IsInvert) { return PTSPEstimatedInversionMoveEvaluator.EvaluateByDistanceMatrix(permutation, new InversionMove(move.Index1, move.Index2, move.Permutation), distanceMatrix, realizations); } else { return PTSPEstimatedInsertionMoveEvaluator.EvaluateByDistanceMatrix(permutation, new TranslocationMove(move.Index1, move.Index1, move.Index2), distanceMatrix, realizations); } } } }