Free cookie consent management tool by TermsFeed Policy Generator

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

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

Improved PDP moves (#1177)

File size: 6.9 KB
RevLine 
[6773]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    }
[7791]75    public ILookupParameter<IntValue> PickupViolationsParameter {
76      get { return (ILookupParameter<IntValue>)Parameters["PickupViolations"]; }
77    }
[6773]78
79    [StorableConstructor]
80    protected PotvinPDExchangeMoveTabuMaker(bool deserializing) : base(deserializing) { }
81    protected PotvinPDExchangeMoveTabuMaker(PotvinPDExchangeMoveTabuMaker original, Cloner cloner) : base(original, cloner) { }
82    public PotvinPDExchangeMoveTabuMaker()
83      : base() {
84      Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list where move attributes are stored."));
85      Parameters.Add(new ValueLookupParameter<IntValue>("TabuTenure", "The tenure of the tabu list."));
86      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The quality of the move."));
87      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the solution."));
88      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, else if it is a minimization problem."));
89
90        Parameters.Add(new LookupParameter<PotvinPDExchangeMove>("PotvinPDExchangeMove", "The moves that should be made."));
91        Parameters.Add(new LookupParameter<IVRPEncoding>("VRPTours", "The VRP tours considered in the move."));
92        Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The VRP problem instance"));
93
94        Parameters.Add(new LookupParameter<DoubleValue>("Distance", "The distance of the individual"));
95        Parameters.Add(new LookupParameter<DoubleValue>("Overload", "The overload of the individual"));
96        Parameters.Add(new LookupParameter<DoubleValue>("Tardiness", "The tardiness of the individual"));
[7791]97        Parameters.Add(new LookupParameter<IntValue>("PickupViolations", "The number of pickup violations."));
[6773]98    }
99
100    public override IDeepCloneable Clone(Cloner cloner) {
101      return new PotvinPDExchangeMoveTabuMaker(this, cloner);
102    }
103
104    public override IOperation Apply() {
105      ItemList<IItem> tabuList = TabuListParameter.ActualValue;
106      int tabuTenure = TabuTenureParameter.ActualValue.Value;
107
108      int overlength = tabuList.Count - tabuTenure;
109      if (overlength >= 0) {
110        for (int i = 0; i < tabuTenure - 1; i++)
111          tabuList[i] = tabuList[i + overlength + 1];
112        while (tabuList.Count >= tabuTenure)
113          tabuList.RemoveAt(tabuList.Count - 1);
114      }
115
116      PotvinPDExchangeMove move = PDExchangeMoveParameter.ActualValue;
117      double moveQuality = MoveQualityParameter.ActualValue.Value;
118      double quality = QualityParameter.ActualValue.Value;
119      double baseQuality = moveQuality;
120      if (quality < moveQuality) baseQuality = quality; // we make an uphill move, the lower bound is the solution quality
121
122      double distance = 0;
123      if (DistanceParameter.ActualValue != null)
124        distance = DistanceParameter.ActualValue.Value;
125
126      double overload = 0;
127      if (OverloadParameter.ActualValue != null)
128        overload = OverloadParameter.ActualValue.Value;
129
130      double tardiness = 0;
131      if (TardinessParameter.ActualValue != null)
132        tardiness = TardinessParameter.ActualValue.Value;
133
[7791]134      int pickupViolations = 0;
135      if (PickupViolationsParameter.ActualValue != null)
136        pickupViolations = PickupViolationsParameter.ActualValue.Value;
137
138      tabuList.Add(new PotvinPDRelocateMoveAttribute(baseQuality, move.OldTour, move.City, distance, overload, tardiness, pickupViolations));
139      tabuList.Add(new PotvinPDRelocateMoveAttribute(baseQuality, move.Tour, move.Replaced, distance, overload, tardiness, pickupViolations));
[6773]140      return base.Apply();
141    }
142  }
143}
Note: See TracBrowser for help on using the repository browser.