[12721] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[12721] | 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 |
|
---|
[11190] | 22 | using System;
|
---|
| 23 | using System.Drawing;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
| 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.Orienteering {
|
---|
| 31 | [Item("OrienteeringSolution", "Represents a Orienteering solution which can be visualized in the GUI.")]
|
---|
| 32 | [StorableClass]
|
---|
[11307] | 33 | public sealed class OrienteeringSolution : Item {
|
---|
[11190] | 34 | public static new Image StaticItemImage {
|
---|
| 35 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Image; }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | [Storable]
|
---|
| 39 | private IntegerVector integerVector;
|
---|
| 40 | public IntegerVector IntegerVector {
|
---|
| 41 | get { return integerVector; }
|
---|
| 42 | set {
|
---|
| 43 | if (integerVector != value) {
|
---|
| 44 | if (integerVector != null) DeregisterIntegerVectorEvents();
|
---|
| 45 | integerVector = value;
|
---|
| 46 | if (integerVector != null) RegisterIntegerVectorEvents();
|
---|
| 47 | OnIntegerVectorChanged();
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | [Storable]
|
---|
| 52 | private DoubleMatrix coordinates;
|
---|
| 53 | public DoubleMatrix Coordinates {
|
---|
| 54 | get { return coordinates; }
|
---|
| 55 | set {
|
---|
| 56 | if (coordinates != value) {
|
---|
| 57 | if (coordinates != null) DeregisterCoordinatesEvents();
|
---|
| 58 | coordinates = value;
|
---|
| 59 | if (coordinates != null) RegisterCoordinatesEvents();
|
---|
| 60 | OnCoordinatesChanged();
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 | [Storable]
|
---|
[11265] | 65 | private IntValue startingPoint;
|
---|
| 66 | public IntValue StartingPoint {
|
---|
| 67 | get { return startingPoint; }
|
---|
| 68 | set {
|
---|
| 69 | if (startingPoint != value) {
|
---|
| 70 | if (startingPoint != null) DeregisterStartingPointEvents();
|
---|
| 71 | startingPoint = value;
|
---|
| 72 | if (startingPoint != null) RegisterStartingPointEvents();
|
---|
| 73 | OnStartingPointChanged();
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | [Storable]
|
---|
[11319] | 78 | private IntValue terminalPoint;
|
---|
| 79 | public IntValue TerminalPoint {
|
---|
| 80 | get { return terminalPoint; }
|
---|
[11265] | 81 | set {
|
---|
[11319] | 82 | if (terminalPoint != value) {
|
---|
| 83 | if (terminalPoint != null) DeregisterTerminalPointEvents();
|
---|
| 84 | terminalPoint = value;
|
---|
| 85 | if (terminalPoint != null) RegisterTerminalPointEvents();
|
---|
| 86 | OnTerminalPointChanged();
|
---|
[11265] | 87 | }
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 | [Storable]
|
---|
[11240] | 91 | private DoubleArray scores;
|
---|
| 92 | public DoubleArray Scores {
|
---|
| 93 | get { return scores; }
|
---|
| 94 | set {
|
---|
| 95 | if (scores != value) {
|
---|
| 96 | if (scores != null) DeregisterScoresEvents();
|
---|
| 97 | scores = value;
|
---|
| 98 | if (scores != null) RegisterScoresEvents();
|
---|
| 99 | OnScoresChanged();
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | [Storable]
|
---|
[11190] | 104 | private DoubleValue quality;
|
---|
| 105 | public DoubleValue Quality {
|
---|
| 106 | get { return quality; }
|
---|
| 107 | set {
|
---|
| 108 | if (quality != value) {
|
---|
| 109 | if (quality != null) DeregisterQualityEvents();
|
---|
| 110 | quality = value;
|
---|
| 111 | if (quality != null) RegisterQualityEvents();
|
---|
| 112 | OnQualityChanged();
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
[11311] | 116 | [Storable]
|
---|
| 117 | private DoubleValue penalty;
|
---|
| 118 | public DoubleValue Penalty {
|
---|
| 119 | get { return penalty; }
|
---|
| 120 | set {
|
---|
| 121 | if (penalty != value) {
|
---|
| 122 | if (penalty != null) DeregisterPenaltyEvents();
|
---|
| 123 | penalty = value;
|
---|
| 124 | if (penalty != null) RegisterPenaltyEvents();
|
---|
| 125 | OnPenaltyChanged();
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
[11327] | 129 | [Storable]
|
---|
| 130 | private DoubleValue distance;
|
---|
| 131 | public DoubleValue Distance {
|
---|
| 132 | get { return distance; }
|
---|
| 133 | set {
|
---|
| 134 | if (distance != value) {
|
---|
| 135 | if (distance != null) DeregisterDistanceEvents();
|
---|
| 136 | distance = value;
|
---|
| 137 | if (distance != null) RegisterDistanceEvents();
|
---|
| 138 | OnDistanceChanged();
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
[11190] | 142 |
|
---|
| 143 | [StorableConstructor]
|
---|
[11307] | 144 | private OrienteeringSolution(bool deserializing)
|
---|
| 145 | : base(deserializing) { }
|
---|
[11190] | 146 | private OrienteeringSolution(OrienteeringSolution original, Cloner cloner)
|
---|
| 147 | : base(original, cloner) {
|
---|
| 148 | this.integerVector = cloner.Clone(original.integerVector);
|
---|
| 149 | this.coordinates = cloner.Clone(original.coordinates);
|
---|
| 150 | this.quality = cloner.Clone(original.quality);
|
---|
[11311] | 151 | this.penalty = cloner.Clone(original.penalty);
|
---|
[11190] | 152 | Initialize();
|
---|
| 153 | }
|
---|
[11319] | 154 | public OrienteeringSolution(IntegerVector integerVector, DoubleMatrix coordinates, IntValue startingPoint, IntValue terminalPoint,
|
---|
[11327] | 155 | DoubleArray scores, DoubleValue quality = null, DoubleValue penalty = null, DoubleValue distance = null)
|
---|
[11190] | 156 | : base() {
|
---|
| 157 | this.integerVector = integerVector;
|
---|
| 158 | this.coordinates = coordinates;
|
---|
[11265] | 159 | this.startingPoint = startingPoint;
|
---|
[11319] | 160 | this.terminalPoint = terminalPoint;
|
---|
[11240] | 161 | this.scores = scores;
|
---|
[11190] | 162 | this.quality = quality;
|
---|
[11311] | 163 | this.penalty = penalty;
|
---|
[11327] | 164 | this.distance = distance;
|
---|
[11190] | 165 | Initialize();
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 169 | return new OrienteeringSolution(this, cloner);
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 173 | private void AfterDeserialization() {
|
---|
| 174 | Initialize();
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | private void Initialize() {
|
---|
| 178 | if (integerVector != null) RegisterIntegerVectorEvents();
|
---|
| 179 | if (coordinates != null) RegisterCoordinatesEvents();
|
---|
[11265] | 180 | if (startingPoint != null) RegisterStartingPointEvents();
|
---|
[11319] | 181 | if (terminalPoint != null) RegisterTerminalPointEvents();
|
---|
[11240] | 182 | if (scores != null) RegisterScoresEvents();
|
---|
[11190] | 183 | if (quality != null) RegisterQualityEvents();
|
---|
[11311] | 184 | if (penalty != null) RegisterPenaltyEvents();
|
---|
[11327] | 185 | if (distance != null) RegisterDistanceEvents();
|
---|
[11190] | 186 | }
|
---|
| 187 |
|
---|
| 188 | #region Events
|
---|
| 189 | public event EventHandler IntegerVectorChanged;
|
---|
| 190 | private void OnIntegerVectorChanged() {
|
---|
| 191 | var changed = IntegerVectorChanged;
|
---|
| 192 | if (changed != null)
|
---|
| 193 | changed(this, EventArgs.Empty);
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | public event EventHandler CoordinatesChanged;
|
---|
| 197 | private void OnCoordinatesChanged() {
|
---|
| 198 | var changed = CoordinatesChanged;
|
---|
| 199 | if (changed != null)
|
---|
| 200 | changed(this, EventArgs.Empty);
|
---|
| 201 | }
|
---|
| 202 |
|
---|
[11265] | 203 | public event EventHandler StartingPointChanged;
|
---|
| 204 | private void OnStartingPointChanged() {
|
---|
| 205 | var changed = StartingPointChanged;
|
---|
| 206 | if (changed != null)
|
---|
| 207 | changed(this, EventArgs.Empty);
|
---|
| 208 | }
|
---|
| 209 |
|
---|
[11319] | 210 | public event EventHandler TerminalPointChanged;
|
---|
| 211 | private void OnTerminalPointChanged() {
|
---|
| 212 | var changed = TerminalPointChanged;
|
---|
[11265] | 213 | if (changed != null)
|
---|
| 214 | changed(this, EventArgs.Empty);
|
---|
| 215 | }
|
---|
| 216 |
|
---|
[11240] | 217 | public event EventHandler ScoresChanged;
|
---|
| 218 | private void OnScoresChanged() {
|
---|
| 219 | var changed = ScoresChanged;
|
---|
| 220 | if (changed != null)
|
---|
| 221 | changed(this, EventArgs.Empty);
|
---|
| 222 | }
|
---|
[11190] | 223 |
|
---|
| 224 | public event EventHandler QualityChanged;
|
---|
| 225 | private void OnQualityChanged() {
|
---|
| 226 | var changed = QualityChanged;
|
---|
| 227 | if (changed != null)
|
---|
| 228 | changed(this, EventArgs.Empty);
|
---|
| 229 | }
|
---|
| 230 |
|
---|
[11311] | 231 | public event EventHandler PenaltyChanged;
|
---|
| 232 | private void OnPenaltyChanged() {
|
---|
| 233 | var changed = PenaltyChanged;
|
---|
| 234 | if (changed != null)
|
---|
| 235 | changed(this, EventArgs.Empty);
|
---|
| 236 | }
|
---|
| 237 |
|
---|
[11327] | 238 | public event EventHandler DistanceChanged;
|
---|
| 239 | private void OnDistanceChanged() {
|
---|
| 240 | var changed = DistanceChanged;
|
---|
| 241 | if (changed != null)
|
---|
| 242 | changed(this, EventArgs.Empty);
|
---|
| 243 | }
|
---|
| 244 |
|
---|
[11190] | 245 | private void RegisterIntegerVectorEvents() {
|
---|
| 246 | IntegerVector.ItemChanged += new EventHandler<EventArgs<int>>(IntegerVector_ItemChanged);
|
---|
| 247 | IntegerVector.Reset += new EventHandler(IntegerVector_Reset);
|
---|
| 248 | }
|
---|
| 249 | private void DeregisterIntegerVectorEvents() {
|
---|
| 250 | IntegerVector.ItemChanged -= new EventHandler<EventArgs<int>>(IntegerVector_ItemChanged);
|
---|
| 251 | IntegerVector.Reset -= new EventHandler(IntegerVector_Reset);
|
---|
| 252 | }
|
---|
| 253 | private void RegisterCoordinatesEvents() {
|
---|
| 254 | Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
|
---|
| 255 | Coordinates.Reset += new EventHandler(Coordinates_Reset);
|
---|
| 256 | }
|
---|
| 257 | private void DeregisterCoordinatesEvents() {
|
---|
| 258 | Coordinates.ItemChanged -= new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
|
---|
| 259 | Coordinates.Reset -= new EventHandler(Coordinates_Reset);
|
---|
| 260 | }
|
---|
[11265] | 261 | private void RegisterStartingPointEvents() {
|
---|
| 262 | StartingPoint.ValueChanged += new EventHandler(StartingPoint_ValueChanged);
|
---|
| 263 | }
|
---|
| 264 | private void DeregisterStartingPointEvents() {
|
---|
| 265 | StartingPoint.ValueChanged -= new EventHandler(StartingPoint_ValueChanged);
|
---|
| 266 | }
|
---|
[11319] | 267 | private void RegisterTerminalPointEvents() {
|
---|
| 268 | TerminalPoint.ValueChanged += new EventHandler(TerminalPoint_ValueChanged);
|
---|
[11265] | 269 | }
|
---|
[11319] | 270 | private void DeregisterTerminalPointEvents() {
|
---|
| 271 | TerminalPoint.ValueChanged -= new EventHandler(TerminalPoint_ValueChanged);
|
---|
[11265] | 272 | }
|
---|
[11240] | 273 | private void RegisterScoresEvents() {
|
---|
| 274 | Scores.ItemChanged += new EventHandler<EventArgs<int>>(Scores_ItemChanged);
|
---|
| 275 | Scores.Reset += new EventHandler(Scores_Reset);
|
---|
| 276 | }
|
---|
| 277 | private void DeregisterScoresEvents() {
|
---|
| 278 | Scores.ItemChanged -= new EventHandler<EventArgs<int>>(Scores_ItemChanged);
|
---|
| 279 | Scores.Reset -= new EventHandler(Scores_Reset);
|
---|
| 280 | }
|
---|
[11190] | 281 | private void RegisterQualityEvents() {
|
---|
| 282 | Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
|
---|
| 283 | }
|
---|
| 284 | private void DeregisterQualityEvents() {
|
---|
| 285 | Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
|
---|
| 286 | }
|
---|
[11311] | 287 | private void RegisterPenaltyEvents() {
|
---|
| 288 | Penalty.ValueChanged += new EventHandler(Penalty_ValueChanged);
|
---|
| 289 | }
|
---|
| 290 | private void DeregisterPenaltyEvents() {
|
---|
| 291 | Penalty.ValueChanged -= new EventHandler(Penalty_ValueChanged);
|
---|
| 292 | }
|
---|
[11327] | 293 | private void RegisterDistanceEvents() {
|
---|
| 294 | Distance.ValueChanged += new EventHandler(Distance_ValueChanged);
|
---|
| 295 | }
|
---|
| 296 | private void DeregisterDistanceEvents() {
|
---|
| 297 | Distance.ValueChanged -= new EventHandler(Distance_ValueChanged);
|
---|
| 298 | }
|
---|
[11190] | 299 |
|
---|
| 300 | private void IntegerVector_ItemChanged(object sender, EventArgs<int> e) {
|
---|
| 301 | OnIntegerVectorChanged();
|
---|
| 302 | }
|
---|
| 303 | private void IntegerVector_Reset(object sender, EventArgs e) {
|
---|
| 304 | OnIntegerVectorChanged();
|
---|
| 305 | }
|
---|
| 306 | private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
|
---|
| 307 | OnCoordinatesChanged();
|
---|
| 308 | }
|
---|
| 309 | private void Coordinates_Reset(object sender, EventArgs e) {
|
---|
| 310 | OnCoordinatesChanged();
|
---|
| 311 | }
|
---|
[11265] | 312 | private void StartingPoint_ValueChanged(object sender, EventArgs e) {
|
---|
| 313 | OnStartingPointChanged();
|
---|
| 314 | }
|
---|
[11319] | 315 | private void TerminalPoint_ValueChanged(object sender, EventArgs e) {
|
---|
| 316 | OnTerminalPointChanged();
|
---|
[11265] | 317 | }
|
---|
[11240] | 318 | private void Scores_ItemChanged(object sender, EventArgs<int> e) {
|
---|
| 319 | OnCoordinatesChanged();
|
---|
| 320 | }
|
---|
| 321 | private void Scores_Reset(object sender, EventArgs e) {
|
---|
| 322 | OnCoordinatesChanged();
|
---|
| 323 | }
|
---|
[11190] | 324 | private void Quality_ValueChanged(object sender, EventArgs e) {
|
---|
| 325 | OnQualityChanged();
|
---|
| 326 | }
|
---|
[11311] | 327 | private void Penalty_ValueChanged(object sender, EventArgs e) {
|
---|
| 328 | OnPenaltyChanged();
|
---|
| 329 | }
|
---|
[11327] | 330 | private void Distance_ValueChanged(object sender, EventArgs e) {
|
---|
| 331 | OnDistanceChanged();
|
---|
| 332 | }
|
---|
[11190] | 333 | #endregion
|
---|
| 334 | }
|
---|
| 335 | } |
---|