1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2012 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.Analysis;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.Operators;
|
---|
28 | using HeuristicLab.Optimization;
|
---|
29 | using HeuristicLab.Optimization.Operators;
|
---|
30 | using HeuristicLab.Parameters;
|
---|
31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
32 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
33 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
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("BestAverageWorstVRPToursAnalyzer", "An operator which analyzes the best, average and worst properties of the VRP tours in the scope tree.")]
|
---|
40 | [StorableClass]
|
---|
41 | public sealed class BestAverageWorstVRPToursAnalyzer : AlgorithmOperator, IAnalyzer, IGeneralVRPOperator {
|
---|
42 | #region Parameter properties
|
---|
43 | public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter {
|
---|
44 | get { return (ILookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; }
|
---|
45 | }
|
---|
46 | public ScopeTreeLookupParameter<DoubleValue> DistanceParameter {
|
---|
47 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Distance"]; }
|
---|
48 | }
|
---|
49 | public ValueLookupParameter<DoubleValue> BestDistanceParameter {
|
---|
50 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestDistance"]; }
|
---|
51 | }
|
---|
52 | public ValueLookupParameter<DoubleValue> CurrentBestDistanceParameter {
|
---|
53 | get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentBestDistance"]; }
|
---|
54 | }
|
---|
55 | public ValueLookupParameter<DoubleValue> CurrentAverageDistanceParameter {
|
---|
56 | get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentAverageDistance"]; }
|
---|
57 | }
|
---|
58 | public ValueLookupParameter<DoubleValue> CurrentWorstDistanceParameter {
|
---|
59 | get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentWorstDistance"]; }
|
---|
60 | }
|
---|
61 | public ValueLookupParameter<DataTable> DistancesParameter {
|
---|
62 | get { return (ValueLookupParameter<DataTable>)Parameters["Distances"]; }
|
---|
63 | }
|
---|
64 |
|
---|
65 | public ScopeTreeLookupParameter<DoubleValue> VehiclesUtilizedParameter {
|
---|
66 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["VehiclesUtilized"]; }
|
---|
67 | }
|
---|
68 | public ValueLookupParameter<DoubleValue> BestVehiclesUtilizedParameter {
|
---|
69 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestVehiclesUtilized"]; }
|
---|
70 | }
|
---|
71 | public ValueLookupParameter<DoubleValue> CurrentBestVehiclesUtilizedParameter {
|
---|
72 | get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentBestVehiclesUtilized"]; }
|
---|
73 | }
|
---|
74 | public ValueLookupParameter<DoubleValue> CurrentAverageVehiclesUtilizedParameter {
|
---|
75 | get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentAverageVehiclesUtilized"]; }
|
---|
76 | }
|
---|
77 | public ValueLookupParameter<DoubleValue> CurrentWorstVehiclesUtilizedParameter {
|
---|
78 | get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentWorstVehiclesUtilized"]; }
|
---|
79 | }
|
---|
80 | public ValueLookupParameter<DataTable> VehiclesUtilizedValuesParameter {
|
---|
81 | get { return (ValueLookupParameter<DataTable>)Parameters["VehiclesUtilizedValues"]; }
|
---|
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 BestVRPToursMemorizer BestMemorizer {
|
---|
94 | get { return (BestVRPToursMemorizer)OperatorGraph.InitialOperator; }
|
---|
95 | }
|
---|
96 | private BestAverageWorstVRPToursCalculator BestAverageWorstCalculator {
|
---|
97 | get { return (BestAverageWorstVRPToursCalculator)BestMemorizer.Successor; }
|
---|
98 | }
|
---|
99 | #endregion
|
---|
100 |
|
---|
101 | public BestAverageWorstVRPToursAnalyzer()
|
---|
102 | : base() {
|
---|
103 | #region Create parameters
|
---|
104 | Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance."));
|
---|
105 |
|
---|
106 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Distance", "The distance of the VRP solutions which should be analyzed."));
|
---|
107 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestDistance", "The best distance value."));
|
---|
108 | Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentBestDistance", "The current best distance value."));
|
---|
109 | Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentAverageDistance", "The current average distance value of all solutions."));
|
---|
110 | Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentWorstDistance", "The current worst distance value of all solutions."));
|
---|
111 | Parameters.Add(new ValueLookupParameter<DataTable>("Distances", "The data table to store the current best, current average, current worst, best and best known distance value."));
|
---|
112 |
|
---|
113 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("VehiclesUtilized", "The vehicles utilized of the VRP solutions which should be analyzed."));
|
---|
114 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestVehiclesUtilized", "The best vehicles utilized value."));
|
---|
115 | Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentBestVehiclesUtilized", "The current best vehicles utilized value."));
|
---|
116 | Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentAverageVehiclesUtilized", "The current average vehicles utilized value of all solutions."));
|
---|
117 | Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentWorstVehiclesUtilized", "The current worst vehicles utilized value of all solutions."));
|
---|
118 | Parameters.Add(new ValueLookupParameter<DataTable>("VehiclesUtilizedValues", "The data table to store the current best, current average, current worst, best and best known vehicles utilized 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 | BestVRPToursMemorizer bestMemorizer = new BestVRPToursMemorizer();
|
---|
125 | BestAverageWorstVRPToursCalculator calculator = new BestAverageWorstVRPToursCalculator();
|
---|
126 | ResultsCollector resultsCollector = new ResultsCollector();
|
---|
127 |
|
---|
128 | //Distance
|
---|
129 | bestMemorizer.BestDistanceParameter.ActualName = BestDistanceParameter.Name;
|
---|
130 | bestMemorizer.DistanceParameter.ActualName = DistanceParameter.Name;
|
---|
131 | bestMemorizer.DistanceParameter.Depth = DistanceParameter.Depth;
|
---|
132 |
|
---|
133 | calculator.DistanceParameter.ActualName = DistanceParameter.Name;
|
---|
134 | calculator.DistanceParameter.Depth = DistanceParameter.Depth;
|
---|
135 | calculator.BestDistanceParameter.ActualName = CurrentBestDistanceParameter.Name;
|
---|
136 | calculator.AverageDistanceParameter.ActualName = CurrentAverageDistanceParameter.Name;
|
---|
137 | calculator.WorstDistanceParameter.ActualName = CurrentWorstDistanceParameter.Name;
|
---|
138 |
|
---|
139 | DataTableValuesCollector distanceDataTablesCollector = new DataTableValuesCollector();
|
---|
140 | distanceDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestDistance", null, BestDistanceParameter.Name));
|
---|
141 | distanceDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentBestDistance", null, CurrentBestDistanceParameter.Name));
|
---|
142 | distanceDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentAverageDistance", null, CurrentAverageDistanceParameter.Name));
|
---|
143 | distanceDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentWorstDistance", null, CurrentWorstDistanceParameter.Name));
|
---|
144 | distanceDataTablesCollector.DataTableParameter.ActualName = DistancesParameter.Name;
|
---|
145 |
|
---|
146 | resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(DistancesParameter.Name));
|
---|
147 |
|
---|
148 | //Vehicles Utlized
|
---|
149 | bestMemorizer.BestVehiclesUtilizedParameter.ActualName = BestVehiclesUtilizedParameter.Name;
|
---|
150 | bestMemorizer.VehiclesUtilizedParameter.ActualName = VehiclesUtilizedParameter.Name;
|
---|
151 | bestMemorizer.VehiclesUtilizedParameter.Depth = VehiclesUtilizedParameter.Depth;
|
---|
152 |
|
---|
153 | calculator.VehiclesUtilizedParameter.ActualName = VehiclesUtilizedParameter.Name;
|
---|
154 | calculator.VehiclesUtilizedParameter.Depth = VehiclesUtilizedParameter.Depth;
|
---|
155 | calculator.BestVehiclesUtilizedParameter.ActualName = CurrentBestVehiclesUtilizedParameter.Name;
|
---|
156 | calculator.AverageVehiclesUtilizedParameter.ActualName = CurrentAverageVehiclesUtilizedParameter.Name;
|
---|
157 | calculator.WorstVehiclesUtilizedParameter.ActualName = CurrentWorstVehiclesUtilizedParameter.Name;
|
---|
158 |
|
---|
159 | DataTableValuesCollector vehiclesUtilizedDataTablesCollector = new DataTableValuesCollector();
|
---|
160 | vehiclesUtilizedDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestVehiclesUtilized", null, BestVehiclesUtilizedParameter.Name));
|
---|
161 | vehiclesUtilizedDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentBestVehiclesUtilized", null, CurrentBestVehiclesUtilizedParameter.Name));
|
---|
162 | vehiclesUtilizedDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentAverageVehiclesUtilized", null, CurrentAverageVehiclesUtilizedParameter.Name));
|
---|
163 | vehiclesUtilizedDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentWorstVehiclesUtilized", null, CurrentWorstVehiclesUtilizedParameter.Name));
|
---|
164 | vehiclesUtilizedDataTablesCollector.DataTableParameter.ActualName = VehiclesUtilizedValuesParameter.Name;
|
---|
165 |
|
---|
166 | resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(VehiclesUtilizedValuesParameter.Name));
|
---|
167 | #endregion
|
---|
168 |
|
---|
169 | #region Create operator graph
|
---|
170 | OperatorGraph.InitialOperator = bestMemorizer;
|
---|
171 | bestMemorizer.Successor = calculator;
|
---|
172 | calculator.Successor = distanceDataTablesCollector;
|
---|
173 | distanceDataTablesCollector.Successor = vehiclesUtilizedDataTablesCollector;
|
---|
174 | vehiclesUtilizedDataTablesCollector.Successor = resultsCollector;
|
---|
175 | resultsCollector.Successor = null;
|
---|
176 | #endregion
|
---|
177 |
|
---|
178 | Initialize();
|
---|
179 | }
|
---|
180 | [StorableConstructor]
|
---|
181 | private BestAverageWorstVRPToursAnalyzer(bool deserializing) : base() { }
|
---|
182 |
|
---|
183 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
184 | return new BestAverageWorstVRPToursAnalyzer(this, cloner);
|
---|
185 | }
|
---|
186 |
|
---|
187 | private BestAverageWorstVRPToursAnalyzer(BestAverageWorstVRPToursAnalyzer original, Cloner cloner)
|
---|
188 | : base(original, cloner) {
|
---|
189 | this.Initialize();
|
---|
190 | }
|
---|
191 |
|
---|
192 | [StorableHook(HookType.AfterDeserialization)]
|
---|
193 | private void Initialize() {
|
---|
194 | DistanceParameter.DepthChanged += new EventHandler(DistanceParameter_DepthChanged);
|
---|
195 | VehiclesUtilizedParameter.DepthChanged += new EventHandler(VehiclesUtilizedParameter_DepthChanged);
|
---|
196 | }
|
---|
197 |
|
---|
198 | void DistanceParameter_DepthChanged(object sender, EventArgs e) {
|
---|
199 | BestAverageWorstCalculator.DistanceParameter.Depth = DistanceParameter.Depth;
|
---|
200 | BestMemorizer.DistanceParameter.Depth = DistanceParameter.Depth;
|
---|
201 | }
|
---|
202 |
|
---|
203 | void VehiclesUtilizedParameter_DepthChanged(object sender, EventArgs e) {
|
---|
204 | BestAverageWorstCalculator.VehiclesUtilizedParameter.Depth = VehiclesUtilizedParameter.Depth;
|
---|
205 | BestMemorizer.VehiclesUtilizedParameter.Depth = DistanceParameter.Depth;
|
---|
206 | }
|
---|
207 | }
|
---|
208 | }
|
---|