source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDExchange/PotvinPDExchangeMoveTabuMaker.cs @ 6773

Last change on this file since 6773 was 6773, checked in by svonolfe, 8 years ago

Added moves for pickup and delivery problems (#1177)

File size: 6.5 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.Operators;
29using HeuristicLab.Data;
30using HeuristicLab.Optimization;
31
32namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
33  [Item("PotvinPDExchangeMoveTabuMaker", "Declares a given exchange move as tabu.")]
34  [StorableClass]
35  public class PotvinPDExchangeMoveTabuMaker : SingleSuccessorOperator, ITabuMaker, IPotvinPDExchangeMoveOperator, IPotvinOperator, IVRPMoveOperator {
36    public LookupParameter<ItemList<IItem>> TabuListParameter {
37      get { return (LookupParameter<ItemList<IItem>>)Parameters["TabuList"]; }
38    }
39    public ValueLookupParameter<IntValue> TabuTenureParameter {
40      get { return (ValueLookupParameter<IntValue>)Parameters["TabuTenure"]; }
41    }
42    public ILookupParameter<DoubleValue> MoveQualityParameter {
43      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
44    }
45    public ILookupParameter<DoubleValue> QualityParameter {
46      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
47    }
48    public IValueLookupParameter<BoolValue> MaximizationParameter {
49      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
50    }
51
52   
53    public ILookupParameter<PotvinPDExchangeMove> PDExchangeMoveParameter {
54      get { return (ILookupParameter<PotvinPDExchangeMove>)Parameters["PotvinPDExchangeMove"]; }
55    }
56    public ILookupParameter VRPMoveParameter {
57      get { return PDExchangeMoveParameter; }
58    }
59    public ILookupParameter<IVRPEncoding> VRPToursParameter {
60      get { return (ILookupParameter<IVRPEncoding>)Parameters["VRPTours"]; }
61    }
62    public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter {
63      get { return (LookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; }
64    }
65
66    public ILookupParameter<DoubleValue> DistanceParameter {
67      get { return (ILookupParameter<DoubleValue>)Parameters["Distance"]; }
68    }
69    public ILookupParameter<DoubleValue> OverloadParameter {
70      get { return (ILookupParameter<DoubleValue>)Parameters["Overload"]; }
71    }
72    public ILookupParameter<DoubleValue> TardinessParameter {
73      get { return (ILookupParameter<DoubleValue>)Parameters["Tardiness"]; }
74    }
75
76    [StorableConstructor]
77    protected PotvinPDExchangeMoveTabuMaker(bool deserializing) : base(deserializing) { }
78    protected PotvinPDExchangeMoveTabuMaker(PotvinPDExchangeMoveTabuMaker original, Cloner cloner) : base(original, cloner) { }
79    public PotvinPDExchangeMoveTabuMaker()
80      : base() {
81      Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list where move attributes are stored."));
82      Parameters.Add(new ValueLookupParameter<IntValue>("TabuTenure", "The tenure of the tabu list."));
83      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The quality of the move."));
84      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the solution."));
85      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, else if it is a minimization problem."));
86
87        Parameters.Add(new LookupParameter<PotvinPDExchangeMove>("PotvinPDExchangeMove", "The moves that should be made."));
88        Parameters.Add(new LookupParameter<IVRPEncoding>("VRPTours", "The VRP tours considered in the move."));
89        Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The VRP problem instance"));
90
91        Parameters.Add(new LookupParameter<DoubleValue>("Distance", "The distance of the individual"));
92        Parameters.Add(new LookupParameter<DoubleValue>("Overload", "The overload of the individual"));
93        Parameters.Add(new LookupParameter<DoubleValue>("Tardiness", "The tardiness of the individual"));
94    }
95
96    public override IDeepCloneable Clone(Cloner cloner) {
97      return new PotvinPDExchangeMoveTabuMaker(this, cloner);
98    }
99
100    public override IOperation Apply() {
101      ItemList<IItem> tabuList = TabuListParameter.ActualValue;
102      int tabuTenure = TabuTenureParameter.ActualValue.Value;
103
104      int overlength = tabuList.Count - tabuTenure;
105      if (overlength >= 0) {
106        for (int i = 0; i < tabuTenure - 1; i++)
107          tabuList[i] = tabuList[i + overlength + 1];
108        while (tabuList.Count >= tabuTenure)
109          tabuList.RemoveAt(tabuList.Count - 1);
110      }
111
112      PotvinPDExchangeMove move = PDExchangeMoveParameter.ActualValue;
113      double moveQuality = MoveQualityParameter.ActualValue.Value;
114      double quality = QualityParameter.ActualValue.Value;
115      double baseQuality = moveQuality;
116      if (quality < moveQuality) baseQuality = quality; // we make an uphill move, the lower bound is the solution quality
117
118      double distance = 0;
119      if (DistanceParameter.ActualValue != null)
120        distance = DistanceParameter.ActualValue.Value;
121
122      double overload = 0;
123      if (OverloadParameter.ActualValue != null)
124        overload = OverloadParameter.ActualValue.Value;
125
126      double tardiness = 0;
127      if (TardinessParameter.ActualValue != null)
128        tardiness = TardinessParameter.ActualValue.Value;
129
130      tabuList.Add(new PotvinPDRelocateMoveAttribute(baseQuality, move.OldTour, move.City, distance, overload, tardiness));
131      tabuList.Add(new PotvinPDRelocateMoveAttribute(baseQuality, move.Tour, move.Replaced, distance, overload, tardiness));
132      return base.Apply();
133    }
134  }
135}
Note: See TracBrowser for help on using the repository browser.