1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 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 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using System.Linq;
|
---|
24 | using HEAL.Attic;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
29 | using HeuristicLab.Parameters;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Problems.Orienteering {
|
---|
32 | /// <summary>
|
---|
33 | /// The initial solution for P-VNS is generated by means of a greedy algorithm that takes into
|
---|
34 | /// account all vertices vi that are located within the cost limit Tmax. These points are sorted
|
---|
35 | /// in descending order regarding the sum of their objective values. Afterwards, the algorithm
|
---|
36 | /// starts with a tour only including the starting and ending point and successively inserts the
|
---|
37 | /// points from this list at the first position in which they can feasibly be inserted.
|
---|
38 | /// (Schilde et. al. 2009)
|
---|
39 | /// </summary>
|
---|
40 | [Item("GreedyOrienteeringTourCreator", @"Implements the solution creation procedure described in Schilde M., Doerner K.F., Hartl R.F., Kiechle G. 2009. Metaheuristics for the bi-objective orienteering problem. Swarm Intelligence, Volume 3, Issue 3, pp 179-201.")]
|
---|
41 | [StorableType("FB68525D-DD53-4BE7-A6B4-EC54E6FD0E64")]
|
---|
42 | public sealed class GreedyOrienteeringTourCreator : IntegerVectorCreator, IOrienteeringSolutionCreator {
|
---|
43 | public override bool CanChangeName { get { return false; } }
|
---|
44 |
|
---|
45 | public ILookupParameter<IOrienteeringProblemData> OrienteeringProblemDataParameter {
|
---|
46 | get { return (ILookupParameter<IOrienteeringProblemData>)Parameters["OrienteeringProblemData"]; }
|
---|
47 | }
|
---|
48 |
|
---|
49 | [StorableConstructor]
|
---|
50 | private GreedyOrienteeringTourCreator(StorableConstructorFlag _) : base(_) { }
|
---|
51 | private GreedyOrienteeringTourCreator(GreedyOrienteeringTourCreator original, Cloner cloner)
|
---|
52 | : base(original, cloner) { }
|
---|
53 |
|
---|
54 | public GreedyOrienteeringTourCreator()
|
---|
55 | : base() {
|
---|
56 | Parameters.Add(new LookupParameter<IOrienteeringProblemData>("OrienteeringProblemData", "The main data that comprises the orienteering problem."));
|
---|
57 | }
|
---|
58 |
|
---|
59 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
60 | return new GreedyOrienteeringTourCreator(this, cloner);
|
---|
61 | }
|
---|
62 |
|
---|
63 | protected override IntegerVector Create(IRandom random, IntValue length, IntMatrix bounds) {
|
---|
64 | var data = OrienteeringProblemDataParameter.ActualValue;
|
---|
65 |
|
---|
66 | // Find all points within the maximum distance allowed (ellipse)
|
---|
67 | var feasiblePoints = (
|
---|
68 | from point in Enumerable.Range(0, data.Cities)
|
---|
69 | let travelCosts = data.GetDistance(data.StartingPoint, point)
|
---|
70 | + data.GetDistance(point, data.TerminalPoint) + data.PointVisitingCosts
|
---|
71 | let score = data.GetScore(point)
|
---|
72 | where travelCosts <= data.MaximumTravelCosts
|
---|
73 | where point != data.StartingPoint && point != data.TerminalPoint
|
---|
74 | orderby score descending
|
---|
75 | select point
|
---|
76 | ).ToList();
|
---|
77 |
|
---|
78 | // Add the starting and terminus point
|
---|
79 | var tour = new List<int> {
|
---|
80 | data.StartingPoint,
|
---|
81 | data.TerminalPoint
|
---|
82 | };
|
---|
83 | double tourLength = data.GetDistance(data.StartingPoint, data.TerminalPoint);
|
---|
84 |
|
---|
85 | // Add points in a greedy way
|
---|
86 | bool insertionPerformed = true;
|
---|
87 | while (insertionPerformed) {
|
---|
88 | insertionPerformed = false;
|
---|
89 |
|
---|
90 | for (int i = 0; i < feasiblePoints.Count; i++) {
|
---|
91 | for (int insertPosition = 1; insertPosition < tour.Count; insertPosition++) {
|
---|
92 | // Create the candidate tour
|
---|
93 | double detour = OrienteeringProblem.CalculateInsertionCosts(data, tour, insertPosition, feasiblePoints[i]);
|
---|
94 |
|
---|
95 | // If the insertion would be feasible, perform it
|
---|
96 | if (tourLength + detour <= data.MaximumTravelCosts) {
|
---|
97 | tour.Insert(insertPosition, feasiblePoints[i]);
|
---|
98 | tourLength += detour;
|
---|
99 | feasiblePoints.RemoveAt(i);
|
---|
100 | insertionPerformed = true;
|
---|
101 | break;
|
---|
102 | }
|
---|
103 | }
|
---|
104 | if (insertionPerformed) break;
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | return new IntegerVector(tour.ToArray());
|
---|
109 | }
|
---|
110 | }
|
---|
111 | } |
---|