Changeset 6752 for branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPEvaluator.cs
- Timestamp:
- 09/13/11 16:00:19 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPEvaluator.cs
r4752 r6752 48 48 49 49 protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) { 50 TourInsertionInfo tourInfo = new TourInsertionInfo(); 51 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 52 50 53 IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance; 51 54 DoubleArray demand = instance.Demand; … … 54 57 double overweight = 0.0; 55 58 double distance = 0.0; 59 60 double capacity = cvrpInstance.Capacity.Value; 61 for (int i = 0; i <= tour.Stops.Count; i++) { 62 int end = 0; 63 if (i < tour.Stops.Count) 64 end = tour.Stops[i]; 65 66 delivered += demand[end]; 67 } 68 69 double spareCapacity = capacity - delivered; 56 70 57 71 //simulate a tour, start and end at depot … … 68 82 distance += currentDistace; 69 83 70 delivered += demand[end]; 84 CVRPInsertionInfo stopInfo = new CVRPInsertionInfo(start, end, spareCapacity); 85 tourInfo.AddStopInsertionInfo(stopInfo); 71 86 } 72 87 … … 77 92 eval.VehicleUtilization += 1; 78 93 79 double capacity = cvrpInstance.Capacity.Value;80 94 if (delivered > capacity) { 81 95 overweight = delivered - capacity; … … 86 100 eval.Penalty += penalty; 87 101 eval.Quality += penalty; 102 tourInfo.Penalty = penalty; 103 } 104 105 protected override double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer, 106 out bool feasible) { 107 CVRPInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPInsertionInfo; 108 109 double costs = 0; 110 feasible = tourInsertionInfo.Penalty < double.Epsilon; 111 112 ICapacitatedProblemInstance cvrp = instance as ICapacitatedProblemInstance; 113 double overloadPenalty = cvrp.OverloadPenalty.Value; 114 115 double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End); 116 double newDistance = 117 instance.GetDistance(insertionInfo.Start, customer) + 118 instance.GetDistance(customer, insertionInfo.End); 119 costs += instance.DistanceFactor.Value * (newDistance - distance); 120 121 double demand = instance.Demand[customer]; 122 if (demand > insertionInfo.SpareCapacity) { 123 feasible = false; 124 125 if(insertionInfo.SpareCapacity >= 0) 126 costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty; 127 else 128 costs += demand * overloadPenalty; 129 } 130 131 return costs; 88 132 } 89 133
Note: See TracChangeset
for help on using the changeset viewer.