Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Moves/AnalyticalPTSPMoveEvaluator.cs @ 17253

Last change on this file since 17253 was 17253, checked in by abeham, 5 years ago

#2521: worked on refactoring PTSP

File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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 HEAL.Attic;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.PermutationEncoding;
27using HeuristicLab.Operators;
28using HeuristicLab.Parameters;
29
30namespace HeuristicLab.Problems.PTSP {
31  [Item("AnalyticalPTSPMoveEvaluator", "A base class for operators which evaluate PTSP moves.")]
32  [StorableType("D23CCC08-AA7D-47C0-A465-FEAA16FECB80")]
33  public abstract class AnalyticalPTSPMoveEvaluator : SingleSuccessorOperator, IAnalyticalPTSPMoveEvaluator {
34
35    public override bool CanChangeName {
36      get { return false; }
37    }
38
39    public ILookupParameter<Permutation> PermutationParameter {
40      get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; }
41    }
42    public ILookupParameter<DoubleValue> QualityParameter {
43      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
44    }
45    public ILookupParameter<DoubleValue> MoveQualityParameter {
46      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
47    }
48    public ILookupParameter<IProbabilisticTSPData> ProbabilisticTSPDataParameter {
49      get { return (ILookupParameter<IProbabilisticTSPData>)Parameters["PTSP Data"]; }
50    }
51
52    [StorableConstructor]
53    protected AnalyticalPTSPMoveEvaluator(StorableConstructorFlag _) : base(_) { }
54    protected AnalyticalPTSPMoveEvaluator(AnalyticalPTSPMoveEvaluator original, Cloner cloner) : base(original, cloner) { }
55    protected AnalyticalPTSPMoveEvaluator()
56      : base() {
57      Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation."));
58      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of a TSP solution."));
59      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The evaluated quality of a move on a TSP solution."));
60      Parameters.Add(new LookupParameter<IProbabilisticTSPData>("PTSP Data", "The main parameters of the p-TSP."));
61    }
62
63    public override IOperation Apply() {
64      var permutation = PermutationParameter.ActualValue;
65      var data = ProbabilisticTSPDataParameter.ActualValue;
66
67      // here moves are not delta-evaluated
68      var newQuality = EvaluateMove(permutation, data);
69      var moveQuality = MoveQualityParameter.ActualValue;
70      if (moveQuality == null) MoveQualityParameter.ActualValue = new DoubleValue(newQuality);
71      else moveQuality.Value = newQuality;
72
73      return base.Apply();
74    }
75
76    protected abstract double EvaluateMove(Permutation tour, IProbabilisticTSPData data);
77  }
78}
Note: See TracBrowser for help on using the repository browser.