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