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