Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2521: Unified architecture

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