[12721] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17246] | 3 | * Copyright (C) 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;
|
---|
[16662] | 28 | using HEAL.Attic;
|
---|
[11190] | 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.Orienteering {
|
---|
| 31 | [Item("OrienteeringSolution", "Represents a Orienteering solution which can be visualized in the GUI.")]
|
---|
[16662] | 32 | [StorableType("BC58ED08-B9A7-40F3-B8E0-A6B33AA993F4")]
|
---|
[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]
|
---|
[16662] | 144 | private OrienteeringSolution(StorableConstructorFlag _) : base(_) { }
|
---|
[11190] | 145 | private OrienteeringSolution(OrienteeringSolution original, Cloner cloner)
|
---|
| 146 | : base(original, cloner) {
|
---|
| 147 | this.integerVector = cloner.Clone(original.integerVector);
|
---|
| 148 | this.coordinates = cloner.Clone(original.coordinates);
|
---|
| 149 | this.quality = cloner.Clone(original.quality);
|
---|
[11311] | 150 | this.penalty = cloner.Clone(original.penalty);
|
---|
[11190] | 151 | Initialize();
|
---|
| 152 | }
|
---|
[11319] | 153 | public OrienteeringSolution(IntegerVector integerVector, DoubleMatrix coordinates, IntValue startingPoint, IntValue terminalPoint,
|
---|
[11327] | 154 | DoubleArray scores, DoubleValue quality = null, DoubleValue penalty = null, DoubleValue distance = null)
|
---|
[11190] | 155 | : base() {
|
---|
| 156 | this.integerVector = integerVector;
|
---|
| 157 | this.coordinates = coordinates;
|
---|
[11265] | 158 | this.startingPoint = startingPoint;
|
---|
[11319] | 159 | this.terminalPoint = terminalPoint;
|
---|
[11240] | 160 | this.scores = scores;
|
---|
[11190] | 161 | this.quality = quality;
|
---|
[11311] | 162 | this.penalty = penalty;
|
---|
[11327] | 163 | this.distance = distance;
|
---|
[11190] | 164 | Initialize();
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 168 | return new OrienteeringSolution(this, cloner);
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 172 | private void AfterDeserialization() {
|
---|
| 173 | Initialize();
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | private void Initialize() {
|
---|
| 177 | if (integerVector != null) RegisterIntegerVectorEvents();
|
---|
| 178 | if (coordinates != null) RegisterCoordinatesEvents();
|
---|
[11265] | 179 | if (startingPoint != null) RegisterStartingPointEvents();
|
---|
[11319] | 180 | if (terminalPoint != null) RegisterTerminalPointEvents();
|
---|
[11240] | 181 | if (scores != null) RegisterScoresEvents();
|
---|
[11190] | 182 | if (quality != null) RegisterQualityEvents();
|
---|
[11311] | 183 | if (penalty != null) RegisterPenaltyEvents();
|
---|
[11327] | 184 | if (distance != null) RegisterDistanceEvents();
|
---|
[11190] | 185 | }
|
---|
| 186 |
|
---|
| 187 | #region Events
|
---|
| 188 | public event EventHandler IntegerVectorChanged;
|
---|
| 189 | private void OnIntegerVectorChanged() {
|
---|
| 190 | var changed = IntegerVectorChanged;
|
---|
| 191 | if (changed != null)
|
---|
| 192 | changed(this, EventArgs.Empty);
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | public event EventHandler CoordinatesChanged;
|
---|
| 196 | private void OnCoordinatesChanged() {
|
---|
| 197 | var changed = CoordinatesChanged;
|
---|
| 198 | if (changed != null)
|
---|
| 199 | changed(this, EventArgs.Empty);
|
---|
| 200 | }
|
---|
| 201 |
|
---|
[11265] | 202 | public event EventHandler StartingPointChanged;
|
---|
| 203 | private void OnStartingPointChanged() {
|
---|
| 204 | var changed = StartingPointChanged;
|
---|
| 205 | if (changed != null)
|
---|
| 206 | changed(this, EventArgs.Empty);
|
---|
| 207 | }
|
---|
| 208 |
|
---|
[11319] | 209 | public event EventHandler TerminalPointChanged;
|
---|
| 210 | private void OnTerminalPointChanged() {
|
---|
| 211 | var changed = TerminalPointChanged;
|
---|
[11265] | 212 | if (changed != null)
|
---|
| 213 | changed(this, EventArgs.Empty);
|
---|
| 214 | }
|
---|
| 215 |
|
---|
[11240] | 216 | public event EventHandler ScoresChanged;
|
---|
| 217 | private void OnScoresChanged() {
|
---|
| 218 | var changed = ScoresChanged;
|
---|
| 219 | if (changed != null)
|
---|
| 220 | changed(this, EventArgs.Empty);
|
---|
| 221 | }
|
---|
[11190] | 222 |
|
---|
| 223 | public event EventHandler QualityChanged;
|
---|
| 224 | private void OnQualityChanged() {
|
---|
| 225 | var changed = QualityChanged;
|
---|
| 226 | if (changed != null)
|
---|
| 227 | changed(this, EventArgs.Empty);
|
---|
| 228 | }
|
---|
| 229 |
|
---|
[11311] | 230 | public event EventHandler PenaltyChanged;
|
---|
| 231 | private void OnPenaltyChanged() {
|
---|
| 232 | var changed = PenaltyChanged;
|
---|
| 233 | if (changed != null)
|
---|
| 234 | changed(this, EventArgs.Empty);
|
---|
| 235 | }
|
---|
| 236 |
|
---|
[11327] | 237 | public event EventHandler DistanceChanged;
|
---|
| 238 | private void OnDistanceChanged() {
|
---|
| 239 | var changed = DistanceChanged;
|
---|
| 240 | if (changed != null)
|
---|
| 241 | changed(this, EventArgs.Empty);
|
---|
| 242 | }
|
---|
| 243 |
|
---|
[11190] | 244 | private void RegisterIntegerVectorEvents() {
|
---|
| 245 | IntegerVector.ItemChanged += new EventHandler<EventArgs<int>>(IntegerVector_ItemChanged);
|
---|
| 246 | IntegerVector.Reset += new EventHandler(IntegerVector_Reset);
|
---|
| 247 | }
|
---|
| 248 | private void DeregisterIntegerVectorEvents() {
|
---|
| 249 | IntegerVector.ItemChanged -= new EventHandler<EventArgs<int>>(IntegerVector_ItemChanged);
|
---|
| 250 | IntegerVector.Reset -= new EventHandler(IntegerVector_Reset);
|
---|
| 251 | }
|
---|
| 252 | private void RegisterCoordinatesEvents() {
|
---|
| 253 | Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
|
---|
| 254 | Coordinates.Reset += new EventHandler(Coordinates_Reset);
|
---|
| 255 | }
|
---|
| 256 | private void DeregisterCoordinatesEvents() {
|
---|
| 257 | Coordinates.ItemChanged -= new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
|
---|
| 258 | Coordinates.Reset -= new EventHandler(Coordinates_Reset);
|
---|
| 259 | }
|
---|
[11265] | 260 | private void RegisterStartingPointEvents() {
|
---|
| 261 | StartingPoint.ValueChanged += new EventHandler(StartingPoint_ValueChanged);
|
---|
| 262 | }
|
---|
| 263 | private void DeregisterStartingPointEvents() {
|
---|
| 264 | StartingPoint.ValueChanged -= new EventHandler(StartingPoint_ValueChanged);
|
---|
| 265 | }
|
---|
[11319] | 266 | private void RegisterTerminalPointEvents() {
|
---|
| 267 | TerminalPoint.ValueChanged += new EventHandler(TerminalPoint_ValueChanged);
|
---|
[11265] | 268 | }
|
---|
[11319] | 269 | private void DeregisterTerminalPointEvents() {
|
---|
| 270 | TerminalPoint.ValueChanged -= new EventHandler(TerminalPoint_ValueChanged);
|
---|
[11265] | 271 | }
|
---|
[11240] | 272 | private void RegisterScoresEvents() {
|
---|
| 273 | Scores.ItemChanged += new EventHandler<EventArgs<int>>(Scores_ItemChanged);
|
---|
| 274 | Scores.Reset += new EventHandler(Scores_Reset);
|
---|
| 275 | }
|
---|
| 276 | private void DeregisterScoresEvents() {
|
---|
| 277 | Scores.ItemChanged -= new EventHandler<EventArgs<int>>(Scores_ItemChanged);
|
---|
| 278 | Scores.Reset -= new EventHandler(Scores_Reset);
|
---|
| 279 | }
|
---|
[11190] | 280 | private void RegisterQualityEvents() {
|
---|
| 281 | Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
|
---|
| 282 | }
|
---|
| 283 | private void DeregisterQualityEvents() {
|
---|
| 284 | Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
|
---|
| 285 | }
|
---|
[11311] | 286 | private void RegisterPenaltyEvents() {
|
---|
| 287 | Penalty.ValueChanged += new EventHandler(Penalty_ValueChanged);
|
---|
| 288 | }
|
---|
| 289 | private void DeregisterPenaltyEvents() {
|
---|
| 290 | Penalty.ValueChanged -= new EventHandler(Penalty_ValueChanged);
|
---|
| 291 | }
|
---|
[11327] | 292 | private void RegisterDistanceEvents() {
|
---|
| 293 | Distance.ValueChanged += new EventHandler(Distance_ValueChanged);
|
---|
| 294 | }
|
---|
| 295 | private void DeregisterDistanceEvents() {
|
---|
| 296 | Distance.ValueChanged -= new EventHandler(Distance_ValueChanged);
|
---|
| 297 | }
|
---|
[11190] | 298 |
|
---|
| 299 | private void IntegerVector_ItemChanged(object sender, EventArgs<int> e) {
|
---|
| 300 | OnIntegerVectorChanged();
|
---|
| 301 | }
|
---|
| 302 | private void IntegerVector_Reset(object sender, EventArgs e) {
|
---|
| 303 | OnIntegerVectorChanged();
|
---|
| 304 | }
|
---|
| 305 | private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
|
---|
| 306 | OnCoordinatesChanged();
|
---|
| 307 | }
|
---|
| 308 | private void Coordinates_Reset(object sender, EventArgs e) {
|
---|
| 309 | OnCoordinatesChanged();
|
---|
| 310 | }
|
---|
[11265] | 311 | private void StartingPoint_ValueChanged(object sender, EventArgs e) {
|
---|
| 312 | OnStartingPointChanged();
|
---|
| 313 | }
|
---|
[11319] | 314 | private void TerminalPoint_ValueChanged(object sender, EventArgs e) {
|
---|
| 315 | OnTerminalPointChanged();
|
---|
[11265] | 316 | }
|
---|
[11240] | 317 | private void Scores_ItemChanged(object sender, EventArgs<int> e) {
|
---|
| 318 | OnCoordinatesChanged();
|
---|
| 319 | }
|
---|
| 320 | private void Scores_Reset(object sender, EventArgs e) {
|
---|
| 321 | OnCoordinatesChanged();
|
---|
| 322 | }
|
---|
[11190] | 323 | private void Quality_ValueChanged(object sender, EventArgs e) {
|
---|
| 324 | OnQualityChanged();
|
---|
| 325 | }
|
---|
[11311] | 326 | private void Penalty_ValueChanged(object sender, EventArgs e) {
|
---|
| 327 | OnPenaltyChanged();
|
---|
| 328 | }
|
---|
[11327] | 329 | private void Distance_ValueChanged(object sender, EventArgs e) {
|
---|
| 330 | OnDistanceChanged();
|
---|
| 331 | }
|
---|
[11190] | 332 | #endregion
|
---|
| 333 | }
|
---|
| 334 | } |
---|