#region License Information
/* HeuristicLab
* Copyright (C) 2002-2011 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;
namespace HeuristicLab.Problems.VehicleRouting {
///
/// An operator which analyzes the best, average and worst quality of solutions in the scope tree.
///
[Item("BestAverageWorstVRPToursAnalyzer", "An operator which analyzes the best, average and worst properties of the VRP tours in the scope tree.")]
[StorableClass]
public sealed class BestAverageWorstVRPToursAnalyzer : AlgorithmOperator, IAnalyzer {
#region Parameter properties
public ScopeTreeLookupParameter OverloadParameter {
get { return (ScopeTreeLookupParameter)Parameters["Overload"]; }
}
public ValueLookupParameter BestOverloadParameter {
get { return (ValueLookupParameter)Parameters["BestOverload"]; }
}
public ValueLookupParameter CurrentBestOverloadParameter {
get { return (ValueLookupParameter)Parameters["CurrentBestOverload"]; }
}
public ValueLookupParameter CurrentAverageOverloadParameter {
get { return (ValueLookupParameter)Parameters["CurrentAverageOverload"]; }
}
public ValueLookupParameter CurrentWorstOverloadParameter {
get { return (ValueLookupParameter)Parameters["CurrentWorstOverload"]; }
}
public ValueLookupParameter OverloadsParameter {
get { return (ValueLookupParameter)Parameters["Overloads"]; }
}
public ScopeTreeLookupParameter TardinessParameter {
get { return (ScopeTreeLookupParameter)Parameters["Tardiness"]; }
}
public ValueLookupParameter BestTardinessParameter {
get { return (ValueLookupParameter)Parameters["BestTardiness"]; }
}
public ValueLookupParameter CurrentBestTardinessParameter {
get { return (ValueLookupParameter)Parameters["CurrentBestTardiness"]; }
}
public ValueLookupParameter CurrentAverageTardinessParameter {
get { return (ValueLookupParameter)Parameters["CurrentAverageTardiness"]; }
}
public ValueLookupParameter CurrentWorstTardinessParameter {
get { return (ValueLookupParameter)Parameters["CurrentWorstTardiness"]; }
}
public ValueLookupParameter TardinessValuesParameter {
get { return (ValueLookupParameter)Parameters["TardinessValues"]; }
}
public ScopeTreeLookupParameter DistanceParameter {
get { return (ScopeTreeLookupParameter)Parameters["Distance"]; }
}
public ValueLookupParameter BestDistanceParameter {
get { return (ValueLookupParameter)Parameters["BestDistance"]; }
}
public ValueLookupParameter CurrentBestDistanceParameter {
get { return (ValueLookupParameter)Parameters["CurrentBestDistance"]; }
}
public ValueLookupParameter CurrentAverageDistanceParameter {
get { return (ValueLookupParameter)Parameters["CurrentAverageDistance"]; }
}
public ValueLookupParameter CurrentWorstDistanceParameter {
get { return (ValueLookupParameter)Parameters["CurrentWorstDistance"]; }
}
public ValueLookupParameter DistancesParameter {
get { return (ValueLookupParameter)Parameters["Distances"]; }
}
public ScopeTreeLookupParameter TravelTimeParameter {
get { return (ScopeTreeLookupParameter)Parameters["TravelTime"]; }
}
public ValueLookupParameter BestTravelTimeParameter {
get { return (ValueLookupParameter)Parameters["BestTravelTime"]; }
}
public ValueLookupParameter CurrentBestTravelTimeParameter {
get { return (ValueLookupParameter)Parameters["CurrentBestTravelTime"]; }
}
public ValueLookupParameter CurrentAverageTravelTimeParameter {
get { return (ValueLookupParameter)Parameters["CurrentAverageTravelTime"]; }
}
public ValueLookupParameter CurrentWorstTravelTimeParameter {
get { return (ValueLookupParameter)Parameters["CurrentWorstTravelTime"]; }
}
public ValueLookupParameter TravelTimesParameter {
get { return (ValueLookupParameter)Parameters["TravelTimes"]; }
}
public ScopeTreeLookupParameter VehiclesUtilizedParameter {
get { return (ScopeTreeLookupParameter)Parameters["VehiclesUtilized"]; }
}
public ValueLookupParameter BestVehiclesUtilizedParameter {
get { return (ValueLookupParameter)Parameters["BestVehiclesUtilized"]; }
}
public ValueLookupParameter CurrentBestVehiclesUtilizedParameter {
get { return (ValueLookupParameter)Parameters["CurrentBestVehiclesUtilized"]; }
}
public ValueLookupParameter CurrentAverageVehiclesUtilizedParameter {
get { return (ValueLookupParameter)Parameters["CurrentAverageVehiclesUtilized"]; }
}
public ValueLookupParameter CurrentWorstVehiclesUtilizedParameter {
get { return (ValueLookupParameter)Parameters["CurrentWorstVehiclesUtilized"]; }
}
public ValueLookupParameter VehiclesUtilizedValuesParameter {
get { return (ValueLookupParameter)Parameters["VehiclesUtilizedValues"]; }
}
public ValueLookupParameter ResultsParameter {
get { return (ValueLookupParameter)Parameters["Results"]; }
}
#endregion
#region Properties
private BestVRPToursMemorizer BestMemorizer {
get { return (BestVRPToursMemorizer)OperatorGraph.InitialOperator; }
}
private BestAverageWorstVRPToursCalculator BestAverageWorstCalculator {
get { return (BestAverageWorstVRPToursCalculator)BestMemorizer.Successor; }
}
#endregion
public BestAverageWorstVRPToursAnalyzer()
: base() {
#region Create parameters
Parameters.Add(new ScopeTreeLookupParameter("Overload", "The overloads of the VRP solutions which should be analyzed."));
Parameters.Add(new ValueLookupParameter("BestOverload", "The best overload value."));
Parameters.Add(new ValueLookupParameter("CurrentBestOverload", "The current best overload value."));
Parameters.Add(new ValueLookupParameter("CurrentAverageOverload", "The current average overload value of all solutions."));
Parameters.Add(new ValueLookupParameter("CurrentWorstOverload", "The current worst overload value of all solutions."));
Parameters.Add(new ValueLookupParameter("Overloads", "The data table to store the current best, current average, current worst, best and best known overload value."));
Parameters.Add(new ScopeTreeLookupParameter("Tardiness", "The tardiness of the VRP solutions which should be analyzed."));
Parameters.Add(new ValueLookupParameter("BestTardiness", "The best tardiness value."));
Parameters.Add(new ValueLookupParameter("CurrentBestTardiness", "The current best tardiness value."));
Parameters.Add(new ValueLookupParameter("CurrentAverageTardiness", "The current average tardiness value of all solutions."));
Parameters.Add(new ValueLookupParameter("CurrentWorstTardiness", "The current worst tardiness value of all solutions."));
Parameters.Add(new ValueLookupParameter("TardinessValues", "The data table to store the current best, current average, current worst, best and best known tardiness value."));
Parameters.Add(new ScopeTreeLookupParameter("Distance", "The distance of the VRP solutions which should be analyzed."));
Parameters.Add(new ValueLookupParameter("BestDistance", "The best distance value."));
Parameters.Add(new ValueLookupParameter("CurrentBestDistance", "The current best distance value."));
Parameters.Add(new ValueLookupParameter("CurrentAverageDistance", "The current average distance value of all solutions."));
Parameters.Add(new ValueLookupParameter("CurrentWorstDistance", "The current worst distance value of all solutions."));
Parameters.Add(new ValueLookupParameter("Distances", "The data table to store the current best, current average, current worst, best and best known distance value."));
Parameters.Add(new ScopeTreeLookupParameter("TravelTime", "The travel time of the VRP solutions which should be analyzed."));
Parameters.Add(new ValueLookupParameter("BestTravelTime", "The best travel time value."));
Parameters.Add(new ValueLookupParameter("CurrentBestTravelTime", "The current best travel time value."));
Parameters.Add(new ValueLookupParameter("CurrentAverageTravelTime", "The current average travel time value of all solutions."));
Parameters.Add(new ValueLookupParameter("CurrentWorstTravelTime", "The current worst travel time value of all solutions."));
Parameters.Add(new ValueLookupParameter("TravelTimes", "The data table to store the current best, current average, current worst, best and best known travel time value."));
Parameters.Add(new ScopeTreeLookupParameter("VehiclesUtilized", "The vehicles utilized of the VRP solutions which should be analyzed."));
Parameters.Add(new ValueLookupParameter("BestVehiclesUtilized", "The best vehicles utilized value."));
Parameters.Add(new ValueLookupParameter("CurrentBestVehiclesUtilized", "The current best vehicles utilized value."));
Parameters.Add(new ValueLookupParameter("CurrentAverageVehiclesUtilized", "The current average vehicles utilized value of all solutions."));
Parameters.Add(new ValueLookupParameter("CurrentWorstVehiclesUtilized", "The current worst vehicles utilized value of all solutions."));
Parameters.Add(new ValueLookupParameter("VehiclesUtilizedValues", "The data table to store the current best, current average, current worst, best and best known vehicles utilized value."));
Parameters.Add(new ValueLookupParameter("Results", "The results collection where the analysis values should be stored."));
#endregion
#region Create operators
BestVRPToursMemorizer bestMemorizer = new BestVRPToursMemorizer();
BestAverageWorstVRPToursCalculator calculator = new BestAverageWorstVRPToursCalculator();
ResultsCollector resultsCollector = new ResultsCollector();
//overload
bestMemorizer.BestOverloadParameter.ActualName = BestOverloadParameter.Name;
bestMemorizer.OverloadParameter.ActualName = OverloadParameter.Name;
bestMemorizer.OverloadParameter.Depth = OverloadParameter.Depth;
calculator.OverloadParameter.ActualName = OverloadParameter.Name;
calculator.OverloadParameter.Depth = OverloadParameter.Depth;
calculator.BestOverloadParameter.ActualName = CurrentBestOverloadParameter.Name;
calculator.AverageOverloadParameter.ActualName = CurrentAverageOverloadParameter.Name;
calculator.WorstOverloadParameter.ActualName = CurrentWorstOverloadParameter.Name;
DataTableValuesCollector overloadDataTablesCollector = new DataTableValuesCollector();
overloadDataTablesCollector.CollectedValues.Add(new LookupParameter("BestOverload", null, BestOverloadParameter.Name));
overloadDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentBestOverload", null, CurrentBestOverloadParameter.Name));
overloadDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentAverageOverload", null, CurrentAverageOverloadParameter.Name));
overloadDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentWorstOverload", null, CurrentWorstOverloadParameter.Name));
overloadDataTablesCollector.DataTableParameter.ActualName = OverloadsParameter.Name;
resultsCollector.CollectedValues.Add(new LookupParameter(OverloadsParameter.Name));
//tardiness
bestMemorizer.BestTardinessParameter.ActualName = BestTardinessParameter.Name;
bestMemorizer.TardinessParameter.ActualName = TardinessParameter.Name;
bestMemorizer.TardinessParameter.Depth = TardinessParameter.Depth;
calculator.TardinessParameter.ActualName = TardinessParameter.Name;
calculator.TardinessParameter.Depth = TardinessParameter.Depth;
calculator.BestTardinessParameter.ActualName = CurrentBestTardinessParameter.Name;
calculator.AverageTardinessParameter.ActualName = CurrentAverageTardinessParameter.Name;
calculator.WorstTardinessParameter.ActualName = CurrentWorstTardinessParameter.Name;
DataTableValuesCollector tardinessDataTablesCollector = new DataTableValuesCollector();
tardinessDataTablesCollector.CollectedValues.Add(new LookupParameter("BestTardiness", null, BestTardinessParameter.Name));
tardinessDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentBestTardiness", null, CurrentBestTardinessParameter.Name));
tardinessDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentAverageTardiness", null, CurrentAverageTardinessParameter.Name));
tardinessDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentWorstTardiness", null, CurrentWorstTardinessParameter.Name));
tardinessDataTablesCollector.DataTableParameter.ActualName = TardinessValuesParameter.Name;
resultsCollector.CollectedValues.Add(new LookupParameter(TardinessValuesParameter.Name));
//Distance
bestMemorizer.BestDistanceParameter.ActualName = BestDistanceParameter.Name;
bestMemorizer.DistanceParameter.ActualName = DistanceParameter.Name;
bestMemorizer.DistanceParameter.Depth = DistanceParameter.Depth;
calculator.DistanceParameter.ActualName = DistanceParameter.Name;
calculator.DistanceParameter.Depth = DistanceParameter.Depth;
calculator.BestDistanceParameter.ActualName = CurrentBestDistanceParameter.Name;
calculator.AverageDistanceParameter.ActualName = CurrentAverageDistanceParameter.Name;
calculator.WorstDistanceParameter.ActualName = CurrentWorstDistanceParameter.Name;
DataTableValuesCollector distanceDataTablesCollector = new DataTableValuesCollector();
distanceDataTablesCollector.CollectedValues.Add(new LookupParameter("BestDistance", null, BestDistanceParameter.Name));
distanceDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentBestDistance", null, CurrentBestDistanceParameter.Name));
distanceDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentAverageDistance", null, CurrentAverageDistanceParameter.Name));
distanceDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentWorstDistance", null, CurrentWorstDistanceParameter.Name));
distanceDataTablesCollector.DataTableParameter.ActualName = DistancesParameter.Name;
resultsCollector.CollectedValues.Add(new LookupParameter(DistancesParameter.Name));
//Travel Time
bestMemorizer.BestTravelTimeParameter.ActualName = BestTravelTimeParameter.Name;
bestMemorizer.TravelTimeParameter.ActualName = TravelTimeParameter.Name;
bestMemorizer.TravelTimeParameter.Depth = TravelTimeParameter.Depth;
calculator.TravelTimeParameter.ActualName = TravelTimeParameter.Name;
calculator.TravelTimeParameter.Depth = TravelTimeParameter.Depth;
calculator.BestTravelTimeParameter.ActualName = CurrentBestTravelTimeParameter.Name;
calculator.AverageTravelTimeParameter.ActualName = CurrentAverageTravelTimeParameter.Name;
calculator.WorstTravelTimeParameter.ActualName = CurrentWorstTravelTimeParameter.Name;
DataTableValuesCollector travelTimeDataTablesCollector = new DataTableValuesCollector();
travelTimeDataTablesCollector.CollectedValues.Add(new LookupParameter("BestTravelTime", null, BestTravelTimeParameter.Name));
travelTimeDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentBestTravelTime", null, CurrentBestTravelTimeParameter.Name));
travelTimeDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentAverageTravelTime", null, CurrentAverageTravelTimeParameter.Name));
travelTimeDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentWorstTravelTime", null, CurrentWorstTravelTimeParameter.Name));
travelTimeDataTablesCollector.DataTableParameter.ActualName = TravelTimesParameter.Name;
resultsCollector.CollectedValues.Add(new LookupParameter(TravelTimesParameter.Name));
//Vehicles Utlized
bestMemorizer.BestVehiclesUtilizedParameter.ActualName = BestVehiclesUtilizedParameter.Name;
bestMemorizer.VehiclesUtilizedParameter.ActualName = VehiclesUtilizedParameter.Name;
bestMemorizer.VehiclesUtilizedParameter.Depth = VehiclesUtilizedParameter.Depth;
calculator.VehiclesUtilizedParameter.ActualName = VehiclesUtilizedParameter.Name;
calculator.VehiclesUtilizedParameter.Depth = VehiclesUtilizedParameter.Depth;
calculator.BestVehiclesUtilizedParameter.ActualName = CurrentBestVehiclesUtilizedParameter.Name;
calculator.AverageVehiclesUtilizedParameter.ActualName = CurrentAverageVehiclesUtilizedParameter.Name;
calculator.WorstVehiclesUtilizedParameter.ActualName = CurrentWorstVehiclesUtilizedParameter.Name;
DataTableValuesCollector vehiclesUtilizedDataTablesCollector = new DataTableValuesCollector();
vehiclesUtilizedDataTablesCollector.CollectedValues.Add(new LookupParameter("BestVehiclesUtilized", null, BestVehiclesUtilizedParameter.Name));
vehiclesUtilizedDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentBestVehiclesUtilized", null, CurrentBestVehiclesUtilizedParameter.Name));
vehiclesUtilizedDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentAverageVehiclesUtilized", null, CurrentAverageVehiclesUtilizedParameter.Name));
vehiclesUtilizedDataTablesCollector.CollectedValues.Add(new LookupParameter("CurrentWorstVehiclesUtilized", null, CurrentWorstVehiclesUtilizedParameter.Name));
vehiclesUtilizedDataTablesCollector.DataTableParameter.ActualName = VehiclesUtilizedValuesParameter.Name;
resultsCollector.CollectedValues.Add(new LookupParameter(VehiclesUtilizedValuesParameter.Name));
#endregion
#region Create operator graph
OperatorGraph.InitialOperator = bestMemorizer;
bestMemorizer.Successor = calculator;
calculator.Successor = overloadDataTablesCollector;
overloadDataTablesCollector.Successor = tardinessDataTablesCollector;
tardinessDataTablesCollector.Successor = distanceDataTablesCollector;
distanceDataTablesCollector.Successor = travelTimeDataTablesCollector;
travelTimeDataTablesCollector.Successor = vehiclesUtilizedDataTablesCollector;
vehiclesUtilizedDataTablesCollector.Successor = resultsCollector;
resultsCollector.Successor = null;
#endregion
Initialize();
}
[StorableConstructor]
private BestAverageWorstVRPToursAnalyzer(bool deserializing) : base() { }
private BestAverageWorstVRPToursAnalyzer(BestAverageWorstVRPToursAnalyzer original, Cloner cloner)
: base(original, cloner) {
Initialize();
}
public override IDeepCloneable Clone(Cloner cloner) {
return new BestAverageWorstVRPToursAnalyzer(this, cloner);
}
[StorableHook(HookType.AfterDeserialization)]
private void AfterDeserialization() {
Initialize();
}
private void Initialize() {
OverloadParameter.DepthChanged += new EventHandler(OverloadParameter_DepthChanged);
TardinessParameter.DepthChanged += new EventHandler(TardinessParameter_DepthChanged);
DistanceParameter.DepthChanged += new EventHandler(DistanceParameter_DepthChanged);
TravelTimeParameter.DepthChanged += new EventHandler(TravelTimeParameter_DepthChanged);
VehiclesUtilizedParameter.DepthChanged += new EventHandler(VehiclesUtilizedParameter_DepthChanged);
}
void OverloadParameter_DepthChanged(object sender, EventArgs e) {
BestAverageWorstCalculator.OverloadParameter.Depth = OverloadParameter.Depth;
BestMemorizer.OverloadParameter.Depth = OverloadParameter.Depth;
}
void TardinessParameter_DepthChanged(object sender, EventArgs e) {
BestAverageWorstCalculator.TardinessParameter.Depth = TardinessParameter.Depth;
BestMemorizer.TardinessParameter.Depth = TardinessParameter.Depth;
}
void DistanceParameter_DepthChanged(object sender, EventArgs e) {
BestAverageWorstCalculator.DistanceParameter.Depth = DistanceParameter.Depth;
BestMemorizer.DistanceParameter.Depth = DistanceParameter.Depth;
}
void TravelTimeParameter_DepthChanged(object sender, EventArgs e) {
BestAverageWorstCalculator.TravelTimeParameter.Depth = TravelTimeParameter.Depth;
BestMemorizer.TravelTimeParameter.Depth = DistanceParameter.Depth;
}
void VehiclesUtilizedParameter_DepthChanged(object sender, EventArgs e) {
BestAverageWorstCalculator.VehiclesUtilizedParameter.Depth = VehiclesUtilizedParameter.Depth;
BestMemorizer.VehiclesUtilizedParameter.Depth = VehiclesUtilizedParameter.Depth;
}
}
}