Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestAverageWorstTours/PickupAndDeliveryTourAnalyzer.cs

Last change on this file was 17717, checked in by abeham, 4 years ago

#2521: working on VRP (refactoring all the capabilities, features, and operator discovery)

File size: 3.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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.Linq;
23using HEAL.Attic;
24using HeuristicLab.Analysis;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Operators;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Problems.VehicleRouting.Interfaces;
31using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
32
33namespace HeuristicLab.Problems.VehicleRouting {
34  /// <summary>
35  /// An operator which analyzes the best, average and worst quality of solutions in the scope tree.
36  /// </summary>
37  [Item("Pickup & Delivery Tour Analyzer", "An operator which analyzes the best, average and worst properties of the VRP tours in the scope tree.")]
38  [StorableType("0a108965-fb1a-47a3-a5d4-11d1bfa51b0d")]
39  public sealed class PickupAndDeliveryTourAnalyzer : InstrumentedOperator, IAnalyzer, IPickupAndDeliveryOperator {
40    [Storable] public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter { get; private set; }
41    [Storable] public IScopeTreeLookupParameter<CVRPPDTWEvaluation> EvaluationResultParameter { get; private set; }
42
43    [Storable] public IResultParameter<DataTable> PickupViolationsResult { get; private set; }
44
45    public bool EnabledByDefault {
46      get { return true; }
47    }
48
49    [StorableConstructor]
50    private PickupAndDeliveryTourAnalyzer(StorableConstructorFlag _) : base(_) { }
51    private PickupAndDeliveryTourAnalyzer(PickupAndDeliveryTourAnalyzer original, Cloner cloner)
52      : base(original, cloner) {
53      ProblemInstanceParameter = cloner.Clone(original.ProblemInstanceParameter);
54      EvaluationResultParameter = cloner.Clone(original.EvaluationResultParameter);
55      PickupViolationsResult = cloner.Clone(original.PickupViolationsResult);
56    }
57    public PickupAndDeliveryTourAnalyzer()
58      : base() {
59      Parameters.Add(ProblemInstanceParameter = new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance."));
60      Parameters.Add(EvaluationResultParameter = new ScopeTreeLookupParameter<CVRPPDTWEvaluation>("EvaluationResult", "The evaluations of the VRP solutions which should be analyzed."));
61      DataTable defaultPickupViolationsTable = new DataTable("Pickup Violations");
62      Parameters.Add(PickupViolationsResult = new ResultParameter<DataTable>("Pickup Violations", "The solution pickup violation progress in each iteration.", defaultPickupViolationsTable));
63
64      defaultPickupViolationsTable.Rows.Add(new DataRow("Best (monotonic)"));
65      defaultPickupViolationsTable.Rows.Add(new DataRow("Best"));
66      defaultPickupViolationsTable.Rows.Add(new DataRow("Average"));
67      defaultPickupViolationsTable.Rows.Add(new DataRow("Worst"));
68    }
69
70    public override IDeepCloneable Clone(Cloner cloner) {
71      return new PickupAndDeliveryTourAnalyzer(this, cloner);
72    }
73
74    public override IOperation InstrumentedApply() {
75      var evaluations = EvaluationResultParameter.ActualValue;
76      var pickupViolations = evaluations.Select(x => (double)x.PickupViolations);
77
78      BasicVRPTourAnalyzer.Analyze(pickupViolations, PickupViolationsResult.ActualValue);
79
80      return base.InstrumentedApply();
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.