[4374] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Drawing;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.VehicleRouting {
|
---|
| 31 | /// <summary>
|
---|
| 32 | /// Represents a VRP solution which can be visualized in the GUI.
|
---|
| 33 | /// </summary>
|
---|
| 34 | [Item("VRPSolution", "Represents a VRP solution which can be visualized in the GUI.")]
|
---|
| 35 | [StorableClass]
|
---|
| 36 | public sealed class VRPSolution : Item {
|
---|
| 37 | public override Image ItemImage {
|
---|
| 38 | get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Image; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | [Storable]
|
---|
| 42 | private IVRPProblemInstance problemInstance;
|
---|
| 43 | public IVRPProblemInstance ProblemInstance {
|
---|
| 44 | get { return problemInstance; }
|
---|
| 45 | set {
|
---|
| 46 | if (problemInstance != value) {
|
---|
| 47 | if (problemInstance != null) DeregisterProblemInstanceEvents();
|
---|
| 48 | problemInstance = value;
|
---|
| 49 | if (problemInstance != null) RegisterProblemInstanceEvents();
|
---|
| 50 | OnProblemInstanceChanged();
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | [Storable]
|
---|
| 55 | private IVRPEncoding solution;
|
---|
| 56 | public IVRPEncoding Solution {
|
---|
| 57 | get { return solution; }
|
---|
| 58 | set {
|
---|
| 59 | if (solution != value) {
|
---|
| 60 | if (solution != null) DeregisterSolutionEvents();
|
---|
| 61 | solution = value;
|
---|
| 62 | if (solution != null) RegisterSolutionEvents();
|
---|
| 63 | OnSolutionChanged();
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | [Storable]
|
---|
| 68 | private DoubleValue quality;
|
---|
| 69 | public DoubleValue Quality {
|
---|
| 70 | get { return quality; }
|
---|
| 71 | set {
|
---|
| 72 | if (quality != value) {
|
---|
| 73 | if (quality != null) DeregisterQualityEvents();
|
---|
| 74 | quality = value;
|
---|
| 75 | if (quality != null) RegisterQualityEvents();
|
---|
| 76 | OnQualityChanged();
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | public VRPSolution() : base() { }
|
---|
| 82 |
|
---|
| 83 | public VRPSolution(IVRPProblemInstance problemInstance, IVRPEncoding solution, DoubleValue quality)
|
---|
| 84 | : base() {
|
---|
| 85 | this.problemInstance = problemInstance;
|
---|
| 86 | this.solution = solution;
|
---|
| 87 | this.quality = quality;
|
---|
| 88 |
|
---|
| 89 | Initialize();
|
---|
| 90 | }
|
---|
| 91 | [StorableConstructor]
|
---|
| 92 | private VRPSolution(bool deserializing) : base(deserializing) { }
|
---|
| 93 |
|
---|
| 94 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 95 | private void Initialize() {
|
---|
| 96 | if (problemInstance != null) RegisterProblemInstanceEvents();
|
---|
| 97 | if (solution != null) RegisterSolutionEvents();
|
---|
| 98 | if (quality != null) RegisterQualityEvents();
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[4752] | 101 |
|
---|
[4374] | 102 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[4752] | 103 | return new VRPSolution(this, cloner);
|
---|
[4374] | 104 | }
|
---|
| 105 |
|
---|
[4752] | 106 | private VRPSolution(VRPSolution original, Cloner cloner)
|
---|
| 107 | : base(original, cloner) {
|
---|
| 108 | this.problemInstance = (IVRPProblemInstance)cloner.Clone(original.problemInstance);
|
---|
| 109 | this.solution = (IVRPEncoding)cloner.Clone(original.solution);
|
---|
| 110 | this.quality = (DoubleValue)cloner.Clone(original.quality);
|
---|
| 111 |
|
---|
| 112 | this.Initialize();
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[4374] | 115 | #region Events
|
---|
| 116 | public event EventHandler ProblemInstanceChanged;
|
---|
| 117 | private void OnProblemInstanceChanged() {
|
---|
| 118 | var changed = ProblemInstanceChanged;
|
---|
| 119 | if (changed != null)
|
---|
| 120 | changed(this, EventArgs.Empty);
|
---|
| 121 | }
|
---|
| 122 | public event EventHandler SolutionChanged;
|
---|
| 123 | private void OnSolutionChanged() {
|
---|
| 124 | var changed = SolutionChanged;
|
---|
| 125 | if (changed != null)
|
---|
| 126 | changed(this, EventArgs.Empty);
|
---|
| 127 | }
|
---|
| 128 | public event EventHandler QualityChanged;
|
---|
| 129 | private void OnQualityChanged() {
|
---|
| 130 | var changed = QualityChanged;
|
---|
| 131 | if (changed != null)
|
---|
| 132 | changed(this, EventArgs.Empty);
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | private void RegisterProblemInstanceEvents() {
|
---|
| 136 | ProblemInstance.ToStringChanged += new EventHandler(ProblemInstance_ToStringChanged);
|
---|
| 137 | }
|
---|
| 138 | private void DeregisterProblemInstanceEvents() {
|
---|
| 139 | ProblemInstance.ToStringChanged -= new EventHandler(ProblemInstance_ToStringChanged);
|
---|
| 140 | }
|
---|
| 141 | private void RegisterSolutionEvents() {
|
---|
| 142 | Solution.ToStringChanged += new EventHandler(Solution_ToStringChanged);
|
---|
| 143 | }
|
---|
| 144 | private void DeregisterSolutionEvents() {
|
---|
| 145 | Solution.ToStringChanged -= new EventHandler(Solution_ToStringChanged);
|
---|
| 146 | }
|
---|
| 147 | private void RegisterQualityEvents() {
|
---|
| 148 | Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
|
---|
| 149 | }
|
---|
| 150 | private void DeregisterQualityEvents() {
|
---|
| 151 | Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | private void ProblemInstance_ToStringChanged(object sender, EventArgs e) {
|
---|
| 155 | OnProblemInstanceChanged();
|
---|
| 156 | }
|
---|
| 157 | private void Solution_ToStringChanged(object sender, EventArgs e) {
|
---|
| 158 | OnSolutionChanged();
|
---|
| 159 | }
|
---|
| 160 | private void Quality_ValueChanged(object sender, EventArgs e) {
|
---|
| 161 | OnQualityChanged();
|
---|
| 162 | }
|
---|
| 163 | #endregion
|
---|
| 164 | }
|
---|
| 165 | }
|
---|