#region License Information /* HeuristicLab * Copyright (C) 2002-2010 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.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Common; using HeuristicLab.Problems.VehicleRouting.ProblemInstances; using HeuristicLab.Problems.VehicleRouting.Interfaces; using HeuristicLab.Problems.VehicleRouting.Variants; namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin { [Item("PotvinPDShiftMoveMaker", "Peforms the shift move on a given PDP encoding and updates the quality.")] [StorableClass] public class PotvinPDShiftMoveMaker : PotvinMoveMaker, IPotvinPDShiftMoveOperator, IMoveMaker { public ILookupParameter PDShiftMoveParameter { get { return (ILookupParameter)Parameters["PotvinPDShiftMove"]; } } public override ILookupParameter VRPMoveParameter { get { return PDShiftMoveParameter; } } [StorableConstructor] private PotvinPDShiftMoveMaker(bool deserializing) : base(deserializing) { } public PotvinPDShiftMoveMaker() : base() { Parameters.Add(new LookupParameter("PotvinPDShiftMove", "The moves that should be made.")); } public override IDeepCloneable Clone(Cloner cloner) { return new PotvinPDShiftMoveMaker(this, cloner); } protected PotvinPDShiftMoveMaker(PotvinPDShiftMoveMaker original, Cloner cloner) : base(original, cloner) { } public static void Apply(PotvinEncoding solution, PotvinPDShiftMove move, IVRPProblemInstance problemInstance) { if (move.Tour >= solution.Tours.Count) solution.Tours.Add(new Tour()); Tour tour = solution.Tours[move.Tour]; Tour oldTour = solution.Tours.Find(t => t.Stops.Contains(move.City)); oldTour.Stops.Remove(move.City); if (problemInstance is IPickupAndDeliveryProblemInstance) { IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance; int location = pdp.GetPickupDeliveryLocation(move.City); Tour oldTour2 = solution.Tours.Find(t => t.Stops.Contains(location)); oldTour2.Stops.Remove(location); solution.InsertPair(tour, move.City, location, problemInstance); } else { int place = solution.FindBestInsertionPlace(tour, move.City); tour.Stops.Insert(place, move.City); } } protected override void PerformMove() { PotvinPDShiftMove move = PDShiftMoveParameter.ActualValue; PotvinEncoding newSolution = move.Individual.Clone() as PotvinEncoding; Apply(newSolution, move, ProblemInstance); newSolution.Repair(); VRPToursParameter.ActualValue = newSolution; } } }