Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestAverageWorstTours/TimeWindowed/BestAverageWorstTimeWindowedVRPToursAnalyzer.cs @ 4374

Last change on this file since 4374 was 4374, checked in by svonolfe, 14 years ago

Added analyzers and views (#1177)

File size: 11.7 KB
Line 
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
22using System;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Optimization.Operators;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31using HeuristicLab.Analysis;
32using HeuristicLab.Problems.VehicleRouting.Variants;
33using HeuristicLab.Problems.VehicleRouting.Interfaces;
34
35namespace 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    private BestTimeWindowedVRPToursMemorizer BestMemorizer {
91      get { return (BestTimeWindowedVRPToursMemorizer)OperatorGraph.InitialOperator; }
92    }
93    private BestAverageWorstTimeWindowedVRPToursCalculator BestAverageWorstCalculator {
94      get { return (BestAverageWorstTimeWindowedVRPToursCalculator)BestMemorizer.Successor; }
95    }
96    #endregion
97
98    public BestAverageWorstTimeWindowedVRPToursAnalyzer()
99      : base() {
100      #region Create parameters
101      Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance."));
102
103      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Tardiness", "The tardiness of the VRP solutions which should be analyzed."));
104      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestTardiness", "The best tardiness value."));
105      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentBestTardiness", "The current best tardiness value."));
106      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentAverageTardiness", "The current average tardiness value of all solutions."));
107      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentWorstTardiness", "The current worst tardiness value of all solutions."));
108      Parameters.Add(new ValueLookupParameter<DataTable>("TardinessValues", "The data table to store the current best, current average, current worst, best and best known tardiness value."));
109
110      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("TravelTime", "The travel time of the VRP solutions which should be analyzed."));
111      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestTravelTime", "The best travel time value."));
112      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentBestTravelTime", "The current best travel time value."));
113      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentAverageTravelTime", "The current average travel time value of all solutions."));
114      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentWorstTravelTime", "The current worst travel time value of all solutions."));
115      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."));
116
117      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The results collection where the analysis values should be stored."));
118      #endregion
119
120      #region Create operators
121      BestTimeWindowedVRPToursMemorizer bestMemorizer = new BestTimeWindowedVRPToursMemorizer();
122      BestAverageWorstTimeWindowedVRPToursCalculator calculator = new BestAverageWorstTimeWindowedVRPToursCalculator();
123      ResultsCollector resultsCollector = new ResultsCollector();
124
125      //tardiness
126      bestMemorizer.BestTardinessParameter.ActualName = BestTardinessParameter.Name;
127      bestMemorizer.TardinessParameter.ActualName = TardinessParameter.Name;
128      bestMemorizer.TardinessParameter.Depth = TardinessParameter.Depth;
129
130      calculator.TardinessParameter.ActualName = TardinessParameter.Name;
131      calculator.TardinessParameter.Depth = TardinessParameter.Depth;
132      calculator.BestTardinessParameter.ActualName = CurrentBestTardinessParameter.Name;
133      calculator.AverageTardinessParameter.ActualName = CurrentAverageTardinessParameter.Name;
134      calculator.WorstTardinessParameter.ActualName = CurrentWorstTardinessParameter.Name;
135
136      DataTableValuesCollector tardinessDataTablesCollector = new DataTableValuesCollector();
137      tardinessDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestTardiness", null, BestTardinessParameter.Name));
138      tardinessDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentBestTardiness", null, CurrentBestTardinessParameter.Name));
139      tardinessDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentAverageTardiness", null, CurrentAverageTardinessParameter.Name));
140      tardinessDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentWorstTardiness", null, CurrentWorstTardinessParameter.Name));
141      tardinessDataTablesCollector.DataTableParameter.ActualName = TardinessValuesParameter.Name;
142
143      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(TardinessValuesParameter.Name));
144
145      //Travel Time
146      bestMemorizer.BestTravelTimeParameter.ActualName = BestTravelTimeParameter.Name;
147      bestMemorizer.TravelTimeParameter.ActualName = TravelTimeParameter.Name;
148      bestMemorizer.TravelTimeParameter.Depth = TravelTimeParameter.Depth;
149
150      calculator.TravelTimeParameter.ActualName = TravelTimeParameter.Name;
151      calculator.TravelTimeParameter.Depth = TravelTimeParameter.Depth;
152      calculator.BestTravelTimeParameter.ActualName = CurrentBestTravelTimeParameter.Name;
153      calculator.AverageTravelTimeParameter.ActualName = CurrentAverageTravelTimeParameter.Name;
154      calculator.WorstTravelTimeParameter.ActualName = CurrentWorstTravelTimeParameter.Name;
155
156      DataTableValuesCollector travelTimeDataTablesCollector = new DataTableValuesCollector();
157      travelTimeDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestTravelTime", null, BestTravelTimeParameter.Name));
158      travelTimeDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentBestTravelTime", null, CurrentBestTravelTimeParameter.Name));
159      travelTimeDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentAverageTravelTime", null, CurrentAverageTravelTimeParameter.Name));
160      travelTimeDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentWorstTravelTime", null, CurrentWorstTravelTimeParameter.Name));
161      travelTimeDataTablesCollector.DataTableParameter.ActualName = TravelTimesParameter.Name;
162
163      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(TravelTimesParameter.Name));
164      #endregion
165
166      #region Create operator graph
167      OperatorGraph.InitialOperator = bestMemorizer;
168      bestMemorizer.Successor = calculator;
169      calculator.Successor = tardinessDataTablesCollector;
170      tardinessDataTablesCollector.Successor = travelTimeDataTablesCollector;
171      travelTimeDataTablesCollector.Successor = resultsCollector;
172      resultsCollector.Successor = null;
173      #endregion
174
175      Initialize();
176    }
177    [StorableConstructor]
178    private BestAverageWorstTimeWindowedVRPToursAnalyzer(bool deserializing) : base() { }
179
180    [StorableHook(HookType.AfterDeserialization)]
181    private void Initialize() {
182      TardinessParameter.DepthChanged += new EventHandler(TardinessParameter_DepthChanged);
183      TravelTimeParameter.DepthChanged += new EventHandler(TravelTimeParameter_DepthChanged);
184    }
185
186    public override IDeepCloneable Clone(Cloner cloner) {
187      BestAverageWorstTimeWindowedVRPToursAnalyzer clone = (BestAverageWorstTimeWindowedVRPToursAnalyzer)base.Clone(cloner);
188      clone.Initialize();
189      return clone;
190    }
191
192    void TardinessParameter_DepthChanged(object sender, EventArgs e) {
193      BestAverageWorstCalculator.TardinessParameter.Depth = TardinessParameter.Depth;
194      BestMemorizer.TardinessParameter.Depth = TardinessParameter.Depth;
195    }
196
197    void TravelTimeParameter_DepthChanged(object sender, EventArgs e) {
198      BestAverageWorstCalculator.TravelTimeParameter.Depth = TravelTimeParameter.Depth;
199      BestMemorizer.TravelTimeParameter.Depth = TravelTimeParameter.Depth;
200    }
201  }
202}
Note: See TracBrowser for help on using the repository browser.