1 | using HEAL.Attic;
|
---|
2 | using HeuristicLab.Common;
|
---|
3 | using HeuristicLab.Core;
|
---|
4 | using HeuristicLab.Data;
|
---|
5 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
6 | using HeuristicLab.Operators;
|
---|
7 | using HeuristicLab.Optimization;
|
---|
8 | using HeuristicLab.Parameters;
|
---|
9 |
|
---|
10 | namespace HeuristicLab.Problems.TravelingSalesman {
|
---|
11 | [StorableType("17477ad2-2c84-4b02-b5ac-f35ef6cc667f")]
|
---|
12 | public interface ITSPMoveEvaluator : IOperator, ISingleObjectiveMoveEvaluator, IMoveOperator {
|
---|
13 | ILookupParameter<Permutation> TSPTourParameter { get; }
|
---|
14 | ILookupParameter<ITSPData> TSPDataParameter { get; }
|
---|
15 | ILookupParameter<DoubleValue> TourLengthParameter { get; }
|
---|
16 | ILookupParameter<DoubleValue> TourLengthWithMoveParameter { get; }
|
---|
17 | }
|
---|
18 |
|
---|
19 | [Item("TSP Move Evaluator", "Base class for all move evaluators of the TSP.")]
|
---|
20 | [StorableType("44af3845-ccdf-4014-805a-5878c64f67f5")]
|
---|
21 | public abstract class TSPMoveEvaluator : SingleSuccessorOperator, ITSPMoveEvaluator {
|
---|
22 | [Storable] public ILookupParameter<Permutation> TSPTourParameter { get; private set; }
|
---|
23 | [Storable] public ILookupParameter<ITSPData> TSPDataParameter { get; private set; }
|
---|
24 | [Storable] public ILookupParameter<DoubleValue> TourLengthParameter { get; private set; }
|
---|
25 | [Storable] public ILookupParameter<DoubleValue> TourLengthWithMoveParameter { get; private set; }
|
---|
26 |
|
---|
27 | ILookupParameter<DoubleValue> ISingleObjectiveMoveEvaluator.QualityParameter => TourLengthParameter;
|
---|
28 | ILookupParameter<DoubleValue> ISingleObjectiveMoveEvaluator.MoveQualityParameter => TourLengthWithMoveParameter;
|
---|
29 |
|
---|
30 | [StorableConstructor]
|
---|
31 | protected TSPMoveEvaluator(StorableConstructorFlag _) : base(_) { }
|
---|
32 | protected TSPMoveEvaluator(TSPMoveEvaluator original, Cloner cloner)
|
---|
33 | : base(original, cloner) {
|
---|
34 | TSPTourParameter = cloner.Clone(original.TSPTourParameter);
|
---|
35 | TSPDataParameter = cloner.Clone(original.TSPDataParameter);
|
---|
36 | TourLengthParameter = cloner.Clone(original.TourLengthParameter);
|
---|
37 | TourLengthWithMoveParameter = cloner.Clone(original.TourLengthWithMoveParameter);
|
---|
38 | }
|
---|
39 | public TSPMoveEvaluator() {
|
---|
40 | Parameters.Add(TSPTourParameter = new LookupParameter<Permutation>("TSPTour", "The tour that describes a solution to the TSP."));
|
---|
41 | Parameters.Add(TSPDataParameter = new LookupParameter<ITSPData>("TSPData", "The main parameters of the TSP."));
|
---|
42 | Parameters.Add(TourLengthParameter = new LookupParameter<DoubleValue>("TourLength", "The length of a TSP tour."));
|
---|
43 | Parameters.Add(TourLengthWithMoveParameter = new LookupParameter<DoubleValue>("TourLengthWithMove", "The length of the TSP tour if the move was applied."));
|
---|
44 | }
|
---|
45 |
|
---|
46 | public sealed override IOperation Apply() {
|
---|
47 | var tour = TSPTourParameter.ActualValue;
|
---|
48 | var tspData = TSPDataParameter.ActualValue;
|
---|
49 | var tourLength = TourLengthParameter.ActualValue.Value;
|
---|
50 | TourLengthWithMoveParameter.ActualValue = new DoubleValue(
|
---|
51 | CalculateTourLengthWithMove(tspData, tour, tourLength)
|
---|
52 | );
|
---|
53 | return base.Apply();
|
---|
54 | }
|
---|
55 |
|
---|
56 | protected abstract double CalculateTourLengthWithMove(ITSPData tspData, Permutation tspTour, double tourLength);
|
---|
57 | }
|
---|
58 | }
|
---|