Changeset 11320 for branches/HeuristicLab.Problems.Orienteering
- Timestamp:
- 09/01/14 10:36:54 (10 years ago)
- Location:
- branches/HeuristicLab.Problems.Orienteering
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Instances/3.3/Types/OPData.cs
r11319 r11320 37 37 /// The penalty for each visited vertex. 38 38 /// </summary> 39 public double FixedPenalty{ get; set; }39 public double PointVisitingCosts { get; set; } 40 40 /// <summary> 41 41 /// Index of the starting point -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/Creators/GreedyOrienteeringTourCreator.cs
r11319 r11320 55 55 get { return (ILookupParameter<IntValue>)Parameters["TerminalPoint"]; } 56 56 } 57 public ILookupParameter<DoubleValue> FixedPenaltyParameter {58 get { return (ILookupParameter<DoubleValue>)Parameters[" FixedPenalty"]; }57 public ILookupParameter<DoubleValue> PointVisitingCostsParameter { 58 get { return (ILookupParameter<DoubleValue>)Parameters["PointVisitingCosts"]; } 59 59 } 60 60 #endregion … … 73 73 Parameters.Add(new LookupParameter<IntValue>("StartingPoint", "Index of the starting point.")); 74 74 Parameters.Add(new LookupParameter<IntValue>("TerminalPoint", "Index of the ending point.")); 75 Parameters.Add(new LookupParameter<DoubleValue>(" FixedPenalty", "The penalty for each visited vertex."));75 Parameters.Add(new LookupParameter<DoubleValue>("PointVisitingCosts", "The costs for visiting a point.")); 76 76 } 77 77 … … 85 85 int numPoints = ScoresParameter.ActualValue.Length; 86 86 var distances = DistanceMatrixParameter.ActualValue; 87 double fixedPenalty = FixedPenaltyParameter.ActualValue.Value;87 double pointVisitingCosts = PointVisitingCostsParameter.ActualValue.Value; 88 88 double maxDistance = MaximumDistanceParameter.ActualValue.Value; 89 89 var scores = ScoresParameter.ActualValue; … … 92 92 var feasiblePoints = ( 93 93 from point in Enumerable.Range(0, numPoints) 94 let distance = distances[startPoint, point] + distances[point, endPoint] + fixedPenalty94 let distance = distances[startPoint, point] + distances[point, endPoint] + pointVisitingCosts 95 95 let score = scores[point] 96 96 where distance <= maxDistance … … 115 115 for (int insertPosition = 1; insertPosition < tour.Count; insertPosition++) { 116 116 // Create the candidate tour 117 double detour = distances.CalculateInsertionCosts(tour, insertPosition, feasiblePoints[i], fixedPenalty);117 double detour = distances.CalculateInsertionCosts(tour, insertPosition, feasiblePoints[i], pointVisitingCosts); 118 118 119 119 // If the insertion would be feasible, perform it -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/DistanceMatrix.cs
r11228 r11320 53 53 } 54 54 55 public double CalculateTourLength(IList<int> path, double fixedPenalty) {55 public double CalculateTourLength(IList<int> path, double pointVisitingCosts) { 56 56 double length = 0.0; 57 57 for (int i = 1; i < path.Count; i++) 58 58 length += this[path[i - 1], path[i]]; 59 59 // Add the fixed penalty for every vertex except for the starting and ending vertex 60 length += (path.Count - 2) * fixedPenalty;60 length += (path.Count - 2) * pointVisitingCosts; 61 61 return length; 62 62 } 63 public double CalculateInsertionCosts(IList<int> path, int insertPosition, int point, double fixedPenalty) {63 public double CalculateInsertionCosts(IList<int> path, int insertPosition, int point, double pointVisitingCosts) { 64 64 double detour = this[path[insertPosition - 1], point] + this[point, path[insertPosition]]; 65 detour += fixedPenalty;65 detour += pointVisitingCosts; 66 66 detour -= this[path[insertPosition - 1], path[insertPosition]]; 67 67 return detour; … … 72 72 return detour; 73 73 } 74 public double CalculateRemovementSaving(List<int> path, int removePosition, double fixedPenalty) {74 public double CalculateRemovementSaving(List<int> path, int removePosition, double pointVisitingCosts) { 75 75 double saving = this[path[removePosition - 1], path[removePosition]]; 76 76 saving += this[path[removePosition], path[removePosition + 1]]; 77 77 saving -= this[path[removePosition - 1], path[removePosition + 1]]; 78 saving += fixedPenalty;78 saving += pointVisitingCosts; 79 79 return saving; 80 80 } -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/Evaluators/OrienteeringEvaluator.cs
r11311 r11320 55 55 get { return (ILookupParameter<DoubleValue>)Parameters["MaximumDistance"]; } 56 56 } 57 public ILookupParameter<DoubleValue> FixedPenaltyParameter {58 get { return (ILookupParameter<DoubleValue>)Parameters[" FixedPenalty"]; }57 public ILookupParameter<DoubleValue> PointVisitingCostsParameter { 58 get { return (ILookupParameter<DoubleValue>)Parameters["PointVisitingCosts"]; } 59 59 } 60 60 #endregion … … 80 80 Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the points.")); 81 81 Parameters.Add(new LookupParameter<DoubleValue>("MaximumDistance", "The maximum distance constraint for a Orienteering solution.")); 82 Parameters.Add(new LookupParameter<DoubleValue>(" FixedPenalty", "The penalty for each visited vertex."));82 Parameters.Add(new LookupParameter<DoubleValue>("PointVisitingCosts", "The costs for visiting a point.")); 83 83 } 84 84 … … 89 89 90 90 public static OrienteeringEvaluation Apply(IntegerVector solution, DoubleArray scores, 91 DistanceMatrix distances, DoubleValue maximumDistance, DoubleValue fixedPenalty, DoubleValue distancePenaltyFactor) {91 DistanceMatrix distances, DoubleValue maximumDistance, DoubleValue pointVisitingCosts, DoubleValue distancePenaltyFactor) { 92 92 93 93 double score = solution.Sum(t => scores[t]); 94 double distance = distances.CalculateTourLength(solution.ToList(), fixedPenalty.Value);94 double distance = distances.CalculateTourLength(solution.ToList(), pointVisitingCosts.Value); 95 95 96 96 double distanceViolation = distance - maximumDistance.Value; … … 110 110 var evaluation = Apply(IntegerVectorParameter.ActualValue, ScoresParameter.ActualValue, 111 111 DistanceMatrixParameter.ActualValue, MaximumDistanceParameter.ActualValue, 112 FixedPenaltyParameter.ActualValue, DistancePenaltyFactorParameter.ActualValue);112 PointVisitingCostsParameter.ActualValue, DistancePenaltyFactorParameter.ActualValue); 113 113 114 114 QualityParameter.ActualValue = evaluation.Quality; -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/Improvers/OrienteeringLocalImprovementOperator.cs
r11319 r11320 58 58 get { return (ILookupParameter<IntValue>)Parameters["TerminalPoint"]; } 59 59 } 60 public ILookupParameter<DoubleValue> FixedPenaltyParameter {61 get { return (ILookupParameter<DoubleValue>)Parameters[" FixedPenalty"]; }60 public ILookupParameter<DoubleValue> PointVisitingCostsParameter { 61 get { return (ILookupParameter<DoubleValue>)Parameters["PointVisitingCosts"]; } 62 62 } 63 63 #region ILocalImprovementOperator Parameters … … 99 99 Parameters.Add(new LookupParameter<IntValue>("StartingPoint", "Index of the starting point.")); 100 100 Parameters.Add(new LookupParameter<IntValue>("TerminalPoint", "Index of the ending point.")); 101 Parameters.Add(new LookupParameter<DoubleValue>(" FixedPenalty", "The penalty for each visited vertex."));101 Parameters.Add(new LookupParameter<DoubleValue>("PointVisitingCosts", "The costs for visiting a point.")); 102 102 103 103 Parameters.Add(new ValueLookupParameter<IntValue>("LocalIterations", "The number of iterations that have already been performed.", new IntValue(0))); … … 119 119 var distances = DistanceMatrixParameter.ActualValue; 120 120 var scores = ScoresParameter.ActualValue; 121 double fixedPenalty = FixedPenaltyParameter.ActualValue.Value;121 double pointVisitingCosts = PointVisitingCostsParameter.ActualValue.Value; 122 122 double maxLength = MaximumDistanceParameter.ActualValue.Value; 123 123 int maxIterations = MaximumIterationsParameter.ActualValue.Value; … … 129 129 var tour = IntegerVectorParameter.ActualValue.ToList(); 130 130 131 double tourLength = distances.CalculateTourLength(tour, fixedPenalty);131 double tourLength = distances.CalculateTourLength(tour, pointVisitingCosts); 132 132 double tourScore = tour.Sum(point => scores[point]); 133 133 … … 148 148 // Determine if any of the visitable points can be included at any position within the tour 149 149 IncludeNewPoints(tour, visitablePoints, 150 distances, fixedPenalty, maxLength, scores,150 distances, pointVisitingCosts, maxLength, scores, 151 151 ref tourLength, ref tourScore, ref evaluations, ref optimizationDone); 152 152 … … 211 211 } 212 212 private void IncludeNewPoints(List<int> tour, List<int> visitablePoints, 213 DistanceMatrix distances, double fixedPenalty, double maxLength, DoubleArray scores,213 DistanceMatrix distances, double pointVisitingCosts, double maxLength, DoubleArray scores, 214 214 ref double tourLength, ref double tourScore, ref int evaluations, ref bool optimizationDone) { 215 215 … … 224 224 evaluations++; 225 225 226 double detour = distances.CalculateInsertionCosts(tour, tourPosition, visitablePoints[i], fixedPenalty);226 double detour = distances.CalculateInsertionCosts(tour, tourPosition, visitablePoints[i], pointVisitingCosts); 227 227 228 228 // Determine if including the point does not violate any constraint -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs
r11319 r11320 64 64 get { return (ValueParameter<DoubleArray>)Parameters["Scores"]; } 65 65 } 66 public ValueParameter<DoubleValue> FixedPenaltyParameter {67 get { return (ValueParameter<DoubleValue>)Parameters[" FixedPenalty"]; }66 public ValueParameter<DoubleValue> PointVisitingCostsParameter { 67 get { return (ValueParameter<DoubleValue>)Parameters["PointVisitingCosts"]; } 68 68 } 69 69 … … 98 98 set { ScoresParameter.Value = value; } 99 99 } 100 public DoubleValue FixedPenalty{101 get { return FixedPenaltyParameter.Value; }102 set { FixedPenaltyParameter.Value = value; }100 public DoubleValue PointVisitingCosts { 101 get { return PointVisitingCostsParameter.Value; } 102 set { PointVisitingCostsParameter.Value = value; } 103 103 } 104 104 public IntegerVector BestKnownSolution { … … 130 130 Parameters.Add(new ValueParameter<DoubleValue>("MaximumDistance", "The maximum distance constraint for a Orienteering solution.")); 131 131 Parameters.Add(new ValueParameter<DoubleArray>("Scores", "The scores of the points.")); 132 Parameters.Add(new ValueParameter<DoubleValue>(" FixedPenalty", "The penalty for each visited vertex."));132 Parameters.Add(new ValueParameter<DoubleValue>("PointVisitingCosts", "The costs for visiting a point.")); 133 133 Parameters.Add(new OptionalValueParameter<IntegerVector>("BestKnownSolution", "The best known solution of this Orienteering instance.")); 134 134 … … 204 204 ParameterizeSolutionCreator(); 205 205 } 206 private void FixedPenaltyParameter_ValueChanged(object sender, EventArgs e) {206 private void PointVisitingCostsParameter_ValueChanged(object sender, EventArgs e) { 207 207 ParameterizeEvaluator(); 208 208 ParameterizeAnalyzer(); … … 231 231 ScoresParameter.ValueChanged += ScoresParameter_ValueChanged; 232 232 ScoresParameter.Value.Reset += ScoresValue_Reset; 233 FixedPenaltyParameter.ValueChanged += FixedPenaltyParameter_ValueChanged;233 PointVisitingCostsParameter.ValueChanged += PointVisitingCostsParameter_ValueChanged; 234 234 } 235 235 … … 242 242 creator.StartingPointParameter.ActualName = StartingPointParameter.Name; 243 243 creator.TerminalPointParameter.ActualName = TerminalPointParameter.Name; 244 creator. FixedPenaltyParameter.ActualName = FixedPenaltyParameter.Name;244 creator.PointVisitingCostsParameter.ActualName = PointVisitingCostsParameter.Name; 245 245 } 246 246 } … … 281 281 op.StartingPointParameter.ActualName = StartingPointParameter.Name; 282 282 op.TerminalPointParameter.ActualName = TerminalPointParameter.Name; 283 op. FixedPenaltyParameter.ActualName = FixedPenaltyParameter.Name;283 op.PointVisitingCostsParameter.ActualName = PointVisitingCostsParameter.Name; 284 284 } 285 285 foreach (var op in Operators.OfType<OrienteeringShakingOperator>()) { … … 290 290 op.StartingPointParameter.ActualName = StartingPointParameter.Name; 291 291 op.TerminalPointParameter.ActualName = TerminalPointParameter.Name; 292 op. FixedPenaltyParameter.ActualName = FixedPenaltyParameter.Name;292 op.PointVisitingCostsParameter.ActualName = PointVisitingCostsParameter.Name; 293 293 } 294 294 } … … 362 362 TerminalPoint = new IntValue(data.TerminalPoint); 363 363 364 PointVisitingCosts = new DoubleValue(data.PointVisitingCosts); 364 365 MaximumDistance = new DoubleValue(data.MaximumDistance); 365 366 Scores = new DoubleArray(data.Scores); … … 388 389 TerminalPoint = new IntValue(data.Dimension - 1); // Last city is interpreted als end point 389 390 391 PointVisitingCosts = new DoubleValue(0); 390 392 MaximumDistance = new DoubleValue(DistanceMatrix.Average() * 5.0); // distance from start to end first to last city is interpreted as maximum distance 391 393 Scores = new DoubleArray(Enumerable.Repeat(1.0, data.Dimension).ToArray()); // all scores are 1 … … 413 415 TerminalPoint = new IntValue(0); // Depot is interpreted als end point 414 416 417 PointVisitingCosts = new DoubleValue(0); 415 418 MaximumDistance = new DoubleValue(data.Capacity * 2); // capacity is interpreted as max distance 416 419 Scores = new DoubleArray(data.Demands); // demands are interpreted as scores 417 418 OnReset();419 420 } 420 421 } -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/Shakers/OrienteeringShakingOperator.cs
r11319 r11320 76 76 get { return (ILookupParameter<DoubleArray>)Parameters["Scores"]; } 77 77 } 78 public ILookupParameter<DoubleValue> FixedPenaltyParameter {79 get { return (ILookupParameter<DoubleValue>)Parameters[" FixedPenalty"]; }78 public ILookupParameter<DoubleValue> PointVisitingCostsParameter { 79 get { return (ILookupParameter<DoubleValue>)Parameters["PointVisitingCosts"]; } 80 80 } 81 81 … … 101 101 Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the points.")); 102 102 Parameters.Add(new LookupParameter<DoubleArray>("Scores", "The scores of the points.")); 103 Parameters.Add(new LookupParameter<DoubleValue>(" FixedPenalty", "The penalty for each visited vertex."));103 Parameters.Add(new LookupParameter<DoubleValue>("PointVisitingCosts", "The costs for visiting a point.")); 104 104 105 105 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator that will be used.")); … … 116 116 var startingPoint = StartingPointParameter.ActualValue.Value; 117 117 var terminalPoint = TerminalPointParameter.ActualValue.Value; 118 var fixedPenalty = FixedPenaltyParameter.ActualValue.Value;118 var pointVisitingCosts = PointVisitingCostsParameter.ActualValue.Value; 119 119 double maxDistance = MaximumDistanceParameter.ActualValue.Value; 120 120 int numPoints = scores.Length; … … 139 139 from point in Enumerable.Range(0, numPoints) 140 140 // Calculate the distance when going from the starting point to this point and then to the end point 141 let distance = distances[startingPoint, point] + distances[point, terminalPoint] + fixedPenalty141 let distance = distances[startingPoint, point] + distances[point, terminalPoint] + pointVisitingCosts 142 142 // If this distance is feasible and the point is neither starting nor ending point, check the point 143 143 where distance < maxDistance && point != startingPoint && point != terminalPoint … … 157 157 158 158 // Bring the tour back to be feasible 159 CleanupTour(actualTour, distances, maxDistance, fixedPenalty);159 CleanupTour(actualTour, distances, maxDistance, pointVisitingCosts); 160 160 161 161 // Set new Tour … … 208 208 } 209 209 } 210 private void CleanupTour(List<int> actualTour, DistanceMatrix distances, double maxDistance, double fixedPenalty) {210 private void CleanupTour(List<int> actualTour, DistanceMatrix distances, double maxDistance, double pointVisitingCosts) { 211 211 // Sort the points on the tour according to their costs savings when removed 212 212 var distanceSavings = ( 213 213 from removePosition in Enumerable.Range(1, actualTour.Count - 2) 214 let saving = distances.CalculateRemovementSaving(actualTour, removePosition, fixedPenalty)214 let saving = distances.CalculateRemovementSaving(actualTour, removePosition, pointVisitingCosts) 215 215 orderby saving descending 216 216 select new SavingInfo { Index = removePosition, Saving = saving } 217 217 ).ToList(); 218 218 219 double tourLength = distances.CalculateTourLength(actualTour, fixedPenalty);219 double tourLength = distances.CalculateTourLength(actualTour, pointVisitingCosts); 220 220 221 221 // As long as the created path is infeasible, remove elements … … 223 223 // Remove the point that frees the largest distance 224 224 // Note, distance savings are not updated after removal 225 tourLength -= distances.CalculateRemovementSaving(actualTour, distanceSavings[0].Index, fixedPenalty);225 tourLength -= distances.CalculateRemovementSaving(actualTour, distanceSavings[0].Index, pointVisitingCosts); 226 226 actualTour.RemoveAt(distanceSavings[0].Index); 227 227
Note: See TracChangeset
for help on using the changeset viewer.