#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("BestAverageWorstCapaciatatedVRPToursAnalyzer", "An operator which analyzes the best, average and worst properties of the VRP tours in the scope tree.")] [StorableType("20B56A45-8112-4D41-9C1D-EC563D0FDF75")] public sealed class BestAverageWorstCapaciatatedVRPToursAnalyzer : AlgorithmOperator, IAnalyzer, IHomogenousCapacitatedOperator { #region Parameter properties public ILookupParameter ProblemInstanceParameter { get { return (ILookupParameter)Parameters["ProblemInstance"]; } } 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 ValueLookupParameter ResultsParameter { get { return (ValueLookupParameter)Parameters["Results"]; } } #endregion #region Properties public bool EnabledByDefault { get { return true; } } private BestCapacitatedVRPToursMemorizer BestMemorizer { get { return (BestCapacitatedVRPToursMemorizer)OperatorGraph.InitialOperator; } } private BestAverageWorstCapacitatedVRPToursCalculator BestAverageWorstCalculator { get { return (BestAverageWorstCapacitatedVRPToursCalculator)BestMemorizer.Successor; } } #endregion public BestAverageWorstCapaciatatedVRPToursAnalyzer() : base() { #region Create parameters Parameters.Add(new LookupParameter("ProblemInstance", "The problem instance.")); 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 ValueLookupParameter("Results", "The results collection where the analysis values should be stored.")); #endregion #region Create operators BestCapacitatedVRPToursMemorizer bestMemorizer = new BestCapacitatedVRPToursMemorizer(); BestAverageWorstCapacitatedVRPToursCalculator calculator = new BestAverageWorstCapacitatedVRPToursCalculator(); 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)); #endregion #region Create operator graph OperatorGraph.InitialOperator = bestMemorizer; bestMemorizer.Successor = calculator; calculator.Successor = overloadDataTablesCollector; overloadDataTablesCollector.Successor = resultsCollector; resultsCollector.Successor = null; #endregion Initialize(); } [StorableConstructor] private BestAverageWorstCapaciatatedVRPToursAnalyzer(StorableConstructorFlag _) : base(_) { } [StorableHook(HookType.AfterDeserialization)] private void Initialize() { OverloadParameter.DepthChanged += new EventHandler(OverloadParameter_DepthChanged); } public override IDeepCloneable Clone(Cloner cloner) { return new BestAverageWorstCapaciatatedVRPToursAnalyzer(this, cloner); } private BestAverageWorstCapaciatatedVRPToursAnalyzer(BestAverageWorstCapaciatatedVRPToursAnalyzer original, Cloner cloner) : base(original, cloner) { this.Initialize(); } void OverloadParameter_DepthChanged(object sender, EventArgs e) { BestAverageWorstCalculator.OverloadParameter.Depth = OverloadParameter.Depth; BestMemorizer.OverloadParameter.Depth = OverloadParameter.Depth; } } }