#region License Information
/* HeuristicLab
* Copyright (C) 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 HEAL.Attic;
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("BestAverageWorstTimeWindowedVRPToursAnalyzer", "An operator which analyzes the best, average and worst properties of the VRP tours in the scope tree.")]
[StorableType("EBEDE5FC-0AA9-4F99-986A-5499A8C8C506")]
public sealed class BestAverageWorstTimeWindowedVRPToursAnalyzer : AlgorithmOperator, IAnalyzer, ITimeWindowedOperator {
#region Parameter properties
public ILookupParameter ProblemInstanceParameter {
get { return (ILookupParameter)Parameters["ProblemInstance"]; }
}
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 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 ValueLookupParameter ResultsParameter {
get { return (ValueLookupParameter)Parameters["Results"]; }
}
#endregion
#region Properties
public bool EnabledByDefault {
get { return true; }
}
private BestTimeWindowedVRPToursMemorizer BestMemorizer {
get { return (BestTimeWindowedVRPToursMemorizer)OperatorGraph.InitialOperator; }
}
private BestAverageWorstTimeWindowedVRPToursCalculator BestAverageWorstCalculator {
get { return (BestAverageWorstTimeWindowedVRPToursCalculator)BestMemorizer.Successor; }
}
#endregion
public BestAverageWorstTimeWindowedVRPToursAnalyzer()
: base() {
#region Create parameters
Parameters.Add(new LookupParameter("ProblemInstance", "The problem instance."));
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("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 ValueLookupParameter("Results", "The results collection where the analysis values should be stored."));
#endregion
#region Create operators
BestTimeWindowedVRPToursMemorizer bestMemorizer = new BestTimeWindowedVRPToursMemorizer();
BestAverageWorstTimeWindowedVRPToursCalculator calculator = new BestAverageWorstTimeWindowedVRPToursCalculator();
ResultsCollector resultsCollector = new ResultsCollector();
//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));
//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));
#endregion
#region Create operator graph
OperatorGraph.InitialOperator = bestMemorizer;
bestMemorizer.Successor = calculator;
calculator.Successor = tardinessDataTablesCollector;
tardinessDataTablesCollector.Successor = travelTimeDataTablesCollector;
travelTimeDataTablesCollector.Successor = resultsCollector;
resultsCollector.Successor = null;
#endregion
Initialize();
}
[StorableConstructor]
private BestAverageWorstTimeWindowedVRPToursAnalyzer(StorableConstructorFlag _) : base(_) { }
[StorableHook(HookType.AfterDeserialization)]
private void Initialize() {
TardinessParameter.DepthChanged += new EventHandler(TardinessParameter_DepthChanged);
TravelTimeParameter.DepthChanged += new EventHandler(TravelTimeParameter_DepthChanged);
}
public override IDeepCloneable Clone(Cloner cloner) {
return new BestAverageWorstTimeWindowedVRPToursAnalyzer(this, cloner);
}
private BestAverageWorstTimeWindowedVRPToursAnalyzer(BestAverageWorstTimeWindowedVRPToursAnalyzer original, Cloner cloner)
: base(original, cloner) {
this.Initialize();
}
void TardinessParameter_DepthChanged(object sender, EventArgs e) {
BestAverageWorstCalculator.TardinessParameter.Depth = TardinessParameter.Depth;
BestMemorizer.TardinessParameter.Depth = TardinessParameter.Depth;
}
void TravelTimeParameter_DepthChanged(object sender, EventArgs e) {
BestAverageWorstCalculator.TravelTimeParameter.Depth = TravelTimeParameter.Depth;
BestMemorizer.TravelTimeParameter.Depth = TravelTimeParameter.Depth;
}
}
}