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 HeuristicLab.Core;
|
---|
23 | using HeuristicLab.Data;
|
---|
24 | using HeuristicLab.Operators;
|
---|
25 | using HeuristicLab.Parameters;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Problems.VehicleRouting {
|
---|
29 | [Item("BestAverageWorstVRPToursCalculator", "An operator which calculates the current best, average and worst properties of VRP tours in the scope tree.")]
|
---|
30 | [StorableClass]
|
---|
31 | public sealed class BestAverageWorstVRPToursCalculator : SingleSuccessorOperator {
|
---|
32 | public ScopeTreeLookupParameter<DoubleValue> OverloadParameter {
|
---|
33 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Overload"]; }
|
---|
34 | }
|
---|
35 | public ValueLookupParameter<DoubleValue> BestOverloadParameter {
|
---|
36 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestOverload"]; }
|
---|
37 | }
|
---|
38 | public ValueLookupParameter<DoubleValue> AverageOverloadParameter {
|
---|
39 | get { return (ValueLookupParameter<DoubleValue>)Parameters["AverageOverload"]; }
|
---|
40 | }
|
---|
41 | public ValueLookupParameter<DoubleValue> WorstOverloadParameter {
|
---|
42 | get { return (ValueLookupParameter<DoubleValue>)Parameters["WorstOverload"]; }
|
---|
43 | }
|
---|
44 |
|
---|
45 | public ScopeTreeLookupParameter<DoubleValue> TardinessParameter {
|
---|
46 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Tardiness"]; }
|
---|
47 | }
|
---|
48 | public ValueLookupParameter<DoubleValue> BestTardinessParameter {
|
---|
49 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestTardiness"]; }
|
---|
50 | }
|
---|
51 | public ValueLookupParameter<DoubleValue> AverageTardinessParameter {
|
---|
52 | get { return (ValueLookupParameter<DoubleValue>)Parameters["AverageTardiness"]; }
|
---|
53 | }
|
---|
54 | public ValueLookupParameter<DoubleValue> WorstTardinessParameter {
|
---|
55 | get { return (ValueLookupParameter<DoubleValue>)Parameters["WorstTardiness"]; }
|
---|
56 | }
|
---|
57 |
|
---|
58 | public ScopeTreeLookupParameter<DoubleValue> DistanceParameter {
|
---|
59 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Distance"]; }
|
---|
60 | }
|
---|
61 | public ValueLookupParameter<DoubleValue> BestDistanceParameter {
|
---|
62 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestDistance"]; }
|
---|
63 | }
|
---|
64 | public ValueLookupParameter<DoubleValue> AverageDistanceParameter {
|
---|
65 | get { return (ValueLookupParameter<DoubleValue>)Parameters["AverageDistance"]; }
|
---|
66 | }
|
---|
67 | public ValueLookupParameter<DoubleValue> WorstDistanceParameter {
|
---|
68 | get { return (ValueLookupParameter<DoubleValue>)Parameters["WorstDistance"]; }
|
---|
69 | }
|
---|
70 |
|
---|
71 | public ScopeTreeLookupParameter<DoubleValue> TravelTimeParameter {
|
---|
72 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["TravelTime"]; }
|
---|
73 | }
|
---|
74 | public ValueLookupParameter<DoubleValue> BestTravelTimeParameter {
|
---|
75 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestTravelTime"]; }
|
---|
76 | }
|
---|
77 | public ValueLookupParameter<DoubleValue> AverageTravelTimeParameter {
|
---|
78 | get { return (ValueLookupParameter<DoubleValue>)Parameters["AverageTravelTime"]; }
|
---|
79 | }
|
---|
80 | public ValueLookupParameter<DoubleValue> WorstTravelTimeParameter {
|
---|
81 | get { return (ValueLookupParameter<DoubleValue>)Parameters["WorstTravelTime"]; }
|
---|
82 | }
|
---|
83 |
|
---|
84 | public ScopeTreeLookupParameter<DoubleValue> VehiclesUtilizedParameter {
|
---|
85 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["VehiclesUtilized"]; }
|
---|
86 | }
|
---|
87 | public ValueLookupParameter<DoubleValue> BestVehiclesUtilizedParameter {
|
---|
88 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestVehiclesUtilized"]; }
|
---|
89 | }
|
---|
90 | public ValueLookupParameter<DoubleValue> AverageVehiclesUtilizedParameter {
|
---|
91 | get { return (ValueLookupParameter<DoubleValue>)Parameters["AverageVehiclesUtilized"]; }
|
---|
92 | }
|
---|
93 | public ValueLookupParameter<DoubleValue> WorstVehiclesUtilizedParameter {
|
---|
94 | get { return (ValueLookupParameter<DoubleValue>)Parameters["WorstVehiclesUtilized"]; }
|
---|
95 | }
|
---|
96 |
|
---|
97 | public BestAverageWorstVRPToursCalculator()
|
---|
98 | : base() {
|
---|
99 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Distance", "The distances of the VRP solutions which should be analyzed."));
|
---|
100 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestDistance", "The best distance value."));
|
---|
101 | Parameters.Add(new ValueLookupParameter<DoubleValue>("AverageDistance", "The average distance value of all solutions."));
|
---|
102 | Parameters.Add(new ValueLookupParameter<DoubleValue>("WorstDistance", "The worst distance value of all solutions."));
|
---|
103 |
|
---|
104 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Overload", "The overloads of the VRP solutions which should be analyzed."));
|
---|
105 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestOverload", "The best overload value."));
|
---|
106 | Parameters.Add(new ValueLookupParameter<DoubleValue>("AverageOverload", "The average overload value of all solutions."));
|
---|
107 | Parameters.Add(new ValueLookupParameter<DoubleValue>("WorstOverload", "The worst overload value of all solutions."));
|
---|
108 |
|
---|
109 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Tardiness", "The tardiness of the VRP solutions which should be analyzed."));
|
---|
110 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestTardiness", "The best tardiness value."));
|
---|
111 | Parameters.Add(new ValueLookupParameter<DoubleValue>("AverageTardiness", "The average tardiness value of all solutions."));
|
---|
112 | Parameters.Add(new ValueLookupParameter<DoubleValue>("WorstTardiness", "The worst tardiness value of all solutions."));
|
---|
113 |
|
---|
114 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("TravelTime", "The travel times of the VRP solutions which should be analyzed."));
|
---|
115 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestTravelTime", "The best travel time value."));
|
---|
116 | Parameters.Add(new ValueLookupParameter<DoubleValue>("AverageTravelTime", "The average travel time value of all solutions."));
|
---|
117 | Parameters.Add(new ValueLookupParameter<DoubleValue>("WorstTravelTime", "The worst travel time value of all solutions."));
|
---|
118 |
|
---|
119 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("VehiclesUtilized", "The utilized vehicles of the VRP solutions which should be analyzed."));
|
---|
120 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestVehiclesUtilized", "The best utilized vehicles value."));
|
---|
121 | Parameters.Add(new ValueLookupParameter<DoubleValue>("AverageVehiclesUtilized", "The average utilized vehicles value of all solutions."));
|
---|
122 | Parameters.Add(new ValueLookupParameter<DoubleValue>("WorstVehiclesUtilized", "The worst utilized vehicles value of all solutions."));
|
---|
123 | }
|
---|
124 |
|
---|
125 | private void UpdateOverloads() {
|
---|
126 | ItemArray<DoubleValue> overloads = OverloadParameter.ActualValue;
|
---|
127 | if (overloads.Length > 0) {
|
---|
128 | double min = double.MaxValue, max = double.MinValue, sum = 0.0;
|
---|
129 | for (int i = 0; i < overloads.Length; i++) {
|
---|
130 | if (overloads[i].Value < min) min = overloads[i].Value;
|
---|
131 | if (overloads[i].Value > max) max = overloads[i].Value;
|
---|
132 | sum += overloads[i].Value;
|
---|
133 | }
|
---|
134 |
|
---|
135 | DoubleValue best = BestOverloadParameter.ActualValue;
|
---|
136 | if (best == null) BestOverloadParameter.ActualValue = new DoubleValue(min);
|
---|
137 | else best.Value = min;
|
---|
138 | DoubleValue average = AverageOverloadParameter.ActualValue;
|
---|
139 | if (average == null) AverageOverloadParameter.ActualValue = new DoubleValue(sum / overloads.Length);
|
---|
140 | else average.Value = sum / overloads.Length;
|
---|
141 | DoubleValue worst = WorstOverloadParameter.ActualValue;
|
---|
142 | if (worst == null) WorstOverloadParameter.ActualValue = new DoubleValue(max);
|
---|
143 | else worst.Value = max;
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 | private void UpdateTardiness() {
|
---|
148 | ItemArray<DoubleValue> tardiness = TardinessParameter.ActualValue;
|
---|
149 | if (tardiness.Length > 0) {
|
---|
150 | double min = double.MaxValue, max = double.MinValue, sum = 0.0;
|
---|
151 | for (int i = 0; i < tardiness.Length; i++) {
|
---|
152 | if (tardiness[i].Value < min) min = tardiness[i].Value;
|
---|
153 | if (tardiness[i].Value > max) max = tardiness[i].Value;
|
---|
154 | sum += tardiness[i].Value;
|
---|
155 | }
|
---|
156 |
|
---|
157 | DoubleValue best = BestTardinessParameter.ActualValue;
|
---|
158 | if (best == null) BestTardinessParameter.ActualValue = new DoubleValue(min);
|
---|
159 | else best.Value = min;
|
---|
160 | DoubleValue average = AverageTardinessParameter.ActualValue;
|
---|
161 | if (average == null) AverageTardinessParameter.ActualValue = new DoubleValue(sum / tardiness.Length);
|
---|
162 | else average.Value = sum / tardiness.Length;
|
---|
163 | DoubleValue worst = WorstTardinessParameter.ActualValue;
|
---|
164 | if (worst == null) WorstTardinessParameter.ActualValue = new DoubleValue(max);
|
---|
165 | else worst.Value = max;
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 | private void UpdateDistances() {
|
---|
170 | ItemArray<DoubleValue> distances = DistanceParameter.ActualValue;
|
---|
171 | if (distances.Length > 0) {
|
---|
172 | double min = double.MaxValue, max = double.MinValue, sum = 0.0;
|
---|
173 | for (int i = 0; i < distances.Length; i++) {
|
---|
174 | if (distances[i].Value < min) min = distances[i].Value;
|
---|
175 | if (distances[i].Value > max) max = distances[i].Value;
|
---|
176 | sum += distances[i].Value;
|
---|
177 | }
|
---|
178 |
|
---|
179 | DoubleValue best = BestDistanceParameter.ActualValue;
|
---|
180 | if (best == null) BestDistanceParameter.ActualValue = new DoubleValue(min);
|
---|
181 | else best.Value = min;
|
---|
182 | DoubleValue average = AverageDistanceParameter.ActualValue;
|
---|
183 | if (average == null) AverageDistanceParameter.ActualValue = new DoubleValue(sum / distances.Length);
|
---|
184 | else average.Value = sum / distances.Length;
|
---|
185 | DoubleValue worst = WorstDistanceParameter.ActualValue;
|
---|
186 | if (worst == null) WorstDistanceParameter.ActualValue = new DoubleValue(max);
|
---|
187 | else worst.Value = max;
|
---|
188 | }
|
---|
189 | }
|
---|
190 |
|
---|
191 | private void UpdateTravelTimes() {
|
---|
192 | ItemArray<DoubleValue> travelTimes = TravelTimeParameter.ActualValue;
|
---|
193 | if (travelTimes.Length > 0) {
|
---|
194 | double min = double.MaxValue, max = double.MinValue, sum = 0.0;
|
---|
195 | for (int i = 0; i < travelTimes.Length; i++) {
|
---|
196 | if (travelTimes[i].Value < min) min = travelTimes[i].Value;
|
---|
197 | if (travelTimes[i].Value > max) max = travelTimes[i].Value;
|
---|
198 | sum += travelTimes[i].Value;
|
---|
199 | }
|
---|
200 |
|
---|
201 | DoubleValue best = BestTravelTimeParameter.ActualValue;
|
---|
202 | if (best == null) BestTravelTimeParameter.ActualValue = new DoubleValue(min);
|
---|
203 | else best.Value = min;
|
---|
204 | DoubleValue average = AverageTravelTimeParameter.ActualValue;
|
---|
205 | if (average == null) AverageTravelTimeParameter.ActualValue = new DoubleValue(sum / travelTimes.Length);
|
---|
206 | else average.Value = sum / travelTimes.Length;
|
---|
207 | DoubleValue worst = WorstTravelTimeParameter.ActualValue;
|
---|
208 | if (worst == null) WorstTravelTimeParameter.ActualValue = new DoubleValue(max);
|
---|
209 | else worst.Value = max;
|
---|
210 | }
|
---|
211 | }
|
---|
212 |
|
---|
213 | private void UpdateVehiclesUtilized() {
|
---|
214 | ItemArray<DoubleValue> vehiclesUtilized = VehiclesUtilizedParameter.ActualValue;
|
---|
215 | if (vehiclesUtilized.Length > 0) {
|
---|
216 | double min = double.MaxValue, max = double.MinValue, sum = 0.0;
|
---|
217 | for (int i = 0; i < vehiclesUtilized.Length; i++) {
|
---|
218 | if (vehiclesUtilized[i].Value < min) min = vehiclesUtilized[i].Value;
|
---|
219 | if (vehiclesUtilized[i].Value > max) max = vehiclesUtilized[i].Value;
|
---|
220 | sum += vehiclesUtilized[i].Value;
|
---|
221 | }
|
---|
222 |
|
---|
223 | DoubleValue best = BestVehiclesUtilizedParameter.ActualValue;
|
---|
224 | if (best == null) BestVehiclesUtilizedParameter.ActualValue = new DoubleValue(min);
|
---|
225 | else best.Value = min;
|
---|
226 | DoubleValue average = AverageVehiclesUtilizedParameter.ActualValue;
|
---|
227 | if (average == null) AverageVehiclesUtilizedParameter.ActualValue = new DoubleValue(sum / vehiclesUtilized.Length);
|
---|
228 | else average.Value = sum / vehiclesUtilized.Length;
|
---|
229 | DoubleValue worst = WorstVehiclesUtilizedParameter.ActualValue;
|
---|
230 | if (worst == null) WorstVehiclesUtilizedParameter.ActualValue = new DoubleValue(max);
|
---|
231 | else worst.Value = max;
|
---|
232 | }
|
---|
233 | }
|
---|
234 |
|
---|
235 | public override IOperation Apply() {
|
---|
236 | UpdateOverloads();
|
---|
237 | UpdateTardiness();
|
---|
238 | UpdateDistances();
|
---|
239 | UpdateTravelTimes();
|
---|
240 | UpdateVehiclesUtilized();
|
---|
241 |
|
---|
242 | return base.Apply();
|
---|
243 | }
|
---|
244 | }
|
---|
245 | }
|
---|