#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 System;
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 Analytical 2.5-MoveEvaluator", "Operator that evaluates 2.5-p-opt moves of PTSP by a full solution evaluation.")]
[StorableClass]
public class PTSPAnalyticalTwoPointFiveMoveEvaluator : AnalyticalPTSPMoveEvaluator, ITwoPointFiveMoveOperator {
public ILookupParameter TwoPointFiveMoveParameter {
get { return (ILookupParameter)Parameters["TwoPointFiveMove"]; }
}
[StorableConstructor]
protected PTSPAnalyticalTwoPointFiveMoveEvaluator(bool deserializing) : base(deserializing) { }
protected PTSPAnalyticalTwoPointFiveMoveEvaluator(PTSPAnalyticalTwoPointFiveMoveEvaluator original, Cloner cloner) : base(original, cloner) { }
public PTSPAnalyticalTwoPointFiveMoveEvaluator()
: base() {
Parameters.Add(new LookupParameter("TwoPointFiveMove", "The move to evaluate."));
}
public override IDeepCloneable Clone(Cloner cloner) {
return new PTSPAnalyticalTwoPointFiveMoveEvaluator(this, cloner);
}
protected override double EvaluateMove(Permutation permutation, Func distance, DoubleArray probabilities) {
return EvaluateMove(permutation, TwoPointFiveMoveParameter.ActualValue, distance, probabilities);
}
public static double EvaluateMove(Permutation permutation, TwoPointFiveMove move, Func distance, DoubleArray probabilities) {
if (move.IsInvert) {
return PTSPAnalyticalInversionMoveEvaluator.EvaluateMove(permutation,
new InversionMove(move.Index1, move.Index2, move.Permutation), distance, probabilities);
} else {
return PTSPAnalyticalInsertionMoveEvaluator.EvaluateMove(permutation,
new TranslocationMove(move.Index1, move.Index1, move.Index2), distance, probabilities);
}
}
}
}