Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestAverageWorstTours/BestAverageWorstVRPToursAnalyzer.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.8 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("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    private BestVRPToursMemorizer BestMemorizer {
91      get { return (BestVRPToursMemorizer)OperatorGraph.InitialOperator; }
92    }
93    private BestAverageWorstVRPToursCalculator BestAverageWorstCalculator {
94      get { return (BestAverageWorstVRPToursCalculator)BestMemorizer.Successor; }
95    }
96    #endregion
97
98    public BestAverageWorstVRPToursAnalyzer()
99      : base() {
100      #region Create parameters
101      Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance."));
102
103      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Distance", "The distance of the VRP solutions which should be analyzed."));
104      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestDistance", "The best distance value."));
105      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentBestDistance", "The current best distance value."));
106      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentAverageDistance", "The current average distance value of all solutions."));
107      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentWorstDistance", "The current worst distance value of all solutions."));
108      Parameters.Add(new ValueLookupParameter<DataTable>("Distances", "The data table to store the current best, current average, current worst, best and best known distance value."));
109
110      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("VehiclesUtilized", "The vehicles utilized of the VRP solutions which should be analyzed."));
111      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestVehiclesUtilized", "The best  vehicles utilized value."));
112      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentBestVehiclesUtilized", "The current best  vehicles utilized value."));
113      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentAverageVehiclesUtilized", "The current average  vehicles utilized value of all solutions."));
114      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentWorstVehiclesUtilized", "The current worst  vehicles utilized value of all solutions."));
115      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."));
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      BestVRPToursMemorizer bestMemorizer = new BestVRPToursMemorizer();
122      BestAverageWorstVRPToursCalculator calculator = new BestAverageWorstVRPToursCalculator();
123      ResultsCollector resultsCollector = new ResultsCollector();
124
125      //Distance
126      bestMemorizer.BestDistanceParameter.ActualName = BestDistanceParameter.Name;
127      bestMemorizer.DistanceParameter.ActualName = DistanceParameter.Name;
128      bestMemorizer.DistanceParameter.Depth = DistanceParameter.Depth;
129
130      calculator.DistanceParameter.ActualName = DistanceParameter.Name;
131      calculator.DistanceParameter.Depth = DistanceParameter.Depth;
132      calculator.BestDistanceParameter.ActualName = CurrentBestDistanceParameter.Name;
133      calculator.AverageDistanceParameter.ActualName = CurrentAverageDistanceParameter.Name;
134      calculator.WorstDistanceParameter.ActualName = CurrentWorstDistanceParameter.Name;
135
136      DataTableValuesCollector distanceDataTablesCollector = new DataTableValuesCollector();
137      distanceDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestDistance", null, BestDistanceParameter.Name));
138      distanceDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentBestDistance", null, CurrentBestDistanceParameter.Name));
139      distanceDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentAverageDistance", null, CurrentAverageDistanceParameter.Name));
140      distanceDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentWorstDistance", null, CurrentWorstDistanceParameter.Name));
141      distanceDataTablesCollector.DataTableParameter.ActualName = DistancesParameter.Name;
142
143      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(DistancesParameter.Name));
144
145      //Vehicles Utlized
146      bestMemorizer.BestVehiclesUtilizedParameter.ActualName = BestVehiclesUtilizedParameter.Name;
147      bestMemorizer.VehiclesUtilizedParameter.ActualName = VehiclesUtilizedParameter.Name;
148      bestMemorizer.VehiclesUtilizedParameter.Depth = VehiclesUtilizedParameter.Depth;
149
150      calculator.VehiclesUtilizedParameter.ActualName = VehiclesUtilizedParameter.Name;
151      calculator.VehiclesUtilizedParameter.Depth = VehiclesUtilizedParameter.Depth;
152      calculator.BestVehiclesUtilizedParameter.ActualName = CurrentBestVehiclesUtilizedParameter.Name;
153      calculator.AverageVehiclesUtilizedParameter.ActualName = CurrentAverageVehiclesUtilizedParameter.Name;
154      calculator.WorstVehiclesUtilizedParameter.ActualName = CurrentWorstVehiclesUtilizedParameter.Name;
155
156      DataTableValuesCollector vehiclesUtilizedDataTablesCollector = new DataTableValuesCollector();
157      vehiclesUtilizedDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestVehiclesUtilized", null, BestVehiclesUtilizedParameter.Name));
158      vehiclesUtilizedDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentBestVehiclesUtilized", null, CurrentBestVehiclesUtilizedParameter.Name));
159      vehiclesUtilizedDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentAverageVehiclesUtilized", null, CurrentAverageVehiclesUtilizedParameter.Name));
160      vehiclesUtilizedDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentWorstVehiclesUtilized", null, CurrentWorstVehiclesUtilizedParameter.Name));
161      vehiclesUtilizedDataTablesCollector.DataTableParameter.ActualName = VehiclesUtilizedValuesParameter.Name;
162
163      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(VehiclesUtilizedValuesParameter.Name));
164      #endregion
165
166      #region Create operator graph
167      OperatorGraph.InitialOperator = bestMemorizer;
168      bestMemorizer.Successor = calculator;
169      calculator.Successor = distanceDataTablesCollector;
170      distanceDataTablesCollector.Successor = vehiclesUtilizedDataTablesCollector;
171      vehiclesUtilizedDataTablesCollector.Successor = resultsCollector;
172      resultsCollector.Successor = null;
173      #endregion
174
175      Initialize();
176    }
177    [StorableConstructor]
178    private BestAverageWorstVRPToursAnalyzer(bool deserializing) : base() { }
179
180    [StorableHook(HookType.AfterDeserialization)]
181    private void Initialize() {
182      DistanceParameter.DepthChanged += new EventHandler(DistanceParameter_DepthChanged);
183      VehiclesUtilizedParameter.DepthChanged += new EventHandler(VehiclesUtilizedParameter_DepthChanged);
184    }
185
186    public override IDeepCloneable Clone(Cloner cloner) {
187      BestAverageWorstVRPToursAnalyzer clone = (BestAverageWorstVRPToursAnalyzer)base.Clone(cloner);
188      clone.Initialize();
189      return clone;
190    }
191
192    void DistanceParameter_DepthChanged(object sender, EventArgs e) {
193      BestAverageWorstCalculator.DistanceParameter.Depth = DistanceParameter.Depth;
194      BestMemorizer.DistanceParameter.Depth = DistanceParameter.Depth;
195    }
196
197    void VehiclesUtilizedParameter_DepthChanged(object sender, EventArgs e) {
198      BestAverageWorstCalculator.VehiclesUtilizedParameter.Depth = VehiclesUtilizedParameter.Depth;
199      BestMemorizer.VehiclesUtilizedParameter.Depth = DistanceParameter.Depth;
200    }
201  }
202}
Note: See TracBrowser for help on using the repository browser.