Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestAverageWorstTours/Capacitated/BestAverageWorstCapacitatedVRPToursAnalyzer.cs @ 13736

Last change on this file since 13736 was 12009, checked in by ascheibe, 10 years ago

#2212 updated copyright year

File size: 7.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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.Analysis;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Operators;
28using HeuristicLab.Optimization;
29using HeuristicLab.Optimization.Operators;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32using HeuristicLab.Problems.VehicleRouting.Interfaces;
33using HeuristicLab.Problems.VehicleRouting.Variants;
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    public bool EnabledByDefault {
72      get { return true; }
73    }
74    private BestCapacitatedVRPToursMemorizer BestMemorizer {
75      get { return (BestCapacitatedVRPToursMemorizer)OperatorGraph.InitialOperator; }
76    }
77    private BestAverageWorstCapacitatedVRPToursCalculator BestAverageWorstCalculator {
78      get { return (BestAverageWorstCapacitatedVRPToursCalculator)BestMemorizer.Successor; }
79    }
80    #endregion
81
82    public BestAverageWorstCapaciatatedVRPToursAnalyzer()
83      : base() {
84      #region Create parameters
85      Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance."));
86
87      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Overload", "The overloads of the VRP solutions which should be analyzed."));
88      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestOverload", "The best overload value."));
89      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentBestOverload", "The current best overload value."));
90      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentAverageOverload", "The current average overload value of all solutions."));
91      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentWorstOverload", "The current worst overload value of all solutions."));
92      Parameters.Add(new ValueLookupParameter<DataTable>("Overloads", "The data table to store the current best, current average, current worst, best and best known overload value."));
93
94      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The results collection where the analysis values should be stored."));
95      #endregion
96
97      #region Create operators
98      BestCapacitatedVRPToursMemorizer bestMemorizer = new BestCapacitatedVRPToursMemorizer();
99      BestAverageWorstCapacitatedVRPToursCalculator calculator = new BestAverageWorstCapacitatedVRPToursCalculator();
100      ResultsCollector resultsCollector = new ResultsCollector();
101
102      //overload
103      bestMemorizer.BestOverloadParameter.ActualName = BestOverloadParameter.Name;
104      bestMemorizer.OverloadParameter.ActualName = OverloadParameter.Name;
105      bestMemorizer.OverloadParameter.Depth = OverloadParameter.Depth;
106
107      calculator.OverloadParameter.ActualName = OverloadParameter.Name;
108      calculator.OverloadParameter.Depth = OverloadParameter.Depth;
109      calculator.BestOverloadParameter.ActualName = CurrentBestOverloadParameter.Name;
110      calculator.AverageOverloadParameter.ActualName = CurrentAverageOverloadParameter.Name;
111      calculator.WorstOverloadParameter.ActualName = CurrentWorstOverloadParameter.Name;
112
113      DataTableValuesCollector overloadDataTablesCollector = new DataTableValuesCollector();
114      overloadDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestOverload", null, BestOverloadParameter.Name));
115      overloadDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentBestOverload", null, CurrentBestOverloadParameter.Name));
116      overloadDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentAverageOverload", null, CurrentAverageOverloadParameter.Name));
117      overloadDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentWorstOverload", null, CurrentWorstOverloadParameter.Name));
118      overloadDataTablesCollector.DataTableParameter.ActualName = OverloadsParameter.Name;
119
120      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(OverloadsParameter.Name));
121      #endregion
122
123      #region Create operator graph
124      OperatorGraph.InitialOperator = bestMemorizer;
125      bestMemorizer.Successor = calculator;
126      calculator.Successor = overloadDataTablesCollector;
127      overloadDataTablesCollector.Successor = resultsCollector;
128      resultsCollector.Successor = null;
129      #endregion
130
131      Initialize();
132    }
133    [StorableConstructor]
134    private BestAverageWorstCapaciatatedVRPToursAnalyzer(bool deserializing) : base() { }
135
136    [StorableHook(HookType.AfterDeserialization)]
137    private void Initialize() {
138      OverloadParameter.DepthChanged += new EventHandler(OverloadParameter_DepthChanged);
139    }
140
141    public override IDeepCloneable Clone(Cloner cloner) {
142      return new BestAverageWorstCapaciatatedVRPToursAnalyzer(this, cloner);
143    }
144
145    private BestAverageWorstCapaciatatedVRPToursAnalyzer(BestAverageWorstCapaciatatedVRPToursAnalyzer original, Cloner cloner)
146      : base(original, cloner) {
147      this.Initialize();
148    }
149
150    void OverloadParameter_DepthChanged(object sender, EventArgs e) {
151      BestAverageWorstCalculator.OverloadParameter.Depth = OverloadParameter.Depth;
152      BestMemorizer.OverloadParameter.Depth = OverloadParameter.Depth;
153    }
154  }
155}
Note: See TracBrowser for help on using the repository browser.