#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 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("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, IGeneralVRPOperator {
#region Parameter properties
public ILookupParameter ProblemInstanceParameter {
get { return (ILookupParameter)Parameters["ProblemInstance"]; }
}
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 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
public bool EnabledByDefault {
get { return true; }
}
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 LookupParameter("ProblemInstance", "The problem instance."));
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("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();
//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));
//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 = distanceDataTablesCollector;
distanceDataTablesCollector.Successor = vehiclesUtilizedDataTablesCollector;
vehiclesUtilizedDataTablesCollector.Successor = resultsCollector;
resultsCollector.Successor = null;
#endregion
Initialize();
}
[StorableConstructor]
private BestAverageWorstVRPToursAnalyzer(bool deserializing) : base() { }
public override IDeepCloneable Clone(Cloner cloner) {
return new BestAverageWorstVRPToursAnalyzer(this, cloner);
}
private BestAverageWorstVRPToursAnalyzer(BestAverageWorstVRPToursAnalyzer original, Cloner cloner)
: base(original, cloner) {
this.Initialize();
}
[StorableHook(HookType.AfterDeserialization)]
private void Initialize() {
DistanceParameter.DepthChanged += new EventHandler(DistanceParameter_DepthChanged);
VehiclesUtilizedParameter.DepthChanged += new EventHandler(VehiclesUtilizedParameter_DepthChanged);
}
void DistanceParameter_DepthChanged(object sender, EventArgs e) {
BestAverageWorstCalculator.DistanceParameter.Depth = DistanceParameter.Depth;
BestMemorizer.DistanceParameter.Depth = DistanceParameter.Depth;
}
void VehiclesUtilizedParameter_DepthChanged(object sender, EventArgs e) {
BestAverageWorstCalculator.VehiclesUtilizedParameter.Depth = VehiclesUtilizedParameter.Depth;
BestMemorizer.VehiclesUtilizedParameter.Depth = DistanceParameter.Depth;
}
}
}