- Timestamp:
- 05/08/20 16:55:51 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/Creators/GreedyOrienteeringTourCreator.cs
r17525 r17533 66 66 // Find all points within the maximum distance allowed (ellipse) 67 67 var feasiblePoints = ( 68 from point in Enumerable.Range(0, data. RoutingData.Cities)69 let travelCosts = data. RoutingData.GetDistance(data.StartingPoint, point)70 + data. RoutingData.GetDistance(point, data.TerminalPoint) + data.PointVisitingCosts68 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 71 let score = data.GetScore(point) 72 72 where travelCosts <= data.MaximumTravelCosts … … 81 81 data.TerminalPoint 82 82 }; 83 double tourLength = data. RoutingData.GetDistance(data.StartingPoint, data.TerminalPoint);83 double tourLength = data.GetDistance(data.StartingPoint, data.TerminalPoint); 84 84 85 85 // Add points in a greedy way -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/Improvers/OrienteeringLocalImprovementOperator.cs
r17525 r17533 126 126 127 127 // Determine all points that have not yet been visited by this tour 128 var visitablePoints = Enumerable.Range(0, data. RoutingData.Cities).Except(tour).ToList();128 var visitablePoints = Enumerable.Range(0, data.Cities).Except(tour).ToList(); 129 129 130 130 // Determine if any of the visitable points can be included at any position within the tour … … 168 168 double newLength = tourLength; 169 169 // Recalculate length of whole swapped part, in case distances are not symmetric 170 for (int index = position - 1; index < position + blockLength; index++) newLength -= data. RoutingData.GetDistance(tour[index], tour[index + 1]);171 for (int index = position + blockLength - 1; index > position; index--) newLength += data. RoutingData.GetDistance(tour[index], tour[index - 1]);172 newLength += data. RoutingData.GetDistance(tour[position - 1], tour[position + blockLength - 1]);173 newLength += data. RoutingData.GetDistance(tour[position], tour[position + blockLength]);170 for (int index = position - 1; index < position + blockLength; index++) newLength -= data.GetDistance(tour[index], tour[index + 1]); 171 for (int index = position + blockLength - 1; index > position; index--) newLength += data.GetDistance(tour[index], tour[index - 1]); 172 newLength += data.GetDistance(tour[position - 1], tour[position + blockLength - 1]); 173 newLength += data.GetDistance(tour[position], tour[position + blockLength]); 174 174 175 175 if (newLength < tourLength - 0.00001) { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs
r17529 r17533 96 96 } 97 97 public static double CalculateTravelCosts(IOrienteeringProblemData data, IntegerVector solution) { 98 var distance = data. RoutingData.GetPathDistance(solution, closed: false);98 var distance = data.GetPathDistance(solution, closed: false); 99 99 distance += (solution.Length - 2) * data.PointVisitingCosts; 100 100 return distance; 101 101 } 102 102 public static double CalculateTravelCosts(IOrienteeringProblemData data, IList<int> solution) { 103 var distance = data. RoutingData.GetPathDistance(solution, closed: false);103 var distance = data.GetPathDistance(solution, closed: false); 104 104 distance += (solution.Count - 2) * data.PointVisitingCosts; 105 105 return distance; … … 127 127 } 128 128 public static double CalculateInsertionCosts(IOrienteeringProblemData data, IList<int> path, int insertPosition, int point) { 129 double detour = data. RoutingData.GetDistance(path[insertPosition - 1], point) + data.RoutingData.GetDistance(point, path[insertPosition]);129 double detour = data.GetDistance(path[insertPosition - 1], point) + data.GetDistance(point, path[insertPosition]); 130 130 detour += data.PointVisitingCosts; 131 detour -= data. RoutingData.GetDistance(path[insertPosition - 1], path[insertPosition]);131 detour -= data.GetDistance(path[insertPosition - 1], path[insertPosition]); 132 132 return detour; 133 133 } 134 134 public static double CalculateReplacementCosts(IOrienteeringProblemData data, IList<int> path, int replacePosition, int point) { 135 double detour = data. RoutingData.GetDistance(path[replacePosition - 1], point) + data.RoutingData.GetDistance(point, path[replacePosition + 1]);136 detour -= data. RoutingData.GetDistance(path[replacePosition - 1], path[replacePosition]) + data.RoutingData.GetDistance(path[replacePosition], path[replacePosition + 1]);135 double detour = data.GetDistance(path[replacePosition - 1], point) + data.GetDistance(point, path[replacePosition + 1]); 136 detour -= data.GetDistance(path[replacePosition - 1], path[replacePosition]) + data.GetDistance(path[replacePosition], path[replacePosition + 1]); 137 137 return detour; 138 138 } 139 139 public static double CalculateRemovementSaving(IOrienteeringProblemData data, IList<int> path, int removePosition) { 140 double saving = data. RoutingData.GetDistance(path[removePosition - 1], path[removePosition]);141 saving += data. RoutingData.GetDistance(path[removePosition], path[removePosition + 1]);142 saving -= data. RoutingData.GetDistance(path[removePosition - 1], path[removePosition + 1]);140 double saving = data.GetDistance(path[removePosition - 1], path[removePosition]); 141 saving += data.GetDistance(path[removePosition], path[removePosition + 1]); 142 saving -= data.GetDistance(path[removePosition - 1], path[removePosition + 1]); 143 143 saving += data.PointVisitingCosts; 144 144 return saving; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblemdata.cs
r17531 r17533 1 1 using System; 2 using System.Collections.Generic; 2 3 using HEAL.Attic; 3 4 using HeuristicLab.Common; … … 5 6 using HeuristicLab.Data; 6 7 using HeuristicLab.Encodings.IntegerVectorEncoding; 8 using HeuristicLab.Encodings.PermutationEncoding; 9 using HeuristicLab.Problems.Instances; 7 10 using HeuristicLab.Problems.Instances.Types; 8 11 using HeuristicLab.Problems.TravelingSalesman; … … 10 13 namespace HeuristicLab.Problems.Orienteering { 11 14 [StorableType("c33063a6-a2ee-4054-9dd8-46a738003139")] 12 public interface IOrienteeringProblemData : INamedItem { 13 ITSPData RoutingData { get; } 15 public interface IOrienteeringProblemData : ITSPData { 14 16 int StartingPoint { get; } 15 17 int TerminalPoint { get; } … … 19 21 double GetScore(int city); 20 22 OrienteeringSolution GetSolution(IntegerVector route, double quality, double score, double travelCosts); 21 OPData Export();23 new OPData Export(); 22 24 } 23 25 … … 93 95 } 94 96 97 #region ITSPData members 98 int ITSPData.Cities => RoutingData.Cities; 99 double ITSPData.GetDistance(int fromCity, int toCity) => RoutingData.GetDistance(fromCity, toCity); 100 double ITSPData.GetPathDistance(IEnumerable<int> path, bool closed) => RoutingData.GetPathDistance(path, closed); 101 ITSPSolution ITSPData.GetSolution(Permutation tspTour, double tourLength) => RoutingData.GetSolution(tspTour, tourLength); 102 TSPData ITSPData.Export() => RoutingData.Export(); 103 DoubleMatrix ITSPData.GetCoordinatesOrDefault() => RoutingData.GetCoordinatesOrDefault(); 104 #endregion 105 95 106 private static double[,] defaultCoordinates = new double[21, 2] { 96 107 { 4.60, 7.10 }, { 5.70, 11.40 }, { 4.40, 12.30 }, { 2.80, 14.30 }, { 3.20, 10.30 }, -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringSolution.cs
r17526 r17533 31 31 32 32 namespace HeuristicLab.Problems.Orienteering { 33 public interface IOrienteeringSolution : ITSPSolution { 34 new IOrienteeringProblemData Data { get; } 35 new IntegerVector Tour { get; } 36 DoubleValue Quality { get; } 37 DoubleValue Score { get; } 38 DoubleValue TravelCosts { get; } 39 } 40 33 41 [Item("OrienteeringSolution", "Represents a Orienteering solution which can be visualized in the GUI.")] 34 42 [StorableType("BC58ED08-B9A7-40F3-B8E0-A6B33AA993F4")] 35 public sealed class OrienteeringSolution : Item, I TSPSolution {43 public sealed class OrienteeringSolution : Item, IOrienteeringSolution { 36 44 public static new Image StaticItemImage { 37 45 get { return HeuristicLab.Common.Resources.VSImageLibrary.Image; } … … 40 48 [Storable] private Permutation routeAsPermutation; 41 49 [Storable] private IntegerVector route; 42 public IntegerVector Route{50 public IntegerVector Tour { 43 51 get { return route; } 44 52 set { … … 46 54 route = value; 47 55 routeAsPermutation = new Permutation(PermutationTypes.RelativeDirected, value); 48 OnPropertyChanged(nameof(Route)); 49 OnPropertyChanged(nameof(ITSPSolution.Tour)); 56 OnPropertyChanged(nameof(Tour)); 50 57 } 51 58 } 52 [Storable] private IOrienteeringProblemData opData;53 public IOrienteeringProblemData OPData {54 get { return opData; }59 [Storable] private IOrienteeringProblemData data; 60 public IOrienteeringProblemData Data { 61 get { return data; } 55 62 set { 56 if (opData == value) return; 57 opData = value; 58 OnPropertyChanged(nameof(OPData)); 59 OnPropertyChanged(nameof(ITSPSolution.TSPData)); 63 if (data == value) return; 64 data = value; 65 OnPropertyChanged(nameof(Data)); 60 66 } 61 67 } … … 92 98 } 93 99 94 ITSPData ITSPSolution. TSPData => OPData.RoutingData;100 ITSPData ITSPSolution.Data => Data; 95 101 Permutation ITSPSolution.Tour => routeAsPermutation; 96 102 DoubleValue ITSPSolution.TourLength => TravelCosts; … … 102 108 this.route = cloner.Clone(original.route); 103 109 this.routeAsPermutation = cloner.Clone(original.routeAsPermutation); 104 this. opData = cloner.Clone(original.opData);110 this.data = cloner.Clone(original.data); 105 111 this.quality = cloner.Clone(original.quality); 106 112 this.score = cloner.Clone(original.score); … … 112 118 this.route = route; 113 119 this.routeAsPermutation = new Permutation(PermutationTypes.RelativeDirected, route); 114 this. opData = opData;120 this.data = opData; 115 121 this.quality = quality; 116 122 this.score = score; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/Shakers/OrienteeringShakingOperator.cs
r17525 r17533 96 96 var initialTour = IntegerVectorParameter.ActualValue; 97 97 var data = OrienteeringProblemDataParameter.ActualValue; 98 int numPoints = data. RoutingData.Cities;98 int numPoints = data.Cities; 99 99 100 100 if (NeighborhoodCountParameter.ActualValue == null) … … 117 117 from point in Enumerable.Range(0, numPoints) 118 118 // Calculate the distance when going from the starting point to this point and then to the end point 119 let distance = data. RoutingData.GetDistance(data.StartingPoint, point) + data.RoutingData.GetDistance(point, data.TerminalPoint) + data.PointVisitingCosts119 let distance = data.GetDistance(data.StartingPoint, point) + data.GetDistance(point, data.TerminalPoint) + data.PointVisitingCosts 120 120 // If this distance is feasible and the point is neither starting nor ending point, check the point 121 121 where distance < data.MaximumTravelCosts && point != data.StartingPoint && point != data.TerminalPoint
Note: See TracChangeset
for help on using the changeset viewer.