Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/Operators/Moves/Exchange/PotvinPDExchangeMoveTabuMaker.cs @ 8670

Last change on this file since 8670 was 8670, checked in by svonolfe, 12 years ago

Added first version of the dynamic vehicle routing addon (#1955)

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