Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDRearrange/PotvinPDRearrangeMoveMaker.cs @ 17717

Last change on this file since 17717 was 17717, checked in by abeham, 4 years ago

#2521: working on VRP (refactoring all the capabilities, features, and operator discovery)

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HEAL.Attic;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Optimization;
26using HeuristicLab.Parameters;
27using HeuristicLab.Problems.VehicleRouting.Interfaces;
28
29namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
30  [Item("PotvinPDRearrangeMoveMaker", "Peforms the rearrange move on a given PDP encoding and updates the quality.")]
31  [StorableType("5F16D0F3-A5E5-44A3-BA40-8CC9CE756FB7")]
32  public class PotvinPDRearrangeMoveMaker : PotvinMoveMaker, IPotvinPDRearrangeMoveOperator, IMoveMaker {
33    public ILookupParameter<PotvinPDRearrangeMove> PDRearrangeMoveParameter {
34      get { return (ILookupParameter<PotvinPDRearrangeMove>)Parameters["PotvinPDRearrangeMove"]; }
35    }
36
37    public override ILookupParameter VRPMoveParameter {
38      get { return PDRearrangeMoveParameter; }
39    }
40
41    [StorableConstructor]
42    protected PotvinPDRearrangeMoveMaker(StorableConstructorFlag _) : base(_) { }
43
44    public PotvinPDRearrangeMoveMaker()
45      : base() {
46      Parameters.Add(new LookupParameter<PotvinPDRearrangeMove>("PotvinPDRearrangeMove", "The moves that should be made."));
47    }
48
49    public override IDeepCloneable Clone(Cloner cloner) {
50      return new PotvinPDRearrangeMoveMaker(this, cloner);
51    }
52
53    protected PotvinPDRearrangeMoveMaker(PotvinPDRearrangeMoveMaker original, Cloner cloner)
54      : base(original, cloner) {
55    }
56
57    public static void Apply(PotvinEncodedSolution solution, PotvinPDRearrangeMove move, IVRPProblemInstance problemInstance) {
58      Tour tour = solution.Tours[move.Tour];
59      int position = tour.Stops.IndexOf(move.City);
60
61      IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance;
62      if (pdp != null) {
63        int location = pdp.GetPickupDeliveryLocation(move.City);
64        Tour tour2 = solution.Tours.Find(t => t.Stops.Contains(location));
65        int position2 = tour2.Stops.IndexOf(location);
66
67        tour.Stops.Remove(move.City);
68        tour2.Stops.Remove(location);
69
70        solution.InsertPair(tour, move.City, location, problemInstance, position, position2);
71      } else {
72        tour.Stops.Remove(move.City);
73        int place = solution.FindBestInsertionPlace(tour, move.City, position);
74        tour.Stops.Insert(place, move.City);
75      }
76
77      solution.Repair();
78    }
79
80    protected override void PerformMove() {
81      PotvinPDRearrangeMove move = PDRearrangeMoveParameter.ActualValue;
82
83      PotvinEncodedSolution newSolution = move.Individual.Clone() as PotvinEncodedSolution;
84      Apply(newSolution, move, ProblemInstance);
85      VRPToursParameter.ActualValue = newSolution;
86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.