#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.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Parameters; using HEAL.Attic; namespace HeuristicLab.Problems.VehicleRouting { [Item("BestCapacitatedVRPToursMemorizer", "An operator that updates the best VRP tour found so far in the scope three.")] [StorableType("888B45AA-2037-49EB-ACD9-36F7D593D320")] public class BestCapacitatedVRPToursMemorizer : SingleSuccessorOperator { public ScopeTreeLookupParameter OverloadParameter { get { return (ScopeTreeLookupParameter)Parameters["Overload"]; } } public ValueLookupParameter BestOverloadParameter { get { return (ValueLookupParameter)Parameters["BestOverload"]; } } public BestCapacitatedVRPToursMemorizer() : base() { Parameters.Add(new ScopeTreeLookupParameter("Overload", "The overloads of the VRP solutions which should be analyzed.")); Parameters.Add(new ValueLookupParameter("BestOverload", "The best overload found so far.")); } public override IDeepCloneable Clone(Cloner cloner) { return new BestCapacitatedVRPToursMemorizer(this, cloner); } protected BestCapacitatedVRPToursMemorizer(BestCapacitatedVRPToursMemorizer original, Cloner cloner) : base(original, cloner) { } [StorableConstructor] protected BestCapacitatedVRPToursMemorizer(StorableConstructorFlag _) : base(_) { } public override IOperation Apply() { int i = OverloadParameter.ActualValue.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; if (BestOverloadParameter.ActualValue == null) BestOverloadParameter.ActualValue = new DoubleValue(OverloadParameter.ActualValue[i].Value); else if (OverloadParameter.ActualValue[i].Value <= BestOverloadParameter.ActualValue.Value) BestOverloadParameter.ActualValue.Value = OverloadParameter.ActualValue[i].Value; return base.Apply(); } } }