[11191] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[11191] | 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 HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
| 28 | using HeuristicLab.Parameters;
|
---|
[16565] | 29 | using HEAL.Attic;
|
---|
[11191] | 30 |
|
---|
| 31 | namespace HeuristicLab.Problems.Orienteering {
|
---|
[12721] | 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.")]
|
---|
[16565] | 41 | [StorableType("FB68525D-DD53-4BE7-A6B4-EC54E6FD0E64")]
|
---|
[11321] | 42 | public sealed class GreedyOrienteeringTourCreator : IntegerVectorCreator, IOrienteeringSolutionCreator {
|
---|
[11191] | 43 | public override bool CanChangeName { get { return false; } }
|
---|
| 44 |
|
---|
| 45 | #region Parameter Properties
|
---|
| 46 | public ILookupParameter<DistanceMatrix> DistanceMatrixParameter {
|
---|
| 47 | get { return (ILookupParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; }
|
---|
| 48 | }
|
---|
| 49 | public ILookupParameter<DoubleArray> ScoresParameter {
|
---|
| 50 | get { return (ILookupParameter<DoubleArray>)Parameters["Scores"]; }
|
---|
| 51 | }
|
---|
| 52 | public ILookupParameter<DoubleValue> MaximumDistanceParameter {
|
---|
| 53 | get { return (ILookupParameter<DoubleValue>)Parameters["MaximumDistance"]; }
|
---|
| 54 | }
|
---|
| 55 | public ILookupParameter<IntValue> StartingPointParameter {
|
---|
| 56 | get { return (ILookupParameter<IntValue>)Parameters["StartingPoint"]; }
|
---|
| 57 | }
|
---|
[11319] | 58 | public ILookupParameter<IntValue> TerminalPointParameter {
|
---|
| 59 | get { return (ILookupParameter<IntValue>)Parameters["TerminalPoint"]; }
|
---|
[11191] | 60 | }
|
---|
[11320] | 61 | public ILookupParameter<DoubleValue> PointVisitingCostsParameter {
|
---|
| 62 | get { return (ILookupParameter<DoubleValue>)Parameters["PointVisitingCosts"]; }
|
---|
[11191] | 63 | }
|
---|
| 64 | #endregion
|
---|
| 65 |
|
---|
| 66 | [StorableConstructor]
|
---|
[16565] | 67 | private GreedyOrienteeringTourCreator(StorableConstructorFlag _) : base(_) { }
|
---|
[11307] | 68 | private GreedyOrienteeringTourCreator(GreedyOrienteeringTourCreator original, Cloner cloner)
|
---|
[11191] | 69 | : base(original, cloner) { }
|
---|
| 70 |
|
---|
| 71 | public GreedyOrienteeringTourCreator()
|
---|
| 72 | : base() {
|
---|
| 73 | Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the points."));
|
---|
| 74 | Parameters.Add(new LookupParameter<DoubleArray>("Scores", "The scores of the points."));
|
---|
| 75 | Parameters.Add(new LookupParameter<DoubleValue>("MaximumDistance", "The maximum distance constraint for a Orienteering solution."));
|
---|
| 76 | Parameters.Add(new LookupParameter<IntValue>("StartingPoint", "Index of the starting point."));
|
---|
[11319] | 77 | Parameters.Add(new LookupParameter<IntValue>("TerminalPoint", "Index of the ending point."));
|
---|
[11320] | 78 | Parameters.Add(new LookupParameter<DoubleValue>("PointVisitingCosts", "The costs for visiting a point."));
|
---|
[11191] | 79 | }
|
---|
| 80 |
|
---|
| 81 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 82 | return new GreedyOrienteeringTourCreator(this, cloner);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[12721] | 85 | protected override IntegerVector Create(IRandom random, IntValue length, IntMatrix bounds) {
|
---|
[11191] | 86 | int startPoint = StartingPointParameter.ActualValue.Value;
|
---|
[11319] | 87 | int endPoint = TerminalPointParameter.ActualValue.Value;
|
---|
[11191] | 88 | int numPoints = ScoresParameter.ActualValue.Length;
|
---|
| 89 | var distances = DistanceMatrixParameter.ActualValue;
|
---|
[11320] | 90 | double pointVisitingCosts = PointVisitingCostsParameter.ActualValue.Value;
|
---|
[11191] | 91 | double maxDistance = MaximumDistanceParameter.ActualValue.Value;
|
---|
| 92 | var scores = ScoresParameter.ActualValue;
|
---|
| 93 |
|
---|
| 94 | // Find all points within the maximum distance allowed (ellipse)
|
---|
[11228] | 95 | var feasiblePoints = (
|
---|
| 96 | from point in Enumerable.Range(0, numPoints)
|
---|
[11320] | 97 | let distance = distances[startPoint, point] + distances[point, endPoint] + pointVisitingCosts
|
---|
[11228] | 98 | let score = scores[point]
|
---|
| 99 | where distance <= maxDistance
|
---|
| 100 | where point != startPoint && point != endPoint
|
---|
| 101 | orderby score descending
|
---|
| 102 | select point
|
---|
| 103 | ).ToList();
|
---|
[11191] | 104 |
|
---|
| 105 | // Add the starting and terminus point
|
---|
| 106 | var tour = new List<int> {
|
---|
| 107 | startPoint,
|
---|
| 108 | endPoint
|
---|
| 109 | };
|
---|
[12721] | 110 | double tourLength = distances[startPoint, endPoint];
|
---|
[11191] | 111 |
|
---|
| 112 | // Add points in a greedy way
|
---|
| 113 | bool insertionPerformed = true;
|
---|
| 114 | while (insertionPerformed) {
|
---|
| 115 | insertionPerformed = false;
|
---|
| 116 |
|
---|
[11228] | 117 | for (int i = 0; i < feasiblePoints.Count; i++) {
|
---|
[11192] | 118 | for (int insertPosition = 1; insertPosition < tour.Count; insertPosition++) {
|
---|
[11191] | 119 | // Create the candidate tour
|
---|
[11320] | 120 | double detour = distances.CalculateInsertionCosts(tour, insertPosition, feasiblePoints[i], pointVisitingCosts);
|
---|
[11191] | 121 |
|
---|
| 122 | // If the insertion would be feasible, perform it
|
---|
[12721] | 123 | if (tourLength + detour <= maxDistance) {
|
---|
[11228] | 124 | tour.Insert(insertPosition, feasiblePoints[i]);
|
---|
[12721] | 125 | tourLength += detour;
|
---|
[11228] | 126 | feasiblePoints.RemoveAt(i);
|
---|
[11191] | 127 | insertionPerformed = true;
|
---|
| 128 | break;
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 | if (insertionPerformed) break;
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | return new IntegerVector(tour.ToArray());
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 | } |
---|