[6710] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[11171] | 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6710] | 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 |
|
---|
| 22 | using System;
|
---|
[8053] | 23 | using HeuristicLab.Analysis;
|
---|
[6710] | 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 | using HeuristicLab.Operators;
|
---|
| 28 | using HeuristicLab.Optimization;
|
---|
| 29 | using HeuristicLab.Optimization.Operators;
|
---|
| 30 | using HeuristicLab.Parameters;
|
---|
| 31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[8053] | 32 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
[6710] | 33 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
| 34 |
|
---|
| 35 | namespace 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
|
---|
[7175] | 71 | public bool EnabledByDefault {
|
---|
| 72 | get { return true; }
|
---|
| 73 | }
|
---|
[6710] | 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() {
|
---|
[8053] | 84 | #region Create parameters
|
---|
[6710] | 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."));
|
---|
[8053] | 93 |
|
---|
[6710] | 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) {
|
---|
[8053] | 147 | this.Initialize();
|
---|
[6710] | 148 | }
|
---|
| 149 |
|
---|
| 150 | void PickupViolationsParameter_DepthChanged(object sender, EventArgs e) {
|
---|
| 151 | BestAverageWorstCalculator.PickupViolationsParameter.Depth = PickupViolationsParameter.Depth;
|
---|
| 152 | BestMemorizer.PickupViolationsParameter.Depth = PickupViolationsParameter.Depth;
|
---|
[8053] | 153 | }
|
---|
[6710] | 154 | }
|
---|
| 155 | }
|
---|