Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDExchange/PotvinPDExchangeMoveTabuMaker.cs @ 12005

Last change on this file since 12005 was 12005, checked in by abeham, 10 years ago

#2174, #2282: merged revisions r11961,r11963,r11967,r11970,r11971,r11982,r11984,r11998,r12001,r12002,r12003,r12004,r11939,r11945,r11956,r11958,r11959,r11960,r11983,r11987,r11988,r11990,r11993,r11994,r11996,r11999,r12000 to stable

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