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 HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Operators;
|
---|
27 | using HeuristicLab.Optimization;
|
---|
28 | using HeuristicLab.Optimization.Operators;
|
---|
29 | using HeuristicLab.Parameters;
|
---|
30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
31 | using HeuristicLab.Analysis;
|
---|
32 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
33 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
34 |
|
---|
35 | namespace HeuristicLab.Problems.VehicleRouting {
|
---|
36 | /// <summary>
|
---|
37 | /// An operator which analyzes the best, average and worst quality of solutions in the scope tree.
|
---|
38 | /// </summary>
|
---|
39 | [Item("BestAverageWorstTimeWindowedVRPToursAnalyzer", "An operator which analyzes the best, average and worst properties of the VRP tours in the scope tree.")]
|
---|
40 | [StorableClass]
|
---|
41 | public sealed class BestAverageWorstTimeWindowedVRPToursAnalyzer : AlgorithmOperator, IAnalyzer, ITimeWindowedOperator {
|
---|
42 | #region Parameter properties
|
---|
43 | public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter {
|
---|
44 | get { return (ILookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; }
|
---|
45 | }
|
---|
46 | public ScopeTreeLookupParameter<DoubleValue> TardinessParameter {
|
---|
47 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Tardiness"]; }
|
---|
48 | }
|
---|
49 | public ValueLookupParameter<DoubleValue> BestTardinessParameter {
|
---|
50 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestTardiness"]; }
|
---|
51 | }
|
---|
52 | public ValueLookupParameter<DoubleValue> CurrentBestTardinessParameter {
|
---|
53 | get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentBestTardiness"]; }
|
---|
54 | }
|
---|
55 | public ValueLookupParameter<DoubleValue> CurrentAverageTardinessParameter {
|
---|
56 | get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentAverageTardiness"]; }
|
---|
57 | }
|
---|
58 | public ValueLookupParameter<DoubleValue> CurrentWorstTardinessParameter {
|
---|
59 | get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentWorstTardiness"]; }
|
---|
60 | }
|
---|
61 | public ValueLookupParameter<DataTable> TardinessValuesParameter {
|
---|
62 | get { return (ValueLookupParameter<DataTable>)Parameters["TardinessValues"]; }
|
---|
63 | }
|
---|
64 |
|
---|
65 | public ScopeTreeLookupParameter<DoubleValue> TravelTimeParameter {
|
---|
66 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["TravelTime"]; }
|
---|
67 | }
|
---|
68 | public ValueLookupParameter<DoubleValue> BestTravelTimeParameter {
|
---|
69 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestTravelTime"]; }
|
---|
70 | }
|
---|
71 | public ValueLookupParameter<DoubleValue> CurrentBestTravelTimeParameter {
|
---|
72 | get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentBestTravelTime"]; }
|
---|
73 | }
|
---|
74 | public ValueLookupParameter<DoubleValue> CurrentAverageTravelTimeParameter {
|
---|
75 | get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentAverageTravelTime"]; }
|
---|
76 | }
|
---|
77 | public ValueLookupParameter<DoubleValue> CurrentWorstTravelTimeParameter {
|
---|
78 | get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentWorstTravelTime"]; }
|
---|
79 | }
|
---|
80 | public ValueLookupParameter<DataTable> TravelTimesParameter {
|
---|
81 | get { return (ValueLookupParameter<DataTable>)Parameters["TravelTimes"]; }
|
---|
82 | }
|
---|
83 |
|
---|
84 | public ValueLookupParameter<VariableCollection> ResultsParameter {
|
---|
85 | get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
|
---|
86 | }
|
---|
87 | #endregion
|
---|
88 |
|
---|
89 | #region Properties
|
---|
90 | public bool EnabledByDefault {
|
---|
91 | get { return true; }
|
---|
92 | }
|
---|
93 | private BestTimeWindowedVRPToursMemorizer BestMemorizer {
|
---|
94 | get { return (BestTimeWindowedVRPToursMemorizer)OperatorGraph.InitialOperator; }
|
---|
95 | }
|
---|
96 | private BestAverageWorstTimeWindowedVRPToursCalculator BestAverageWorstCalculator {
|
---|
97 | get { return (BestAverageWorstTimeWindowedVRPToursCalculator)BestMemorizer.Successor; }
|
---|
98 | }
|
---|
99 | #endregion
|
---|
100 |
|
---|
101 | public BestAverageWorstTimeWindowedVRPToursAnalyzer()
|
---|
102 | : base() {
|
---|
103 | #region Create parameters
|
---|
104 | Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance."));
|
---|
105 |
|
---|
106 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Tardiness", "The tardiness of the VRP solutions which should be analyzed."));
|
---|
107 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestTardiness", "The best tardiness value."));
|
---|
108 | Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentBestTardiness", "The current best tardiness value."));
|
---|
109 | Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentAverageTardiness", "The current average tardiness value of all solutions."));
|
---|
110 | Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentWorstTardiness", "The current worst tardiness value of all solutions."));
|
---|
111 | Parameters.Add(new ValueLookupParameter<DataTable>("TardinessValues", "The data table to store the current best, current average, current worst, best and best known tardiness value."));
|
---|
112 |
|
---|
113 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("TravelTime", "The travel time of the VRP solutions which should be analyzed."));
|
---|
114 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestTravelTime", "The best travel time value."));
|
---|
115 | Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentBestTravelTime", "The current best travel time value."));
|
---|
116 | Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentAverageTravelTime", "The current average travel time value of all solutions."));
|
---|
117 | Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentWorstTravelTime", "The current worst travel time value of all solutions."));
|
---|
118 | Parameters.Add(new ValueLookupParameter<DataTable>("TravelTimes", "The data table to store the current best, current average, current worst, best and best known travel time value."));
|
---|
119 |
|
---|
120 | Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The results collection where the analysis values should be stored."));
|
---|
121 | #endregion
|
---|
122 |
|
---|
123 | #region Create operators
|
---|
124 | BestTimeWindowedVRPToursMemorizer bestMemorizer = new BestTimeWindowedVRPToursMemorizer();
|
---|
125 | BestAverageWorstTimeWindowedVRPToursCalculator calculator = new BestAverageWorstTimeWindowedVRPToursCalculator();
|
---|
126 | ResultsCollector resultsCollector = new ResultsCollector();
|
---|
127 |
|
---|
128 | //tardiness
|
---|
129 | bestMemorizer.BestTardinessParameter.ActualName = BestTardinessParameter.Name;
|
---|
130 | bestMemorizer.TardinessParameter.ActualName = TardinessParameter.Name;
|
---|
131 | bestMemorizer.TardinessParameter.Depth = TardinessParameter.Depth;
|
---|
132 |
|
---|
133 | calculator.TardinessParameter.ActualName = TardinessParameter.Name;
|
---|
134 | calculator.TardinessParameter.Depth = TardinessParameter.Depth;
|
---|
135 | calculator.BestTardinessParameter.ActualName = CurrentBestTardinessParameter.Name;
|
---|
136 | calculator.AverageTardinessParameter.ActualName = CurrentAverageTardinessParameter.Name;
|
---|
137 | calculator.WorstTardinessParameter.ActualName = CurrentWorstTardinessParameter.Name;
|
---|
138 |
|
---|
139 | DataTableValuesCollector tardinessDataTablesCollector = new DataTableValuesCollector();
|
---|
140 | tardinessDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestTardiness", null, BestTardinessParameter.Name));
|
---|
141 | tardinessDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentBestTardiness", null, CurrentBestTardinessParameter.Name));
|
---|
142 | tardinessDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentAverageTardiness", null, CurrentAverageTardinessParameter.Name));
|
---|
143 | tardinessDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentWorstTardiness", null, CurrentWorstTardinessParameter.Name));
|
---|
144 | tardinessDataTablesCollector.DataTableParameter.ActualName = TardinessValuesParameter.Name;
|
---|
145 |
|
---|
146 | resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(TardinessValuesParameter.Name));
|
---|
147 |
|
---|
148 | //Travel Time
|
---|
149 | bestMemorizer.BestTravelTimeParameter.ActualName = BestTravelTimeParameter.Name;
|
---|
150 | bestMemorizer.TravelTimeParameter.ActualName = TravelTimeParameter.Name;
|
---|
151 | bestMemorizer.TravelTimeParameter.Depth = TravelTimeParameter.Depth;
|
---|
152 |
|
---|
153 | calculator.TravelTimeParameter.ActualName = TravelTimeParameter.Name;
|
---|
154 | calculator.TravelTimeParameter.Depth = TravelTimeParameter.Depth;
|
---|
155 | calculator.BestTravelTimeParameter.ActualName = CurrentBestTravelTimeParameter.Name;
|
---|
156 | calculator.AverageTravelTimeParameter.ActualName = CurrentAverageTravelTimeParameter.Name;
|
---|
157 | calculator.WorstTravelTimeParameter.ActualName = CurrentWorstTravelTimeParameter.Name;
|
---|
158 |
|
---|
159 | DataTableValuesCollector travelTimeDataTablesCollector = new DataTableValuesCollector();
|
---|
160 | travelTimeDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestTravelTime", null, BestTravelTimeParameter.Name));
|
---|
161 | travelTimeDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentBestTravelTime", null, CurrentBestTravelTimeParameter.Name));
|
---|
162 | travelTimeDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentAverageTravelTime", null, CurrentAverageTravelTimeParameter.Name));
|
---|
163 | travelTimeDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentWorstTravelTime", null, CurrentWorstTravelTimeParameter.Name));
|
---|
164 | travelTimeDataTablesCollector.DataTableParameter.ActualName = TravelTimesParameter.Name;
|
---|
165 |
|
---|
166 | resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(TravelTimesParameter.Name));
|
---|
167 | #endregion
|
---|
168 |
|
---|
169 | #region Create operator graph
|
---|
170 | OperatorGraph.InitialOperator = bestMemorizer;
|
---|
171 | bestMemorizer.Successor = calculator;
|
---|
172 | calculator.Successor = tardinessDataTablesCollector;
|
---|
173 | tardinessDataTablesCollector.Successor = travelTimeDataTablesCollector;
|
---|
174 | travelTimeDataTablesCollector.Successor = resultsCollector;
|
---|
175 | resultsCollector.Successor = null;
|
---|
176 | #endregion
|
---|
177 |
|
---|
178 | Initialize();
|
---|
179 | }
|
---|
180 | [StorableConstructor]
|
---|
181 | private BestAverageWorstTimeWindowedVRPToursAnalyzer(bool deserializing) : base() { }
|
---|
182 |
|
---|
183 | [StorableHook(HookType.AfterDeserialization)]
|
---|
184 | private void Initialize() {
|
---|
185 | TardinessParameter.DepthChanged += new EventHandler(TardinessParameter_DepthChanged);
|
---|
186 | TravelTimeParameter.DepthChanged += new EventHandler(TravelTimeParameter_DepthChanged);
|
---|
187 | }
|
---|
188 |
|
---|
189 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
190 | return new BestAverageWorstTimeWindowedVRPToursAnalyzer(this, cloner);
|
---|
191 | }
|
---|
192 |
|
---|
193 | private BestAverageWorstTimeWindowedVRPToursAnalyzer(BestAverageWorstTimeWindowedVRPToursAnalyzer original, Cloner cloner)
|
---|
194 | : base(original, cloner) {
|
---|
195 | this.Initialize();
|
---|
196 | }
|
---|
197 |
|
---|
198 | void TardinessParameter_DepthChanged(object sender, EventArgs e) {
|
---|
199 | BestAverageWorstCalculator.TardinessParameter.Depth = TardinessParameter.Depth;
|
---|
200 | BestMemorizer.TardinessParameter.Depth = TardinessParameter.Depth;
|
---|
201 | }
|
---|
202 |
|
---|
203 | void TravelTimeParameter_DepthChanged(object sender, EventArgs e) {
|
---|
204 | BestAverageWorstCalculator.TravelTimeParameter.Depth = TravelTimeParameter.Depth;
|
---|
205 | BestMemorizer.TravelTimeParameter.Depth = TravelTimeParameter.Depth;
|
---|
206 | }
|
---|
207 | }
|
---|
208 | }
|
---|