Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Moves/EstimatedPTSPMoveEvaluator.cs @ 17260

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

#2521: Worked on PTSP refactoring

File size: 3.9 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("EstimatedPTSPMoveEvaluator", "A base class for operators which evaluate PTSP moves.")]
32  [StorableType("F2F7F857-F2CD-4AB2-8656-5158BD04EFDD")]
33  public abstract class EstimatedPTSPMoveEvaluator : SingleSuccessorOperator, IEstimatedPTSPMoveEvaluator {
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<IProbabilisticTSPData> ProbabilisticTSPDataParameter {
43      get { return (ILookupParameter<IProbabilisticTSPData>)Parameters["PTSP Data"]; }
44    }
45    public ILookupParameter<ReadOnlyItemList<BoolArray>> RealizationsParameter {
46      get { return (ILookupParameter<ReadOnlyItemList<BoolArray>>)Parameters["Realizations"]; }
47    }
48    public ILookupParameter<DoubleValue> QualityParameter {
49      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
50    }
51    public ILookupParameter<DoubleValue> MoveQualityParameter {
52      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
53    }
54
55    [StorableConstructor]
56    protected EstimatedPTSPMoveEvaluator(StorableConstructorFlag _) : base(_) { }
57    protected EstimatedPTSPMoveEvaluator(EstimatedPTSPMoveEvaluator original, Cloner cloner) : base(original, cloner) { }
58    protected EstimatedPTSPMoveEvaluator()
59      : base() {
60      Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation."));
61      Parameters.Add(new LookupParameter<IProbabilisticTSPData>("PTSP Data", "The main parameters of the pTSP."));
62      Parameters.Add(new LookupParameter<ReadOnlyItemList<BoolArray>>("Realizations", "The list of samples drawn from all possible stochastic instances."));
63      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of a TSP solution."));
64      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The evaluated quality of a move on a TSP solution."));
65    }
66
67    public override IOperation Apply() {
68      var permutation = PermutationParameter.ActualValue;
69      var realizations = RealizationsParameter.ActualValue;
70      var data = ProbabilisticTSPDataParameter.ActualValue;
71      var relativeQualityDifference = EvaluateMove(permutation, data, realizations);
72      var moveQuality = MoveQualityParameter.ActualValue;
73      if (moveQuality == null) MoveQualityParameter.ActualValue = new DoubleValue(QualityParameter.ActualValue.Value + relativeQualityDifference);
74      else moveQuality.Value = QualityParameter.ActualValue.Value + relativeQualityDifference;
75      return base.Apply();
76    }
77
78    protected abstract double EvaluateMove(Permutation tour, IProbabilisticTSPData data, ReadOnlyItemList<BoolArray> realizations);
79  }
80}
Note: See TracBrowser for help on using the repository browser.