Changeset 6857 for branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Creators/IterativeInsertionCreator.cs
- Timestamp:
- 09/30/11 15:23:48 (13 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Creators/IterativeInsertionCreator.cs
r6753 r6857 31 31 using HeuristicLab.Problems.VehicleRouting.Interfaces; 32 32 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 33 using HeuristicLab.Problems.VehicleRouting.Variants; 33 34 34 35 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin { … … 64 65 65 66 private static double CalculateAngleToDepot(IVRPProblemInstance instance, int city) { 66 double dx = instance. Coordinates[0,0];67 double dy = instance. Coordinates[0,1];67 double dx = instance.GetCoordinates(0)[0]; 68 double dy = instance.GetCoordinates(0)[1]; 68 69 69 double cx = instance. Coordinates[city,0];70 double cy = instance. Coordinates[city,1];70 double cx = instance.GetCoordinates(city)[0]; 71 double cy = instance.GetCoordinates(city)[1]; 71 72 72 73 double alpha = Math.Atan((cx - dx) / (dy - cy)) * (180.0 / Math.PI); … … 84 85 PotvinEncoding result = new PotvinEncoding(instance); 85 86 87 IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance; 88 86 89 List<int> customers = new List<int>(); 87 for (int i = 0; i < instance.Cities.Value; i++) 88 customers.Add(i + 1); 90 for (int i = 1; i <= instance.Cities.Value; i++) 91 if(pdp == null || pdp.GetDemand(i) >= 0) 92 customers.Add(i); 93 89 94 customers.Sort(delegate(int city1, int city2) 90 95 { … … 96 101 97 102 Tour currentTour = new Tour(); 103 result.Tours.Add(currentTour); 98 104 99 105 int j = random.Next(customers.Count); … … 101 107 int index = (i + j) % customers.Count; 102 108 103 int stopIdx = result.FindBestInsertionPlace(currentTour, customers[index]); 109 int stopIdx = 0; 110 if(currentTour.Stops.Count > 0) 111 result.FindBestInsertionPlace(currentTour, customers[index]); 104 112 currentTour.Stops.Insert(stopIdx, customers[index]); 105 113 106 CVRPEvaluation evaluation = instance.Evaluate(currentTour) as CVRPEvaluation; 114 if (pdp != null) { 115 stopIdx = result.FindBestInsertionPlace(currentTour, pdp.GetPickupDeliveryLocation(customers[index])); 116 currentTour.Stops.Insert(stopIdx, pdp.GetPickupDeliveryLocation(customers[index])); 117 } 118 119 CVRPEvaluation evaluation = instance.EvaluateTour(currentTour, result) as CVRPEvaluation; 107 120 if (result.Tours.Count < instance.Vehicles.Value && 108 121 ((adhereTimeWindows && !instance.Feasible(evaluation)) || ((!adhereTimeWindows) && evaluation.Overload > double.Epsilon))) { 109 currentTour.Stops.RemoveAt(stopIdx); 122 currentTour.Stops.Remove(customers[index]); 123 if (pdp != null) 124 currentTour.Stops.Remove(pdp.GetPickupDeliveryLocation(customers[index])); 110 125 111 if (currentTour.Stops.Count >0)112 result.Tours. Add(currentTour);126 if (currentTour.Stops.Count == 0) 127 result.Tours.Remove(currentTour); 113 128 currentTour = new Tour(); 129 result.Tours.Add(currentTour); 114 130 115 131 currentTour.Stops.Add(customers[index]); 132 if (pdp != null) { 133 currentTour.Stops.Add(pdp.GetPickupDeliveryLocation(customers[index])); 134 } 116 135 } 117 136 } 118 137 119 if (currentTour.Stops.Count >0)120 result.Tours. Add(currentTour);138 if (currentTour.Stops.Count == 0) 139 result.Tours.Remove(currentTour); 121 140 122 141 return result;
Note: See TracChangeset
for help on using the changeset viewer.