Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringSolution.cs @ 17526

Last change on this file since 17526 was 17526, checked in by abeham, 4 years ago

#2521: Completed porting of OrienteeringProblem

  • Adapted unit tests
  • Commented non-working unit test
File size: 4.8 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 System.ComponentModel;
23using System.Drawing;
24using HEAL.Attic;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Encodings.IntegerVectorEncoding;
29using HeuristicLab.Encodings.PermutationEncoding;
30using HeuristicLab.Problems.TravelingSalesman;
31
32namespace HeuristicLab.Problems.Orienteering {
33  [Item("OrienteeringSolution", "Represents a Orienteering solution which can be visualized in the GUI.")]
34  [StorableType("BC58ED08-B9A7-40F3-B8E0-A6B33AA993F4")]
35  public sealed class OrienteeringSolution : Item, ITSPSolution {
36    public static new Image StaticItemImage {
37      get { return HeuristicLab.Common.Resources.VSImageLibrary.Image; }
38    }
39
40    [Storable] private Permutation routeAsPermutation;
41    [Storable] private IntegerVector route;
42    public IntegerVector Route {
43      get { return route; }
44      set {
45        if (route == value) return;
46        route = value;
47        routeAsPermutation = new Permutation(PermutationTypes.RelativeDirected, value);
48        OnPropertyChanged(nameof(Route));
49        OnPropertyChanged(nameof(ITSPSolution.Tour));
50      }
51    }
52    [Storable] private IOrienteeringProblemData opData;
53    public IOrienteeringProblemData OPData {
54      get { return opData; }
55      set {
56        if (opData == value) return;
57        opData = value;
58        OnPropertyChanged(nameof(OPData));
59        OnPropertyChanged(nameof(ITSPSolution.TSPData));
60      }
61    }
62    [Storable]
63    private DoubleValue quality;
64    public DoubleValue Quality {
65      get { return quality; }
66      set {
67        if (quality == value) return;
68        quality = value;
69        OnPropertyChanged(nameof(Quality));
70      }
71    }
72    [Storable]
73    private DoubleValue score;
74    public DoubleValue Score {
75      get { return score; }
76      set {
77        if (score == value) return;
78        score = value;
79        OnPropertyChanged(nameof(Score));
80      }
81    }
82    [Storable]
83    private DoubleValue travelCosts;
84    public DoubleValue TravelCosts {
85      get { return travelCosts; }
86      set {
87        if (travelCosts == value) return;
88        travelCosts = value;
89        OnPropertyChanged(nameof(TravelCosts));
90        OnPropertyChanged(nameof(ITSPSolution.TourLength));
91      }
92    }
93
94    ITSPData ITSPSolution.TSPData => OPData.RoutingData;
95    Permutation ITSPSolution.Tour => routeAsPermutation;
96    DoubleValue ITSPSolution.TourLength => TravelCosts;
97
98    [StorableConstructor]
99    private OrienteeringSolution(StorableConstructorFlag _) : base(_) { }
100    private OrienteeringSolution(OrienteeringSolution original, Cloner cloner)
101      : base(original, cloner) {
102      this.route = cloner.Clone(original.route);
103      this.routeAsPermutation = cloner.Clone(original.routeAsPermutation);
104      this.opData = cloner.Clone(original.opData);
105      this.quality = cloner.Clone(original.quality);
106      this.score = cloner.Clone(original.score);
107    }
108    public OrienteeringSolution(IntegerVector route, IOrienteeringProblemData opData, double quality, double score, double travelCosts)
109      : this(route, opData, new DoubleValue(quality), new DoubleValue(score), new DoubleValue(travelCosts)) { }
110    public OrienteeringSolution(IntegerVector route, IOrienteeringProblemData opData, DoubleValue quality = null, DoubleValue score = null, DoubleValue distance = null)
111      : base() {
112      this.route = route;
113      this.routeAsPermutation = new Permutation(PermutationTypes.RelativeDirected, route);
114      this.opData = opData;
115      this.quality = quality;
116      this.score = score;
117      this.travelCosts = distance;
118    }
119
120    public override IDeepCloneable Clone(Cloner cloner) {
121      return new OrienteeringSolution(this, cloner);
122    }
123
124    public event PropertyChangedEventHandler PropertyChanged;
125    private void OnPropertyChanged(string property) {
126      PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
127    }
128  }
129}
Note: See TracBrowser for help on using the repository browser.