Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestAverageWorstTours/PickupAndDelivery/BestAverageWorstPickupAndDeliveryVRPToursAnalyzer.cs @ 6710

Last change on this file since 6710 was 6710, checked in by svonolfe, 13 years ago

Added support for pickups and deliveries (#1177)

File size: 8.4 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("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    private BestPickupAndDeliveryVRPToursMemorizer BestMemorizer {
72      get { return (BestPickupAndDeliveryVRPToursMemorizer)OperatorGraph.InitialOperator; }
73    }
74    private BestAverageWorstPickupAndDeliveryVRPToursCalculator BestAverageWorstCalculator {
75      get { return (BestAverageWorstPickupAndDeliveryVRPToursCalculator)BestMemorizer.Successor; }
76    }
77    #endregion
78
79    public BestAverageWorstPickupAndDeliveryVRPToursAnalyzer()
80      : base() {
81      #region Create parameters
82      Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance."));
83
84      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("PickupViolations", "The pickup violations of the VRP solutions which should be analyzed."));
85      Parameters.Add(new ValueLookupParameter<IntValue>("BestPickupViolations", "The best pickup violations value."));
86      Parameters.Add(new ValueLookupParameter<IntValue>("CurrentBestPickupViolations", "The current best pickup violations value."));
87      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentAveragePickupViolations", "The current average pickup violations value of all solutions."));
88      Parameters.Add(new ValueLookupParameter<IntValue>("CurrentWorstPickupViolations", "The current worst pickup violations value of all solutions."));
89      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."));
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      BestPickupAndDeliveryVRPToursMemorizer bestMemorizer = new BestPickupAndDeliveryVRPToursMemorizer();
96      BestAverageWorstPickupAndDeliveryVRPToursCalculator calculator = new BestAverageWorstPickupAndDeliveryVRPToursCalculator();
97      ResultsCollector resultsCollector = new ResultsCollector();
98
99      //pickup violations
100      bestMemorizer.BestPickupViolationsParameter.ActualName = BestPickupViolationsParameter.Name;
101      bestMemorizer.PickupViolationsParameter.ActualName = PickupViolationsParameter.Name;
102      bestMemorizer.PickupViolationsParameter.Depth = PickupViolationsParameter.Depth;
103
104      calculator.PickupViolationsParameter.ActualName = PickupViolationsParameter.Name;
105      calculator.PickupViolationsParameter.Depth = PickupViolationsParameter.Depth;
106      calculator.BestPickupViolationsParameter.ActualName = CurrentBestPickupViolationsParameter.Name;
107      calculator.AveragePickupViolationsParameter.ActualName = CurrentAveragePickupViolationsParameter.Name;
108      calculator.WorstPickupViolationsParameter.ActualName = CurrentWorstPickupViolationsParameter.Name;
109
110      DataTableValuesCollector pickupViolationsDataTablesCollector = new DataTableValuesCollector();
111      pickupViolationsDataTablesCollector.CollectedValues.Add(new LookupParameter<IntValue>("BestPickupViolations", null, BestPickupViolationsParameter.Name));
112      pickupViolationsDataTablesCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentBestPickupViolations", null, CurrentBestPickupViolationsParameter.Name));
113      pickupViolationsDataTablesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentAveragePickupViolations", null, CurrentAveragePickupViolationsParameter.Name));
114      pickupViolationsDataTablesCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentWorstPickupViolations", null, CurrentWorstPickupViolationsParameter.Name));
115      pickupViolationsDataTablesCollector.DataTableParameter.ActualName = PickupViolationsValuesParameter.Name;
116
117      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(PickupViolationsValuesParameter.Name));
118      #endregion
119
120      #region Create operator graph
121      OperatorGraph.InitialOperator = bestMemorizer;
122      bestMemorizer.Successor = calculator;
123      calculator.Successor = pickupViolationsDataTablesCollector;
124      pickupViolationsDataTablesCollector.Successor = resultsCollector;
125      resultsCollector.Successor = null;
126      #endregion
127
128      Initialize();
129    }
130    [StorableConstructor]
131    private BestAverageWorstPickupAndDeliveryVRPToursAnalyzer(bool deserializing) : base() { }
132
133    [StorableHook(HookType.AfterDeserialization)]
134    private void Initialize() {
135      PickupViolationsParameter.DepthChanged += new EventHandler(PickupViolationsParameter_DepthChanged);
136    }
137
138    public override IDeepCloneable Clone(Cloner cloner) {
139      return new BestAverageWorstPickupAndDeliveryVRPToursAnalyzer(this, cloner);
140    }
141
142    private BestAverageWorstPickupAndDeliveryVRPToursAnalyzer(BestAverageWorstPickupAndDeliveryVRPToursAnalyzer original, Cloner cloner)
143      : base(original, cloner) {
144        this.Initialize();
145    }
146
147    void PickupViolationsParameter_DepthChanged(object sender, EventArgs e) {
148      BestAverageWorstCalculator.PickupViolationsParameter.Depth = PickupViolationsParameter.Depth;
149      BestMemorizer.PickupViolationsParameter.Depth = PickupViolationsParameter.Depth;
150    }
151  }
152}
Note: See TracBrowser for help on using the repository browser.