source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDShift/PotvinPDShiftMoveTabuMaker.cs @ 7791

Last change on this file since 7791 was 7791, checked in by svonolfe, 7 years ago

Improved PDP moves (#1177)

File size: 4.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Optimization.Operators;
25using HeuristicLab.Parameters;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Problems.VehicleRouting.Interfaces;
28using HeuristicLab.Data;
29
30namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
31  [Item("PotvinPDShiftMoveTabuMaker", "Declares a given shift move as tabu.")]
32  [StorableClass]
33  public class PotvinPDShiftMoveTabuMaker : TabuMaker, IPotvinPDShiftMoveOperator, IPotvinOperator, IVRPMoveOperator {
34    public ILookupParameter<PotvinPDShiftMove> PDShiftMoveParameter {
35      get { return (ILookupParameter<PotvinPDShiftMove>)Parameters["PotvinPDShiftMove"]; }
36    }
37    public ILookupParameter VRPMoveParameter {
38      get { return PDShiftMoveParameter; }
39    }
40    public ILookupParameter<IVRPEncoding> VRPToursParameter {
41      get { return (ILookupParameter<IVRPEncoding>)Parameters["VRPTours"]; }
42    }
43    public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter {
44      get { return (LookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; }
45    }
46
47    public ILookupParameter<DoubleValue> DistanceParameter {
48      get { return (ILookupParameter<DoubleValue>)Parameters["Distance"]; }
49    }
50    public ILookupParameter<DoubleValue> OverloadParameter {
51      get { return (ILookupParameter<DoubleValue>)Parameters["Overload"]; }
52    }
53    public ILookupParameter<DoubleValue> TardinessParameter {
54      get { return (ILookupParameter<DoubleValue>)Parameters["Tardiness"]; }
55    }
56    public ILookupParameter<IntValue> PickupViolationsParameter {
57      get { return (ILookupParameter<IntValue>)Parameters["PickupViolations"]; }
58    }
59
60    [StorableConstructor]
61    protected PotvinPDShiftMoveTabuMaker(bool deserializing) : base(deserializing) { }
62    protected PotvinPDShiftMoveTabuMaker(PotvinPDShiftMoveTabuMaker original, Cloner cloner) : base(original, cloner) { }
63    public PotvinPDShiftMoveTabuMaker()
64      : base() {
65        Parameters.Add(new LookupParameter<PotvinPDShiftMove>("PotvinPDShiftMove", "The moves that should be made."));
66        Parameters.Add(new LookupParameter<IVRPEncoding>("VRPTours", "The VRP tours considered in the move."));
67        Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The VRP problem instance"));
68
69        Parameters.Add(new LookupParameter<DoubleValue>("Distance", "The distance of the individual"));
70        Parameters.Add(new LookupParameter<DoubleValue>("Overload", "The overload of the individual"));
71        Parameters.Add(new LookupParameter<DoubleValue>("Tardiness", "The tardiness of the individual"));
72        Parameters.Add(new LookupParameter<IntValue>("PickupViolations", "The number of pickup violations."));
73    }
74
75    public override IDeepCloneable Clone(Cloner cloner) {
76      return new PotvinPDShiftMoveTabuMaker(this, cloner);
77    }
78
79    protected override IItem GetTabuAttribute(bool maximization, double quality, double moveQuality) {
80      PotvinPDShiftMove move = PDShiftMoveParameter.ActualValue;
81      double baseQuality = moveQuality;
82      if (quality < moveQuality) baseQuality = quality; // we make an uphill move, the lower bound is the solution quality
83
84      double distance = 0;
85      if (DistanceParameter.ActualValue != null)
86        distance = DistanceParameter.ActualValue.Value;
87
88      double overload = 0;
89      if (OverloadParameter.ActualValue != null)
90        overload = OverloadParameter.ActualValue.Value;
91
92      double tardiness = 0;
93      if (TardinessParameter.ActualValue != null)
94        tardiness = TardinessParameter.ActualValue.Value;
95
96      int pickupViolations = 0;
97      if (PickupViolationsParameter.ActualValue != null)
98        pickupViolations = PickupViolationsParameter.ActualValue.Value;
99     
100      return new PotvinPDRelocateMoveAttribute(baseQuality, move.OldTour, move.City, distance, overload, tardiness, pickupViolations);
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.