Free cookie consent management tool by TermsFeed Policy Generator

source: branches/crossvalidation-2434/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestAverageWorstTours/PickupAndDelivery/BestAverageWorstPickupAndDeliveryVRPToursAnalyzer.cs @ 13495

Last change on this file since 13495 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

File size: 8.4 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("BestAverageWorstPickupAndDeliveryVRPToursAnalyzer", "An operator which analyzes the best, average and worst properties of the VRP tours in the scope tree.")]
40  [StorableClass]
41  public sealed class BestAverageWorstPickupAndDeliveryVRPToursAnalyzer : AlgorithmOperator, IAnalyzer, IPickupAndDeliveryOperator {
42    #region Parameter properties
43    public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter {
44      get { return (ILookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; }
45    }
46    public ScopeTreeLookupParameter<IntValue> PickupViolationsParameter {
47      get { return (ScopeTreeLookupParameter<IntValue>)Parameters["PickupViolations"]; }
48    }
49    public ValueLookupParameter<IntValue> BestPickupViolationsParameter {
50      get { return (ValueLookupParameter<IntValue>)Parameters["BestPickupViolations"]; }
51    }
52    public ValueLookupParameter<IntValue> CurrentBestPickupViolationsParameter {
53      get { return (ValueLookupParameter<IntValue>)Parameters["CurrentBestPickupViolations"]; }
54    }
55    public ValueLookupParameter<DoubleValue> CurrentAveragePickupViolationsParameter {
56      get { return (ValueLookupParameter<DoubleValue>)Parameters["CurrentAveragePickupViolations"]; }
57    }
58    public ValueLookupParameter<IntValue> CurrentWorstPickupViolationsParameter {
59      get { return (ValueLookupParameter<IntValue>)Parameters["CurrentWorstPickupViolations"]; }
60    }
61    public ValueLookupParameter<DataTable> PickupViolationsValuesParameter {
62      get { return (ValueLookupParameter<DataTable>)Parameters["PickupViolationsValues"]; }
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 BestPickupAndDeliveryVRPToursMemorizer BestMemorizer {
75      get { return (BestPickupAndDeliveryVRPToursMemorizer)OperatorGraph.InitialOperator; }
76    }
77    private BestAverageWorstPickupAndDeliveryVRPToursCalculator BestAverageWorstCalculator {
78      get { return (BestAverageWorstPickupAndDeliveryVRPToursCalculator)BestMemorizer.Successor; }
79    }
80    #endregion
81
82    public BestAverageWorstPickupAndDeliveryVRPToursAnalyzer()
83      : base() {
84      #region Create parameters
85      Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance."));
86
87      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("PickupViolations", "The pickup violations of the VRP solutions which should be analyzed."));
88      Parameters.Add(new ValueLookupParameter<IntValue>("BestPickupViolations", "The best pickup violations value."));
89      Parameters.Add(new ValueLookupParameter<IntValue>("CurrentBestPickupViolations", "The current best pickup violations value."));
90      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentAveragePickupViolations", "The current average pickup violations value of all solutions."));
91      Parameters.Add(new ValueLookupParameter<IntValue>("CurrentWorstPickupViolations", "The current worst pickup violations value of all solutions."));
92      Parameters.Add(new ValueLookupParameter<DataTable>("PickupViolationsValues", "The data table to store the current best, current average, current worst, best and best known pickup violations 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      BestPickupAndDeliveryVRPToursMemorizer bestMemorizer = new BestPickupAndDeliveryVRPToursMemorizer();
99      BestAverageWorstPickupAndDeliveryVRPToursCalculator calculator = new BestAverageWorstPickupAndDeliveryVRPToursCalculator();
100      ResultsCollector resultsCollector = new ResultsCollector();
101
102      //pickup violations
103      bestMemorizer.BestPickupViolationsParameter.ActualName = BestPickupViolationsParameter.Name;
104      bestMemorizer.PickupViolationsParameter.ActualName = PickupViolationsParameter.Name;
105      bestMemorizer.PickupViolationsParameter.Depth = PickupViolationsParameter.Depth;
106
107      calculator.PickupViolationsParameter.ActualName = PickupViolationsParameter.Name;
108      calculator.PickupViolationsParameter.Depth = PickupViolationsParameter.Depth;
109      calculator.BestPickupViolationsParameter.ActualName = CurrentBestPickupViolationsParameter.Name;
110      calculator.AveragePickupViolationsParameter.ActualName = CurrentAveragePickupViolationsParameter.Name;
111      calculator.WorstPickupViolationsParameter.ActualName = CurrentWorstPickupViolationsParameter.Name;
112
113      DataTableValuesCollector pickupViolationsDataTablesCollector = new DataTableValuesCollector();
114      pickupViolationsDataTablesCollector.CollectedValues.Add(new LookupParameter<IntValue>("BestPickupViolations", null, BestPickupViolationsParameter.Name));
115      pickupViolationsDataTablesCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentBestPickupViolations", null, CurrentBestPickupViolationsParameter.Name));
116      pickupViolationsDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentAveragePickupViolations", null, CurrentAveragePickupViolationsParameter.Name));
117      pickupViolationsDataTablesCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentWorstPickupViolations", null, CurrentWorstPickupViolationsParameter.Name));
118      pickupViolationsDataTablesCollector.DataTableParameter.ActualName = PickupViolationsValuesParameter.Name;
119
120      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(PickupViolationsValuesParameter.Name));
121      #endregion
122
123      #region Create operator graph
124      OperatorGraph.InitialOperator = bestMemorizer;
125      bestMemorizer.Successor = calculator;
126      calculator.Successor = pickupViolationsDataTablesCollector;
127      pickupViolationsDataTablesCollector.Successor = resultsCollector;
128      resultsCollector.Successor = null;
129      #endregion
130
131      Initialize();
132    }
133    [StorableConstructor]
134    private BestAverageWorstPickupAndDeliveryVRPToursAnalyzer(bool deserializing) : base() { }
135
136    [StorableHook(HookType.AfterDeserialization)]
137    private void Initialize() {
138      PickupViolationsParameter.DepthChanged += new EventHandler(PickupViolationsParameter_DepthChanged);
139    }
140
141    public override IDeepCloneable Clone(Cloner cloner) {
142      return new BestAverageWorstPickupAndDeliveryVRPToursAnalyzer(this, cloner);
143    }
144
145    private BestAverageWorstPickupAndDeliveryVRPToursAnalyzer(BestAverageWorstPickupAndDeliveryVRPToursAnalyzer original, Cloner cloner)
146      : base(original, cloner) {
147      this.Initialize();
148    }
149
150    void PickupViolationsParameter_DepthChanged(object sender, EventArgs e) {
151      BestAverageWorstCalculator.PickupViolationsParameter.Depth = PickupViolationsParameter.Depth;
152      BestMemorizer.PickupViolationsParameter.Depth = PickupViolationsParameter.Depth;
153    }
154  }
155}
Note: See TracBrowser for help on using the repository browser.