Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestAverageWorstTours/Capacitated/BestAverageWorstCapacitatedVRPToursAnalyzer.cs @ 4376

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

Added Potvin encoding (#1177)

File size: 7.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("BestAverageWorstCapaciatatedVRPToursAnalyzer", "An operator which analyzes the best, average and worst properties of the VRP tours in the scope tree.")]
40  [StorableClass]
41  public sealed class BestAverageWorstCapaciatatedVRPToursAnalyzer : AlgorithmOperator, IAnalyzer, IHomogenousCapacitatedOperator {
42    #region Parameter properties
43    public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter {
44      get { return (ILookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; }
45    }
46    public ScopeTreeLookupParameter<DoubleValue> OverloadParameter {
47      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Overload"]; }
48    }
49    public ValueLookupParameter<DoubleValue> BestOverloadParameter {
50      get { return (ValueLookupParameter<DoubleValue>)Parameters["BestOverload"]; }
51    }
52    public ValueLookupParameter<DoubleValue> CurrentBestOverloadParameter {
53      get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentBestOverload"]; }
54    }
55    public ValueLookupParameter<DoubleValue> CurrentAverageOverloadParameter {
56      get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentAverageOverload"]; }
57    }
58    public ValueLookupParameter<DoubleValue> CurrentWorstOverloadParameter {
59      get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentWorstOverload"]; }
60    }
61    public ValueLookupParameter<DataTable> OverloadsParameter {
62      get { return (ValueLookupParameter<DataTable>)Parameters["Overloads"]; }
63    }
64
65    public ValueLookupParameter<VariableCollection> ResultsParameter {
66      get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
67    }
68    #endregion
69
70    #region Properties
71    private BestCapacitatedVRPToursMemorizer BestMemorizer {
72      get { return (BestCapacitatedVRPToursMemorizer)OperatorGraph.InitialOperator; }
73    }
74    private BestAverageWorstCapacitatedVRPToursCalculator BestAverageWorstCalculator {
75      get { return (BestAverageWorstCapacitatedVRPToursCalculator)BestMemorizer.Successor; }
76    }
77    #endregion
78
79    public BestAverageWorstCapaciatatedVRPToursAnalyzer()
80      : base() {
81      #region Create parameters
82      Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance."));
83
84      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Overload", "The overloads of the VRP solutions which should be analyzed."));
85      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestOverload", "The best overload value."));
86      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentBestOverload", "The current best overload value."));
87      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentAverageOverload", "The current average overload value of all solutions."));
88      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentWorstOverload", "The current worst overload value of all solutions."));
89      Parameters.Add(new ValueLookupParameter<DataTable>("Overloads", "The data table to store the current best, current average, current worst, best and best known overload value."));
90 
91      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The results collection where the analysis values should be stored."));
92      #endregion
93
94      #region Create operators
95      BestCapacitatedVRPToursMemorizer bestMemorizer = new BestCapacitatedVRPToursMemorizer();
96      BestAverageWorstCapacitatedVRPToursCalculator calculator = new BestAverageWorstCapacitatedVRPToursCalculator();
97      ResultsCollector resultsCollector = new ResultsCollector();
98
99      //overload
100      bestMemorizer.BestOverloadParameter.ActualName = BestOverloadParameter.Name;
101      bestMemorizer.OverloadParameter.ActualName = OverloadParameter.Name;
102      bestMemorizer.OverloadParameter.Depth = OverloadParameter.Depth;
103
104      calculator.OverloadParameter.ActualName = OverloadParameter.Name;
105      calculator.OverloadParameter.Depth = OverloadParameter.Depth;
106      calculator.BestOverloadParameter.ActualName = CurrentBestOverloadParameter.Name;
107      calculator.AverageOverloadParameter.ActualName = CurrentAverageOverloadParameter.Name;
108      calculator.WorstOverloadParameter.ActualName = CurrentWorstOverloadParameter.Name;
109
110      DataTableValuesCollector overloadDataTablesCollector = new DataTableValuesCollector();
111      overloadDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestOverload", null, BestOverloadParameter.Name));
112      overloadDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentBestOverload", null, CurrentBestOverloadParameter.Name));
113      overloadDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentAverageOverload", null, CurrentAverageOverloadParameter.Name));
114      overloadDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentWorstOverload", null, CurrentWorstOverloadParameter.Name));
115      overloadDataTablesCollector.DataTableParameter.ActualName = OverloadsParameter.Name;
116
117      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(OverloadsParameter.Name));
118      #endregion
119
120      #region Create operator graph
121      OperatorGraph.InitialOperator = bestMemorizer;
122      bestMemorizer.Successor = calculator;
123      calculator.Successor = overloadDataTablesCollector;
124      overloadDataTablesCollector.Successor = resultsCollector;
125      resultsCollector.Successor = null;
126      #endregion
127
128      Initialize();
129    }
130    [StorableConstructor]
131    private BestAverageWorstCapaciatatedVRPToursAnalyzer(bool deserializing) : base() { }
132
133    [StorableHook(HookType.AfterDeserialization)]
134    private void Initialize() {
135      OverloadParameter.DepthChanged += new EventHandler(OverloadParameter_DepthChanged);
136    }
137
138    public override IDeepCloneable Clone(Cloner cloner) {
139      BestAverageWorstCapaciatatedVRPToursAnalyzer clone = (BestAverageWorstCapaciatatedVRPToursAnalyzer)base.Clone(cloner);
140      clone.Initialize();
141      return clone;
142    }
143
144    void OverloadParameter_DepthChanged(object sender, EventArgs e) {
145      BestAverageWorstCalculator.OverloadParameter.Depth = OverloadParameter.Depth;
146      BestMemorizer.OverloadParameter.Depth = OverloadParameter.Depth;
147    }
148  }
149}
Note: See TracBrowser for help on using the repository browser.