#region License Information
/* HeuristicLab
* Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using HeuristicLab.Analysis;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Operators;
using HeuristicLab.Optimization;
using HeuristicLab.Optimization.Operators;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.Problems.VehicleRouting.Interfaces;
using HeuristicLab.Problems.VehicleRouting.Variants;
namespace HeuristicLab.Problems.VehicleRouting {
///
/// An operator which analyzes the best, average and worst quality of solutions in the scope tree.
///
[Item("BestAverageWorstPickupAndDeliveryVRPToursAnalyzer", "An operator which analyzes the best, average and worst properties of the VRP tours in the scope tree.")]
[StorableClass]
public sealed class BestAverageWorstPickupAndDeliveryVRPToursAnalyzer : AlgorithmOperator, IAnalyzer, IPickupAndDeliveryOperator {
#region Parameter properties
public ILookupParameter ProblemInstanceParameter {
get { return (ILookupParameter)Parameters["ProblemInstance"]; }
}
public ScopeTreeLookupParameter PickupViolationsParameter {
get { return (ScopeTreeLookupParameter)Parameters["PickupViolations"]; }
}
public ValueLookupParameter BestPickupViolationsParameter {
get { return (ValueLookupParameter)Parameters["BestPickupViolations"]; }
}
public ValueLookupParameter CurrentBestPickupViolationsParameter {
get { return (ValueLookupParameter)Parameters["CurrentBestPickupViolations"]; }
}
public ValueLookupParameter CurrentAveragePickupViolationsParameter {
get { return (ValueLookupParameter)Parameters["CurrentAveragePickupViolations"]; }
}
public ValueLookupParameter CurrentWorstPickupViolationsParameter {
get { return (ValueLookupParameter)Parameters["CurrentWorstPickupViolations"]; }
}
public ValueLookupParameter PickupViolationsValuesParameter {
get { return (ValueLookupParameter)Parameters["PickupViolationsValues"]; }
}
public ValueLookupParameter ResultsParameter {
get { return (ValueLookupParameter)Parameters["Results"]; }
}
#endregion
#region Properties
public bool EnabledByDefault {
get { return true; }
}
private BestPickupAndDeliveryVRPToursMemorizer BestMemorizer {
get { return (BestPickupAndDeliveryVRPToursMemorizer)OperatorGraph.InitialOperator; }
}
private BestAverageWorstPickupAndDeliveryVRPToursCalculator BestAverageWorstCalculator {
get { return (BestAverageWorstPickupAndDeliveryVRPToursCalculator)BestMemorizer.Successor; }
}
#endregion
public BestAverageWorstPickupAndDeliveryVRPToursAnalyzer()
: base() {
#region Create parameters
Parameters.Add(new LookupParameter("ProblemInstance", "The problem instance."));
Parameters.Add(new ScopeTreeLookupParameter("PickupViolations", "The pickup violations of the VRP solutions which should be analyzed."));
Parameters.Add(new ValueLookupParameter("BestPickupViolations", "The best pickup violations value."));
Parameters.Add(new ValueLookupParameter("CurrentBestPickupViolations", "The current best pickup violations value."));
Parameters.Add(new ValueLookupParameter("CurrentAveragePickupViolations", "The current average pickup violations value of all solutions."));
Parameters.Add(new ValueLookupParameter("CurrentWorstPickupViolations", "The current worst pickup violations value of all solutions."));
Parameters.Add(new ValueLookupParameter("PickupViolationsValues", "The data table to store the current best, current average, current worst, best and best known pickup violations value."));
Parameters.Add(new ValueLookupParameter("Results", "The results collection where the analysis values should be stored."));
#endregion
#region Create operators
BestPickupAndDeliveryVRPToursMemorizer bestMemorizer = new BestPickupAndDeliveryVRPToursMemorizer();
BestAverageWorstPickupAndDeliveryVRPToursCalculator calculator = new BestAverageWorstPickupAndDeliveryVRPToursCalculator();
ResultsCollector resultsCollector = new ResultsCollector();
//pickup violations
bestMemorizer.BestPickupViolationsParameter.ActualName = BestPickupViolationsParameter.Name;
bestMemorizer.PickupViolationsParameter.ActualName = PickupViolationsParameter.Name;
bestMemorizer.PickupViolationsParameter.Depth = PickupViolationsParameter.Depth;
calculator.PickupViolationsParameter.ActualName = PickupViolationsParameter.Name;
calculator.PickupViolationsParameter.Depth = PickupViolationsParameter.Depth;
calculator.BestPickupViolationsParameter.ActualName = CurrentBestPickupViolationsParameter.Name;
calculator.AveragePickupViolationsParameter.ActualName = CurrentAveragePickupViolationsParameter.Name;
calculator.WorstPickupViolationsParameter.ActualName = CurrentWorstPickupViolationsParameter.Name;
DataTableValuesCollector pickupViolationsDataTablesCollector = new DataTableValuesCollector();
pickupViolationsDataTablesCollector.CollectedValues.Add(new LookupParameter("BestPickupViolations", null, BestPickupViolationsParameter.Name));
pickupViolationsDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentBestPickupViolations", null, CurrentBestPickupViolationsParameter.Name));
pickupViolationsDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentAveragePickupViolations", null, CurrentAveragePickupViolationsParameter.Name));
pickupViolationsDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentWorstPickupViolations", null, CurrentWorstPickupViolationsParameter.Name));
pickupViolationsDataTablesCollector.DataTableParameter.ActualName = PickupViolationsValuesParameter.Name;
resultsCollector.CollectedValues.Add(new LookupParameter(PickupViolationsValuesParameter.Name));
#endregion
#region Create operator graph
OperatorGraph.InitialOperator = bestMemorizer;
bestMemorizer.Successor = calculator;
calculator.Successor = pickupViolationsDataTablesCollector;
pickupViolationsDataTablesCollector.Successor = resultsCollector;
resultsCollector.Successor = null;
#endregion
Initialize();
}
[StorableConstructor]
private BestAverageWorstPickupAndDeliveryVRPToursAnalyzer(bool deserializing) : base() { }
[StorableHook(HookType.AfterDeserialization)]
private void Initialize() {
PickupViolationsParameter.DepthChanged += new EventHandler(PickupViolationsParameter_DepthChanged);
}
public override IDeepCloneable Clone(Cloner cloner) {
return new BestAverageWorstPickupAndDeliveryVRPToursAnalyzer(this, cloner);
}
private BestAverageWorstPickupAndDeliveryVRPToursAnalyzer(BestAverageWorstPickupAndDeliveryVRPToursAnalyzer original, Cloner cloner)
: base(original, cloner) {
this.Initialize();
}
void PickupViolationsParameter_DepthChanged(object sender, EventArgs e) {
BestAverageWorstCalculator.PickupViolationsParameter.Depth = PickupViolationsParameter.Depth;
BestMemorizer.PickupViolationsParameter.Depth = PickupViolationsParameter.Depth;
}
}
}