[11191] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15584] | 3 | * Copyright (C) 2002-2018 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;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 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.")]
|
---|
[11191] | 41 | [StorableClass]
|
---|
[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]
|
---|
[11307] | 67 | private GreedyOrienteeringTourCreator(bool deserializing)
|
---|
[11191] | 68 | : base(deserializing) { }
|
---|
[11307] | 69 | private GreedyOrienteeringTourCreator(GreedyOrienteeringTourCreator original, Cloner cloner)
|
---|
[11191] | 70 | : base(original, cloner) { }
|
---|
| 71 |
|
---|
| 72 | public GreedyOrienteeringTourCreator()
|
---|
| 73 | : base() {
|
---|
| 74 | Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the points."));
|
---|
| 75 | Parameters.Add(new LookupParameter<DoubleArray>("Scores", "The scores of the points."));
|
---|
| 76 | Parameters.Add(new LookupParameter<DoubleValue>("MaximumDistance", "The maximum distance constraint for a Orienteering solution."));
|
---|
| 77 | Parameters.Add(new LookupParameter<IntValue>("StartingPoint", "Index of the starting point."));
|
---|
[11319] | 78 | Parameters.Add(new LookupParameter<IntValue>("TerminalPoint", "Index of the ending point."));
|
---|
[11320] | 79 | Parameters.Add(new LookupParameter<DoubleValue>("PointVisitingCosts", "The costs for visiting a point."));
|
---|
[11191] | 80 | }
|
---|
| 81 |
|
---|
| 82 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 83 | return new GreedyOrienteeringTourCreator(this, cloner);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[12721] | 86 | protected override IntegerVector Create(IRandom random, IntValue length, IntMatrix bounds) {
|
---|
[11191] | 87 | int startPoint = StartingPointParameter.ActualValue.Value;
|
---|
[11319] | 88 | int endPoint = TerminalPointParameter.ActualValue.Value;
|
---|
[11191] | 89 | int numPoints = ScoresParameter.ActualValue.Length;
|
---|
| 90 | var distances = DistanceMatrixParameter.ActualValue;
|
---|
[11320] | 91 | double pointVisitingCosts = PointVisitingCostsParameter.ActualValue.Value;
|
---|
[11191] | 92 | double maxDistance = MaximumDistanceParameter.ActualValue.Value;
|
---|
| 93 | var scores = ScoresParameter.ActualValue;
|
---|
| 94 |
|
---|
| 95 | // Find all points within the maximum distance allowed (ellipse)
|
---|
[11228] | 96 | var feasiblePoints = (
|
---|
| 97 | from point in Enumerable.Range(0, numPoints)
|
---|
[11320] | 98 | let distance = distances[startPoint, point] + distances[point, endPoint] + pointVisitingCosts
|
---|
[11228] | 99 | let score = scores[point]
|
---|
| 100 | where distance <= maxDistance
|
---|
| 101 | where point != startPoint && point != endPoint
|
---|
| 102 | orderby score descending
|
---|
| 103 | select point
|
---|
| 104 | ).ToList();
|
---|
[11191] | 105 |
|
---|
| 106 | // Add the starting and terminus point
|
---|
| 107 | var tour = new List<int> {
|
---|
| 108 | startPoint,
|
---|
| 109 | endPoint
|
---|
| 110 | };
|
---|
[12721] | 111 | double tourLength = distances[startPoint, endPoint];
|
---|
[11191] | 112 |
|
---|
| 113 | // Add points in a greedy way
|
---|
| 114 | bool insertionPerformed = true;
|
---|
| 115 | while (insertionPerformed) {
|
---|
| 116 | insertionPerformed = false;
|
---|
| 117 |
|
---|
[11228] | 118 | for (int i = 0; i < feasiblePoints.Count; i++) {
|
---|
[11192] | 119 | for (int insertPosition = 1; insertPosition < tour.Count; insertPosition++) {
|
---|
[11191] | 120 | // Create the candidate tour
|
---|
[11320] | 121 | double detour = distances.CalculateInsertionCosts(tour, insertPosition, feasiblePoints[i], pointVisitingCosts);
|
---|
[11191] | 122 |
|
---|
| 123 | // If the insertion would be feasible, perform it
|
---|
[12721] | 124 | if (tourLength + detour <= maxDistance) {
|
---|
[11228] | 125 | tour.Insert(insertPosition, feasiblePoints[i]);
|
---|
[12721] | 126 | tourLength += detour;
|
---|
[11228] | 127 | feasiblePoints.RemoveAt(i);
|
---|
[11191] | 128 | insertionPerformed = true;
|
---|
| 129 | break;
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 | if (insertionPerformed) break;
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | return new IntegerVector(tour.ToArray());
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
| 139 | } |
---|