#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 HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Parameters; using HEAL.Attic; namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin { [Item("PotvinCustomerRelocationMoveEvaluator", "Evaluates a customer relocation move for a VRP representation. ")] [StorableType("6289C1EA-7223-4BCC-97FD-884E668B6AF4")] public sealed class PotvinCustomerRelocationMoveEvaluator : PotvinMoveEvaluator, IPotvinCustomerRelocationMoveOperator { public ILookupParameter CustomerRelocationMoveParameter { get { return (ILookupParameter)Parameters["PotvinCustomerRelocationMove"]; } } public override ILookupParameter VRPMoveParameter { get { return CustomerRelocationMoveParameter; } } public ILookupParameter MemoriesParameter { get { return (ILookupParameter)Parameters["Memories"]; } } public IValueParameter AdditionFrequencyMemoryKeyParameter { get { return (IValueParameter)Parameters["AdditionFrequencyMemoryKey"]; } } public IValueParameter LambdaParameter { get { return (IValueParameter)Parameters["Lambda"]; } } [StorableConstructor] private PotvinCustomerRelocationMoveEvaluator(StorableConstructorFlag _) : base(_) { } public PotvinCustomerRelocationMoveEvaluator() : base() { Parameters.Add(new LookupParameter("PotvinCustomerRelocationMove", "The move that should be evaluated.")); Parameters.Add(new LookupParameter("Memories", "The TS memory collection.")); Parameters.Add(new ValueParameter("AdditionFrequencyMemoryKey", "The key that is used for the addition frequency in the TS memory.", new StringValue("AdditionFrequency"))); Parameters.Add(new ValueParameter("Lambda", "The lambda parameter.", new DoubleValue(0.015))); } public override IDeepCloneable Clone(Cloner cloner) { return new PotvinCustomerRelocationMoveEvaluator(this, cloner); } private PotvinCustomerRelocationMoveEvaluator(PotvinCustomerRelocationMoveEvaluator original, Cloner cloner) : base(original, cloner) { } protected override void EvaluateMove() { PotvinCustomerRelocationMove move = CustomerRelocationMoveParameter.ActualValue; PotvinEncoding newSolution = CustomerRelocationMoveParameter.ActualValue.Individual.Clone() as PotvinEncoding; PotvinCustomerRelocationMoveMaker.Apply(newSolution, move, ProblemInstance); UpdateEvaluation(newSolution); //Apply memory, only if move is worse if (MoveQualityParameter.ActualValue.Value >= QualityParameter.ActualValue.Value) { VariableCollection memory = MemoriesParameter.ActualValue; string key = AdditionFrequencyMemoryKeyParameter.Value.Value; if (memory != null && memory.ContainsKey(key)) { ItemDictionary additionFrequency = memory[key].Value as ItemDictionary; PotvinCustomerRelocationMoveAttribute attr = new PotvinCustomerRelocationMoveAttribute(0, move.Tour, move.City); if (additionFrequency.ContainsKey(attr)) { int frequency = additionFrequency[attr].Value; double quality = MoveQualityParameter.ActualValue.Value; MoveQualityParameter.ActualValue.Value += LambdaParameter.Value.Value * quality * frequency; } } } } } }