Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveProjectManagement/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/TwoOptStar/PotvinTwoOptStarMoveTabuMaker.cs @ 15377

Last change on this file since 15377 was 14185, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 6.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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 System.Collections.Generic;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.Problems.VehicleRouting.Interfaces;
31
32namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
33  [Item("PotvinTwoOptStarMoveTabuMaker", "Declares a given two opt star move as tabu.")]
34  [StorableClass]
35  public class PotvinTwoOptStarMoveTabuMaker : SingleSuccessorOperator, ITabuMaker, IPotvinTwoOptStarMoveOperator, IPotvinOperator, ISingleObjectiveOperator {
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<PotvinTwoOptStarMove> TwoOptStarMoveParameter {
54      get { return (ILookupParameter<PotvinTwoOptStarMove>)Parameters["PotvinTwoOptStarMove"]; }
55    }
56    public ILookupParameter VRPMoveParameter {
57      get { return TwoOptStarMoveParameter; }
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 PotvinTwoOptStarMoveTabuMaker(bool deserializing) : base(deserializing) { }
78    protected PotvinTwoOptStarMoveTabuMaker(PotvinTwoOptStarMoveTabuMaker original, Cloner cloner) : base(original, cloner) { }
79    public PotvinTwoOptStarMoveTabuMaker()
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<PotvinTwoOptStarMove>("PotvinTwoOptStarMove", "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 PotvinTwoOptStarMoveTabuMaker(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      double distance = 0;
113      if (DistanceParameter.ActualValue != null)
114        distance = DistanceParameter.ActualValue.Value;
115
116      double overload = 0;
117      if (OverloadParameter.ActualValue != null)
118        overload = OverloadParameter.ActualValue.Value;
119
120      double tardiness = 0;
121      if (TardinessParameter.ActualValue != null)
122        tardiness = TardinessParameter.ActualValue.Value;
123
124      PotvinTwoOptStarMove move = TwoOptStarMoveParameter.ActualValue;
125      double moveQuality = MoveQualityParameter.ActualValue.Value;
126      double quality = QualityParameter.ActualValue.Value;
127      double baseQuality = moveQuality;
128      if (quality < moveQuality) baseQuality = quality; // we make an uphill move, the lower bound is the solution quality
129
130      List<int> segmentX1;
131      List<int> segmentX2;
132      PotvinTwoOptStarMoveMaker.GetSegments(move, out segmentX1, out segmentX2);
133
134      foreach (int city in segmentX1) {
135        tabuList.Add(new PotvinTwoOptStarMoveAttribute(baseQuality, move.Tour1, city, distance, overload, tardiness));
136      }
137
138      foreach (int city in segmentX2) {
139        tabuList.Add(new PotvinTwoOptStarMoveAttribute(baseQuality, move.Tour2, city, distance, overload, tardiness));
140      }
141
142      return base.Apply();
143    }
144  }
145}
Note: See TracBrowser for help on using the repository browser.