- Timestamp:
- 09/29/11 15:51:56 (13 years ago)
- Location:
- branches/VRP
- Files:
-
- 21 added
- 1 deleted
- 43 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting.Views/3.4/CVRPPDTWView.cs
r6789 r6851 95 95 96 96 t += Content.GetDistance( 97 lastCustomer, location );97 lastCustomer, location, Solution); 98 98 99 99 if (t < readyTime[location]) { -
branches/VRP/HeuristicLab.Problems.VehicleRouting.Views/3.4/CVRPTWView.cs
r4374 r6851 76 76 77 77 t += Content.GetDistance( 78 lastCustomer, location );78 lastCustomer, location, Solution); 79 79 80 80 if (t < readyTime[location]) { -
branches/VRP/HeuristicLab.Problems.VehicleRouting.Views/3.4/HeuristicLab.Problems.VehicleRouting.Views-3.4.csproj
r6710 r6851 112 112 </ItemGroup> 113 113 <ItemGroup> 114 <Compile Include="MultiDepotVRPView.cs"> 115 <SubType>UserControl</SubType> 116 </Compile> 117 <Compile Include="MultiDepotVRPView.Designer.cs"> 118 <DependentUpon>MultiDepotVRPView.cs</DependentUpon> 119 </Compile> 114 120 <Compile Include="CVRPPDTWView.cs"> 115 121 <SubType>UserControl</SubType> -
branches/VRP/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPImportDialog.Designer.cs
r6710 r6851 85 85 this.openVRPFileDialog.DefaultExt = "vrp"; 86 86 this.openVRPFileDialog.FileName = "vrp"; 87 this.openVRPFileDialog.Filter = "TSPLib Format|*.vrp|Solomon Format|*.txt|ORLib Format|*.txt|LiLim Format|*.txt ";88 this.openVRPFileDialog.Title = "Open TSP File";87 this.openVRPFileDialog.Filter = "TSPLib Format|*.vrp|Solomon Format|*.txt|ORLib Format|*.txt|LiLim Format|*.txt|Cordeau Format|*.md"; 88 this.openVRPFileDialog.Title = "Open VRP File"; 89 89 // 90 90 // tspFileLabel -
branches/VRP/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPImportDialog.cs
r6710 r6851 27 27 28 28 namespace HeuristicLab.Problems.VehicleRouting.Views { 29 public enum VRPFormat { Empty, TSPLib, Solomon, ORLib, LiLim }29 public enum VRPFormat { Empty, TSPLib, Solomon, ORLib, LiLim, Cordeau } 30 30 31 31 public sealed partial class VRPImportDialog : Form { -
branches/VRP/HeuristicLab.Problems.VehicleRouting.Views/3.4/VehicleRoutingProblemView.cs
r6710 r6851 86 86 Content.ImportFromLiLim(vrpImportDialog.VRPFileName); 87 87 break; 88 89 case VRPFormat.Cordeau: 90 Content.ImportFromCordeau(vrpImportDialog.VRPFileName); 91 break; 88 92 } 89 93 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/AlbaEncoding.cs
r6710 r6851 33 33 [Item("AlbaEncoding", "Represents an Alba encoding of VRP solutions. It is implemented as described in Alba, E. and Dorronsoro, B. (2004). Solving the Vehicle Routing Problem by Using Cellular Genetic Algorithms.")] 34 34 [StorableClass] 35 public class AlbaEncoding : PermutationEncoding , IHeterogenousCapacitatedEncoding{35 public class AlbaEncoding : PermutationEncoding { 36 36 #region IVRPEncoding Members 37 37 public override List<Tour> GetTours() { 38 Repair(); 38 39 List<Tour> result = new List<Tour>(); 39 40 … … 55 56 if (tour.Stops.Count > 0) { 56 57 result.Add(tour); 57 } 58 } 58 59 59 60 return result; 60 61 } 61 #endregion62 62 63 #region IHeterogenousCapacitatedEncoding Members 64 65 public int GetVehicleAssignment(int tour) { 63 public override int GetVehicleAssignment(int tour) { 66 64 int vehicleAssignment = -1; 67 65 Tour currentTour = GetTours()[tour]; … … 72 70 int lastStopIndex = this.IndexOf(lastStop); 73 71 74 if (lastStopIndex == this.Length - 1) 75 vehicleAssignment = this.ProblemInstance.Vehicles.Value - 1; 72 if (lastStopIndex == this.Length - 1) { 73 int i = this.Length - 1; 74 75 while (vehicleAssignment == -1) { 76 if (this.array[i] >= ProblemInstance.Cities.Value) { 77 vehicleAssignment = this.array[i] - ProblemInstance.Cities.Value; 78 } 79 80 i--; 81 } 82 } 76 83 else 77 84 vehicleAssignment = this[lastStopIndex + 1] - this.ProblemInstance.Cities.Value; … … 80 87 } 81 88 #endregion 89 90 public void Repair() { 91 int cities = ProblemInstance.Cities.Value; 92 93 if (this[this.Length - 1] < cities) { 94 int index = this.Length - 2; 95 while (this[index] < cities) { 96 index--; 97 } 98 99 int vehicle = this[index]; 100 for (int i = index; i < this.Length - 1; i++) 101 this[i] = this[i + 1]; 102 this[Length - 1] = vehicle; 103 } 104 } 82 105 83 106 public AlbaEncoding(Permutation permutation, IVRPProblemInstance instance) … … 100 123 public static AlbaEncoding ConvertFrom(List<int> routeParam, IVRPProblemInstance instance) { 101 124 List<int> route = new List<int>(routeParam); 102 route.RemoveAt(routeParam.Count - 1);103 125 104 126 int cities = instance.Cities.Value; … … 129 151 int emptyVehicles = instance.Vehicles.Value - tours.Count; 130 152 131 int[] array = new int[cities + tours.Count + emptyVehicles - 1];153 int[] array = new int[cities + tours.Count + emptyVehicles]; 132 154 int delimiter = 0; 133 155 int arrayIndex = 0; … … 140 162 141 163 if (arrayIndex != array.Length) { 142 if (encoding is IHeterogenousCapacitatedEncoding) { 143 array[arrayIndex] = cities + (encoding as IHeterogenousCapacitatedEncoding).GetVehicleAssignment(delimiter); 144 } else { 145 array[arrayIndex] = cities + delimiter; 146 } 164 array[arrayIndex] = cities + encoding.GetVehicleAssignment(delimiter); 147 165 148 166 delimiter++; … … 151 169 } 152 170 153 for (int i = 0; i < emptyVehicles - 1; i++) { 154 if (encoding is IHeterogenousCapacitatedEncoding) { 155 array[arrayIndex] = cities + (encoding as IHeterogenousCapacitatedEncoding).GetVehicleAssignment(delimiter); 156 } else { 157 array[arrayIndex] = cities + delimiter; 158 } 171 for (int i = 0; i < emptyVehicles; i++) { 172 array[arrayIndex] = cities + encoding.GetVehicleAssignment(delimiter); 159 173 160 174 delimiter++; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Creators/AlbaCreator.cs
r4752 r6851 47 47 : base(original, cloner) { 48 48 } 49 50 public override IOperation Apply() { 51 (VRPToursParameter.ActualValue as AlbaEncoding).Repair(); 52 53 return base.Apply(); 54 } 49 55 } 50 56 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Crossovers/AlbaCrossover.cs
r4752 r6851 67 67 68 68 ChildParameter.ActualValue = 69 Crossover(RandomParameter.ActualValue, parents[0] as AlbaEncoding, parents[1] as AlbaEncoding); 69 Crossover(RandomParameter.ActualValue, parents[0] as AlbaEncoding, parents[1] as AlbaEncoding); 70 (ChildParameter.ActualValue as AlbaEncoding).Repair(); 70 71 71 72 return base.Apply(); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/IAlbaOperator.cs
r4369 r6851 32 32 33 33 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba { 34 public interface IAlbaOperator: 35 ISingleDepotOperator, IHeterogenousCapacitatedOperator, I TimeWindowedOperator {34 public interface IAlbaOperator: 35 ISingleDepotOperator, IHeterogenousCapacitatedOperator, IMultiDepotOperator, ITimeWindowedOperator { 36 36 } 37 37 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Manipulators/AlbaManipulator.cs
r4752 r6851 71 71 72 72 Manipulate(RandomParameter.ActualValue, VRPToursParameter.ActualValue as AlbaEncoding); 73 (VRPToursParameter.ActualValue as AlbaEncoding).Repair(); 73 74 74 75 return base.Apply(); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/ExtendedPotvin/Creators/IterativeInsertionCreator.cs
r6838 r6851 33 33 using HeuristicLab.Problems.VehicleRouting.Variants; 34 34 35 namespace HeuristicLab.Problems.VehicleRouting.Encodings. Potvin {35 namespace HeuristicLab.Problems.VehicleRouting.Encodings.ExtendedPotvin { 36 36 [Item("IterativeInsertionCreator", "Creates a randomly initialized VRP solution.")] 37 37 [StorableClass] 38 public sealed class IterativeInsertionCreator : PotvinCreator, IStochasticOperator {38 public sealed class IterativeInsertionCreator : ExtendedPotvinCreator, IStochasticOperator { 39 39 #region IStochasticOperator Members 40 40 public ILookupParameter<IRandom> RandomParameter { … … 65 65 66 66 private static double CalculateAngleToDepot(IVRPProblemInstance instance, int city) { 67 double dx = instance. Coordinates[0,0];68 double dy = instance. Coordinates[0,1];67 double dx = instance.GetCoordinates(0)[0]; 68 double dy = instance.GetCoordinates(0)[1]; 69 69 70 double cx = instance. Coordinates[city,0];71 double cy = instance. Coordinates[city,1];70 double cx = instance.GetCoordinates(city)[0]; 71 double cy = instance.GetCoordinates(city)[1]; 72 72 73 73 double alpha = Math.Atan((cx - dx) / (dy - cy)) * (180.0 / Math.PI); … … 82 82 } 83 83 84 private static PotvinEncoding CreateSolution(IVRPProblemInstance instance, IRandom random, bool adhereTimeWindows) {85 PotvinEncoding result = newPotvinEncoding(instance);84 private static ExtendedPotvinEncoding CreateSolution(IVRPProblemInstance instance, IRandom random, bool adhereTimeWindows) { 85 ExtendedPotvinEncoding result = new ExtendedPotvinEncoding(instance); 86 86 87 87 IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance; … … 89 89 List<int> customers = new List<int>(); 90 90 for (int i = 1; i <= instance.Cities.Value; i++) 91 if(pdp == null || pdp. Demand[i]>= 0)91 if(pdp == null || pdp.GetDemand(i) >= 0) 92 92 customers.Add(i); 93 93 … … 107 107 int index = (i + j) % customers.Count; 108 108 109 int stopIdx = result.FindBestInsertionPlace(currentTour, customers[index]); 109 int stopIdx = 0; 110 if(currentTour.Stops.Count > 0) 111 result.FindBestInsertionPlace(currentTour, customers[index]); 110 112 currentTour.Stops.Insert(stopIdx, customers[index]); 111 113 … … 122 124 currentTour.Stops.Remove(pdp.PickupDeliveryLocation[customers[index]]); 123 125 124 if (currentTour.Stops.Count >0)125 result.Tours. Add(currentTour);126 if (currentTour.Stops.Count == 0) 127 result.Tours.Remove(currentTour); 126 128 currentTour = new Tour(); 129 result.Tours.Add(currentTour); 127 130 128 131 currentTour.Stops.Add(customers[index]); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/ExtendedPotvin/Creators/PushForwardInsertionCreator.cs
r6839 r6851 33 33 using HeuristicLab.Problems.VehicleRouting.Variants; 34 34 35 namespace HeuristicLab.Problems.VehicleRouting.Encodings. Potvin {35 namespace HeuristicLab.Problems.VehicleRouting.Encodings.ExtendedPotvin { 36 36 [Item("PushForwardInsertionCreator", "Creates a randomly initialized VRP solution.")] 37 37 [StorableClass] 38 public sealed class PushForwardInsertionCreator : PotvinCreator, IStochasticOperator {38 public sealed class PushForwardInsertionCreator : ExtendedPotvinCreator, IStochasticOperator { 39 39 #region IStochasticOperator Members 40 40 public ILookupParameter<IRandom> RandomParameter { … … 99 99 } 100 100 101 private static double Distance(IVRPProblemInstance problemInstance, int start, int end) { 102 return problemInstance.GetDistance(start, end); 103 } 104 105 private static PotvinEncoding CreateSolution(IVRPProblemInstance problemInstance, IRandom random, 101 private static double GetDistance(int start, int end, IVRPProblemInstance problemInstance) { 102 double distance = 0.0; 103 104 double startX = problemInstance.Coordinates[start, 0]; 105 double startY = problemInstance.Coordinates[start, 1]; 106 107 double endX = problemInstance.Coordinates[end, 0]; 108 double endY = problemInstance.Coordinates[end, 1]; 109 110 distance = 111 Math.Sqrt( 112 Math.Pow(startX - endX, 2) + 113 Math.Pow(startY - endY, 2)); 114 115 return distance; 116 } 117 118 private static ExtendedPotvinEncoding CreateSolution(IVRPProblemInstance problemInstance, IRandom random, 106 119 double alphaValue = 0.7, double betaValue = 0.1, double gammaValue = 0.2, 107 120 double alphaVariance = 0.5, double betaVariance = 0.07, double gammaVariance = 0.14) { 108 PotvinEncoding result = newPotvinEncoding(problemInstance);121 ExtendedPotvinEncoding result = new ExtendedPotvinEncoding(problemInstance); 109 122 110 123 double alpha, beta, gamma; … … 113 126 gamma = N(gammaValue, Math.Sqrt(gammaVariance), random); 114 127 115 double x0 = problemInstance.Coordinates[0, 0];116 double y0 = problemInstance.Coordinates[0, 1]; 128 int totalTours = 0; 129 117 130 double distance = 0; 118 131 double cost = 0; … … 121 134 122 135 IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance; 123 124 /*----------------------------------------------------------------------------- 125 * generate cost list 126 *----------------------------------------------------------------------------- 127 */ 128 for (int i = 1; i <= problemInstance.Cities.Value; i++) { 129 //only insert sources 130 if (pdp == null || problemInstance.Demand[i] >= 0) { 131 distance = Distance(problemInstance, i, 0); 132 if (problemInstance.Coordinates[i, 0] < x0) distance = -distance; 133 134 cost = -alpha * distance + // distance 0 <-> City[i] 135 beta * (problemInstance as ITimeWindowedProblemInstance).DueTime[i] + // latest arrival time 136 gamma * (Math.Asin((problemInstance.Coordinates[i, 1] - y0) / distance) / 360 * distance); // polar angle 137 138 int index = 0; 139 while (index < costList.Count && costList[index] < cost) index++; 140 141 costList.Insert(index, cost); 142 143 unroutedList.Insert(index, i); 144 } 136 IMultiDepotProblemInstance mdp = problemInstance as IMultiDepotProblemInstance; 137 138 int depots = 1; 139 if (mdp != null) { 140 depots = mdp.Depots.Value; 141 for (int i = 0; i < result.VehicleAssignment.Length; i++) 142 result.VehicleAssignment[i] = -1; 145 143 } 146 144 147 double minimumCost = double.MaxValue; 148 int indexOfMinimumCost = -1; 149 int indexOfMinimumCost2 = -1; 150 int indexOfCustomer = -1; 151 152 Tour tour = new Tour(); 153 result.Tours.Add(tour); 154 155 tour.Stops.Add(unroutedList[0]); 156 157 if (pdp != null) { 158 tour.Stops.Add(pdp.PickupDeliveryLocation[unroutedList[0]]); 159 } 160 161 unroutedList.RemoveAt(0); 162 163 while (unroutedList.Count > 0) { 164 for (int c = 0; c < unroutedList.Count; c++) { 165 VRPEvaluation eval = 166 problemInstance.EvaluateTour(tour, result); 167 double originalCosts = eval.Quality; 168 int customer = unroutedList[c]; 169 170 for (int i = 0; i <= tour.Stops.Count; i++) { 171 tour.Stops.Insert(i, customer); 172 eval = problemInstance.EvaluateTour(tour, result); 173 double tourCost = eval.Quality - originalCosts; 174 175 if (pdp != null) { 176 for (int j = i + 1; j <= tour.Stops.Count; j++) { 177 bool feasible; 178 cost = tourCost + 179 problemInstance.GetInsertionCosts(eval, pdp.PickupDeliveryLocation[unroutedList[c]], 0, j, out feasible); 145 List<int> unrouted = new List<int>(); 146 for (int i = 1; i <= problemInstance.Cities.Value; i++) 147 if (pdp == null || problemInstance.GetDemand(i) >= 0) 148 unrouted.Add(i); 149 150 for (int depot = 0; depot < depots; depot++) { 151 int vehicleCount = problemInstance.Vehicles.Value; 152 List<int> vehicles = new List<int>(); 153 if (mdp != null) { 154 vehicleCount = 0; 155 for (int i = 0; i < mdp.VehicleDepotAssignment.Length; i++) { 156 if (mdp.VehicleDepotAssignment[i] == depot) { 157 vehicleCount++; 158 vehicles.Add(i); 159 } 160 } 161 } else { 162 for (int i = 0; i < problemInstance.Vehicles.Value; i++) 163 vehicles.Add(i); 164 } 165 166 costList.Clear(); 167 unroutedList.Clear(); 168 169 double x0 = problemInstance.Coordinates[depot, 0]; 170 double y0 = problemInstance.Coordinates[depot, 1]; 171 172 /*----------------------------------------------------------------------------- 173 * generate cost list 174 *----------------------------------------------------------------------------- 175 */ 176 for (int i = 1; i <= problemInstance.Cities.Value; i++) { 177 //only insert sources 178 if (unrouted.Contains(i) && (pdp == null || problemInstance.GetDemand(i) >= 0)) { 179 distance = GetDistance(i + depots - 1, depot, problemInstance); 180 if (problemInstance.Coordinates[i + depots - 1, 0] < x0) distance = -distance; 181 182 double dueTime = 0; 183 if (problemInstance is ITimeWindowedProblemInstance) 184 dueTime = (problemInstance as ITimeWindowedProblemInstance).DueTime[i]; 185 186 cost = -alpha * distance + // distance 0 <-> City[i] 187 beta * dueTime + // latest arrival time 188 gamma * (Math.Asin((problemInstance.Coordinates[i + depots - 1, 0] - y0) / distance) / 360 * distance); // polar angle 189 190 int index = 0; 191 while (index < costList.Count && costList[index] < cost) index++; 192 193 costList.Insert(index, cost); 194 195 unroutedList.Insert(index, i); 196 } 197 } 198 199 int tours = 0; 200 double minimumCost = double.MaxValue; 201 int indexOfMinimumCost = -1; 202 int indexOfMinimumCost2 = -1; 203 int indexOfCustomer = -1; 204 205 Tour tour = new Tour(); 206 result.Tours.Add(tour); 207 result.VehicleAssignment[totalTours] = vehicles[0]; 208 vehicles.RemoveAt(0); 209 tours++; 210 totalTours++; 211 212 tour.Stops.Add(unroutedList[0]); 213 214 if (pdp != null) { 215 tour.Stops.Add(pdp.PickupDeliveryLocation[unroutedList[0]]); 216 } 217 218 unrouted.Remove(unroutedList[0]); 219 unroutedList.RemoveAt(0); 220 221 while (unroutedList.Count > 0 && (tours < vehicleCount || depot == depots - 1)) { 222 for (int c = 0; c < unroutedList.Count; c++) { 223 VRPEvaluation eval = problemInstance.EvaluateTour(tour, result); 224 double originalCosts = eval.Quality; 225 int customer = unroutedList[c]; 226 227 for (int i = 0; i <= tour.Stops.Count; i++) { 228 tour.Stops.Insert(i, customer); 229 eval = problemInstance.EvaluateTour(tour, result); 230 double tourCost = eval.Quality - originalCosts; 231 232 if (pdp != null) { 233 for (int j = i + 1; j <= tour.Stops.Count; j++) { 234 bool feasible; 235 cost = tourCost + 236 problemInstance.GetInsertionCosts(eval, result, pdp.PickupDeliveryLocation[unroutedList[c]], 0, j, out feasible); 237 if (cost < minimumCost && feasible) { 238 minimumCost = cost; 239 indexOfMinimumCost = i; 240 indexOfMinimumCost2 = j; 241 indexOfCustomer = c; 242 } 243 } 244 } else { 245 cost = tourCost; 246 bool feasible = problemInstance.Feasible(eval); 180 247 if (cost < minimumCost && feasible) { 181 248 minimumCost = cost; 182 249 indexOfMinimumCost = i; 183 indexOfMinimumCost2 = j;184 250 indexOfCustomer = c; 185 251 } 186 252 } 187 } else { 188 cost = tourCost; 189 bool feasible = problemInstance.Feasible(eval); 190 if (cost < minimumCost && feasible) { 191 minimumCost = cost; 192 indexOfMinimumCost = i; 193 indexOfCustomer = c; 194 } 253 254 tour.Stops.RemoveAt(i); 195 255 } 196 197 tour.Stops.RemoveAt(i); 198 } 199 } 200 201 // insert customer if found 202 if (indexOfMinimumCost != -1) { 203 tour.Stops.Insert(indexOfMinimumCost, unroutedList[indexOfCustomer]); 204 if (pdp != null) { 205 tour.Stops.Insert(indexOfMinimumCost2, pdp.PickupDeliveryLocation[unroutedList[indexOfCustomer]]); 206 } 207 208 unroutedList.RemoveAt(indexOfCustomer); 209 } else { // no feasible customer found 210 tour = new Tour(); 211 result.Tours.Add(tour); 212 213 tour.Stops.Add(unroutedList[0]); 214 if (pdp != null) { 215 tour.Stops.Add(pdp.PickupDeliveryLocation[unroutedList[0]]); 216 } 217 218 unroutedList.RemoveAt(0); 219 } 220 // reset minimum 221 minimumCost = double.MaxValue; 222 indexOfMinimumCost = -1; 223 indexOfMinimumCost2 = -1; 224 indexOfCustomer = -1; 256 } 257 258 // insert customer if found 259 if (indexOfMinimumCost != -1) { 260 tour.Stops.Insert(indexOfMinimumCost, unroutedList[indexOfCustomer]); 261 if (pdp != null) { 262 tour.Stops.Insert(indexOfMinimumCost2, pdp.PickupDeliveryLocation[unroutedList[indexOfCustomer]]); 263 } 264 265 unrouted.Remove(unroutedList[indexOfCustomer]); 266 unroutedList.RemoveAt(indexOfCustomer); 267 } else if (tours < vehicleCount || depot == depots - 1) { // no feasible customer found 268 tour = new Tour(); 269 result.Tours.Add(tour); 270 result.VehicleAssignment[totalTours] = vehicles[0]; 271 vehicles.RemoveAt(0); 272 tours++; 273 totalTours++; 274 275 tour.Stops.Add(unroutedList[0]); 276 if (pdp != null) { 277 tour.Stops.Add(pdp.PickupDeliveryLocation[unroutedList[0]]); 278 } 279 280 unrouted.Remove(unroutedList[0]); 281 unroutedList.RemoveAt(0); 282 } 283 // reset minimum 284 minimumCost = double.MaxValue; 285 indexOfMinimumCost = -1; 286 indexOfMinimumCost2 = -1; 287 indexOfCustomer = -1; 288 } 289 } 290 291 if (mdp != null) { 292 List<int> availableVehicles = new List<int>(); 293 for (int i = 0; i < mdp.Vehicles.Value; i++) 294 availableVehicles.Add(i); 295 296 for (int i = 0; i < result.VehicleAssignment.Length; i++) { 297 if (result.VehicleAssignment[i] != -1) 298 availableVehicles.Remove(result.VehicleAssignment[i]); 299 } 300 301 for (int i = 0; i < result.VehicleAssignment.Length; i++) { 302 if (result.VehicleAssignment[i] == -1) { 303 result.VehicleAssignment[i] = availableVehicles[0]; 304 availableVehicles.RemoveAt(0); 305 } 306 } 225 307 } 226 308 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/GVR/Crossovers/GVRCrossover.cs
r4752 r6851 82 82 for (int i = 1; i <= ProblemInstance.Cities.Value; i++) { 83 83 if (!subroute.Contains(i)) { 84 double distance = ProblemInstance.GetDistance(subroute[0], i );84 double distance = ProblemInstance.GetDistance(subroute[0], i, child); 85 85 86 86 if (customer == -1 || distance < minDistance) { -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/GVR/GVREncoding.cs
r4752 r6851 42 42 double currentDemand = 0; 43 43 44 DoubleArray demand = ProblemInstance.Demand;45 44 DoubleValue capacity = new DoubleValue(double.MaxValue); 46 45 if (ProblemInstance is IHomogenousCapacitatedProblemInstance) { … … 50 49 51 50 foreach (int city in tour.Stops) { 52 currentDemand += demand[city];51 currentDemand += ProblemInstance.GetDemand(city); 53 52 54 53 if (currentDemand > capacity.Value) { … … 58 57 newTour = new Tour(); 59 58 newTour.Stops.Add(city); 60 currentDemand = demand[city];59 currentDemand = ProblemInstance.GetDemand(city); 61 60 } else { 62 61 newTour.Stops.Add(city); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Crossovers/BiasedMultiVRPSolutionCrossover.cs
r6716 r6851 160 160 OperationCollection next = new OperationCollection(successorOp); 161 161 if (successor != null) { 162 SelectedOperatorParameter.ActualValue = new StringValue(successor. GetType().Name);162 SelectedOperatorParameter.ActualValue = new StringValue(successor.Name); 163 163 164 164 if (CreateChildOperation) -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Manipulators/BiasedMultiVRPSolutionManipulator.cs
r6716 r6851 160 160 OperationCollection next = new OperationCollection(successorOp); 161 161 if (successor != null) { 162 SelectedOperatorParameter.ActualValue = new StringValue(successor. GetType().Name);162 SelectedOperatorParameter.ActualValue = new StringValue(successor.Name); 163 163 164 164 if (CreateChildOperation) -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/PermutationEncoding.cs
r4899 r6851 35 35 #region IVRPEncoding Members 36 36 public abstract List<Tour> GetTours(); 37 38 public int GetTourIndex(Tour tour) { 39 int index = -1; 40 41 List<Tour> tours = GetTours(); 42 for (int i = 0; i < tours.Count; i++) { 43 if (tours[i].IsEqual(tour)) { 44 index = i; 45 break; 46 } 47 } 48 49 return index; 50 } 51 52 public virtual int GetVehicleAssignment(int tour) { 53 return tour; 54 } 37 55 #endregion 38 56 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/TourEncoding.cs
r6837 r6851 38 38 39 39 #region IVRPEncoding Members 40 public v oid Repair() {40 public virtual void Repair() { 41 41 List<Tour> toBeRemoved = new List<Tour>(); 42 42 foreach (Tour tour in Tours) { … … 62 62 63 63 return result; 64 } 65 66 public int GetTourIndex(Tour tour) { 67 int index = -1; 68 69 for (int i = 0; i < Tours.Count; i++) { 70 if (Tours[i].IsEqual(tour)) { 71 index = i; 72 break; 73 } 74 } 75 76 return index; 77 } 78 79 public virtual int GetVehicleAssignment(int tour) { 80 return tour; 64 81 } 65 82 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinInsertionBasedCrossover.cs
r6838 r6851 28 28 using HeuristicLab.Parameters; 29 29 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 30 using HeuristicLab.Problems.VehicleRouting.Interfaces; 30 31 31 32 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin { … … 74 75 } 75 76 76 private double CalculateCentroidDistance(Tour t1, Tour t2, DoubleMatrix coordinates) {77 private double CalculateCentroidDistance(Tour t1, Tour t2, IVRPProblemInstance instance) { 77 78 double xSum = 0; 78 79 double ySum = 0; … … 80 81 81 82 for (int i = 0; i < t1.Stops.Count; i++) { 82 xSum += coordinates[t1.Stops[i],0];83 ySum += coordinates[t1.Stops[i],1];83 xSum += instance.GetCoordinates(t1.Stops[i])[0]; 84 ySum += instance.GetCoordinates(t1.Stops[i])[1]; 84 85 } 85 86 c1X = xSum / t1.Stops.Count; … … 87 88 88 89 for (int i = 0; i < t2.Stops.Count; i++) { 89 xSum += coordinates[t2.Stops[i],0];90 ySum += coordinates[t2.Stops[i],1];90 xSum += instance.GetCoordinates(t2.Stops[i])[0]; 91 ySum += instance.GetCoordinates(t2.Stops[i])[1]; 91 92 } 92 93 c2X = xSum / t1.Stops.Count; … … 98 99 } 99 100 100 private double CalculateMeanCentroidDistance(Tour t1, IList<Tour> tours, DoubleMatrix coordinates) {101 private double CalculateMeanCentroidDistance(Tour t1, IList<Tour> tours, IVRPProblemInstance instance) { 101 102 double sum = 0; 102 103 103 104 for (int i = 0; i < tours.Count; i++) { 104 sum += CalculateCentroidDistance(t1, tours[i], coordinates);105 sum += CalculateCentroidDistance(t1, tours[i], instance); 105 106 } 106 107 … … 108 109 } 109 110 110 private int SelectCityBiasedByNeighborDistance(IRandom random, Tour tour ) {111 private int SelectCityBiasedByNeighborDistance(IRandom random, Tour tour, IVRPEncoding solution) { 111 112 int cityIndex = -1; 112 113 … … 120 121 next = tour.Stops[i + 1]; 121 122 double distance = ProblemInstance.GetDistance( 122 tour.Stops[i], next );123 tour.Stops[i], next, solution); 123 124 124 125 int prev; … … 128 129 prev = tour.Stops[i - 1]; 129 130 distance += ProblemInstance.GetDistance( 130 tour.Stops[i], prev );131 tour.Stops[i], prev, solution); 131 132 132 133 probabilities[i] = distance; … … 168 169 for (int i = 0; i <= tour.Stops.Count; i++) { 169 170 bool feasible; 170 double detour = ProblemInstance.GetInsertionCosts(eval, city, 0, i, out feasible);171 double detour = ProblemInstance.GetInsertionCosts(eval, individual, city, 0, i, out feasible); 171 172 if (feasible || allowInfeasible) { 172 173 if (place < 0 || detour < minDetour) { … … 195 196 196 197 protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) { 197 PotvinEncoding child = new PotvinEncoding(ProblemInstance); 198 PotvinEncoding child = parent1.Clone() as PotvinEncoding; 199 child.Tours.Clear(); 198 200 199 201 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; … … 213 215 List<int> R2 = new List<int>(); 214 216 215 double r = CalculateMeanCentroidDistance(r1, parent2.Tours, ProblemInstance .Coordinates);217 double r = CalculateMeanCentroidDistance(r1, parent2.Tours, ProblemInstance); 216 218 foreach (Tour tour in parent2.Tours) { 217 if (CalculateCentroidDistance(r1, tour, ProblemInstance .Coordinates) <= r) {219 if (CalculateCentroidDistance(r1, tour, ProblemInstance) <= r) { 218 220 R2.AddRange(tour.Stops); 219 221 } … … 227 229 int removed = random.Next(1, r1.Stops.Count + 1); 228 230 for (int i = 0; i < removed; i++) { 229 childTour.Stops.RemoveAt(SelectCityBiasedByNeighborDistance(random, childTour ));231 childTour.Stops.RemoveAt(SelectCityBiasedByNeighborDistance(random, childTour, child)); 230 232 } 231 233 232 234 //REPAIR - add cities from R2 233 int maxCount = random.Next(1, Math.Min(5, R2.Count)); 235 int maxCount = 1; 236 if(R2.Count > 1) 237 maxCount = random.Next(1, Math.Min(5, R2.Count)); 234 238 int count = 0; 235 239 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinRouteBasedCrossover.cs
r6607 r6851 26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.Common; 28 using HeuristicLab.Problems.VehicleRouting.Encodings.ExtendedPotvin; 28 29 29 30 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin { … … 57 58 58 59 child.Tours.Remove(replaced); 59 child.Tours.Add(replacing); 60 child.Tours.Insert(tourParent2, replacing); 61 62 if (parent1 is ExtendedPotvinEncoding && child is ExtendedPotvinEncoding) { 63 Permutation vehicleAssignment = (child as ExtendedPotvinEncoding).VehicleAssignment; 64 65 int vehicle = vehicleAssignment[tourParent2]; 66 int vehicle2 = (parent1 as ExtendedPotvinEncoding).VehicleAssignment[tourParent1]; 67 vehicleAssignment[tourParent2] = vehicle2; 68 69 for (int i = 0; i < vehicleAssignment.Length; i++) { 70 if (vehicleAssignment[i] == vehicle2 && i != tourParent2) { 71 vehicleAssignment[i] = vehicle; 72 break; 73 } 74 } 75 } 60 76 61 77 foreach (int city in replaced.Stops) -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinSequenceBasedCrossover.cs
r6607 r6851 67 67 newTour.Stops.Add(tour2.Stops[i]); 68 68 69 int tour1Index = child.Tours.IndexOf(tour1); 69 70 child.Tours.Remove(tour1); 70 child.Tours. Add(newTour);71 child.Tours.Insert(tour1Index, newTour); 71 72 72 73 foreach (int city in tour1.Stops) -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinCustomerRelocationManipulator.cs
r6753 r6851 67 67 for (int i = 0; i < route1.Stops.Count; i++) { 68 68 int stop = route1.Stops[i]; 69 if (ProblemInstance. Demand[stop]< 0) {69 if (ProblemInstance.GetDemand(stop) < 0) { 70 70 int source = pdp.PickupDeliveryLocation[stop]; 71 71 … … 158 158 159 159 //drive there 160 double currentDistace = vrptw.GetDistance(start, end );160 double currentDistace = vrptw.GetDistance(start, end, individual); 161 161 time += currentDistace; 162 162 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDExchange/PotvinPDExchangeExhaustiveMoveGenerator.cs
r6773 r6851 62 62 if (k != i) { 63 63 int city1 = individual.Tours[i].Stops[j]; 64 if (pdp == null || pdp. Demand[city1]>= 0) {64 if (pdp == null || pdp.GetDemand(city1) >= 0) { 65 65 for (int l = 0; l < individual.Tours[k].Stops.Count; l++) { 66 66 int city2 = individual.Tours[k].Stops[l]; 67 if (pdp == null || pdp. Demand[city2]>= 0) {67 if (pdp == null || pdp.GetDemand(city2) >= 0) { 68 68 bool valid = pdp == null || 69 69 (pdp.PickupDeliveryLocation[city2] != pdp.PickupDeliveryLocation[city1] && -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDExchange/PotvinPDExchangeSingleMoveGenerator.cs
r6773 r6851 62 62 IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance; 63 63 for (int i = 1; i <= individual.Cities; i++) { 64 if (pdp == null || pdp. Demand[i]>= 0)64 if (pdp == null || pdp.GetDemand(i) >= 0) 65 65 cities.Add(i); 66 66 } … … 84 84 foreach (int stop in newTour.Stops) { 85 85 if (pdp == null || 86 (pdp. Demand[stop]>= 0 &&86 (pdp.GetDemand(stop) >= 0 && 87 87 pdp.PickupDeliveryLocation[stop] != pdp.PickupDeliveryLocation[city] && 88 88 pdp.PickupDeliveryLocation[stop] != city && -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDRearrange/PotvinPDRearrangeExhaustiveMoveGenerator.cs
r6773 r6851 54 54 55 55 for (int i = 1; i <= problemInstance.Cities.Value; i++) { 56 if (pdp == null || pdp. Demand[i]>= 0) {56 if (pdp == null || pdp.GetDemand(i) >= 0) { 57 57 int tour = individual.Tours.FindIndex(t => t.Stops.Contains(i)); 58 58 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDRearrange/PotvinPDRearrangeMoveMaker.cs
r6838 r6851 74 74 if (positionToAvoid != i || positionToAvoid2 != j || stops == 0) { 75 75 bool feasible; 76 double targetCosts = problemInstance.GetInsertionCosts(tourEval, target, 0, j, out feasible);76 double targetCosts = problemInstance.GetInsertionCosts(tourEval, solution, target, 0, j, out feasible); 77 77 78 78 double costs = sourceCosts + targetCosts; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDRearrange/PotvinPDRearrangeSingleMoveGenerator.cs
r6773 r6851 62 62 IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance; 63 63 for (int i = 1; i <= individual.Cities; i++) { 64 if(pdp == null || pdp. Demand[i]>= 0)64 if(pdp == null || pdp.GetDemand(i) >= 0) 65 65 cities.Add(i); 66 66 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDShift/PotvinPDShiftExhaustiveMoveGenerator.cs
r6773 r6851 62 62 if (k != i) { 63 63 int city = individual.Tours[i].Stops[j]; 64 if (pdp == null || pdp. Demand[city]>= 0) {64 if (pdp == null || pdp.GetDemand(city) >= 0) { 65 65 PotvinPDShiftMove move = new PotvinPDShiftMove( 66 66 city, i, k, individual); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDShift/PotvinPDShiftSingleMoveGenerator.cs
r6773 r6851 62 62 IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance; 63 63 for (int i = 1; i <= individual.Cities; i++) { 64 if(pdp == null || pdp. Demand[i]>= 0)64 if(pdp == null || pdp.GetDemand(i) >= 0) 65 65 cities.Add(i); 66 66 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncoding.cs
r6838 r6851 45 45 46 46 [StorableConstructor] 47 pr ivatePotvinEncoding(bool serializing)47 protected PotvinEncoding(bool serializing) 48 48 : base(serializing) { 49 49 } … … 75 75 76 76 public double GetTourLength(Tour tour) { 77 return tour.GetTourLength(ProblemInstance );77 return tour.GetTourLength(ProblemInstance, this); 78 78 } 79 79 … … 87 87 if (positionToAvoid != i) { 88 88 bool feasible; 89 double quality = ProblemInstance.GetInsertionCosts(eval, city, 0, i, out feasible);89 double quality = ProblemInstance.GetInsertionCosts(eval, this, city, 0, i, out feasible); 90 90 if (place < 0 || quality < minQuality) { 91 91 place = i; … … 115 115 for (int i = 0; i <= Tours[tour].Stops.Count; i++) { 116 116 bool feasible; 117 double detour = ProblemInstance.GetInsertionCosts(eval, city, tour, i, out feasible);118 117 double detour = ProblemInstance.GetInsertionCosts(eval, this, city, tour, i, out feasible); 118 119 119 if (feasible || allowInfeasible) { 120 120 if (route < 0 || detour < minDetour) { -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Tour.cs
r6607 r6851 48 48 } 49 49 50 public double GetTourLength(IVRPProblemInstance instance ) {50 public double GetTourLength(IVRPProblemInstance instance, IVRPEncoding solution) { 51 51 double length = 0; 52 52 … … 60 60 61 61 for (int i = 1; i < cities.Count; i++) { 62 length += instance.GetDistance(cities[i - 1], cities[i] );62 length += instance.GetDistance(cities[i - 1], cities[i], solution); 63 63 } 64 64 } … … 66 66 return length; 67 67 } 68 69 public bool IsEqual(Tour tour) { 70 bool equal = (tour != null) && (tour.Stops.Count == Stops.Count); 71 int index = 0; 72 73 while (equal && index < Stops.Count) { 74 equal = equal && tour.Stops[index] == Stops[index]; 75 index++; 76 } 77 78 return equal; 79 } 68 80 } 69 81 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Zhu/Crossovers/ZhuHeuristicCrossover1.cs
r6771 r6851 77 77 78 78 if (ProblemInstance.GetDistance( 79 child[i] + 1, parent1[(i + 1) % child.Length] + 1 )79 child[i] + 1, parent1[(i + 1) % child.Length] + 1, child) 80 80 < 81 81 ProblemInstance.GetDistance( 82 child[i] + 1, parent2[(i + 1) % child.Length] + 1 )) {82 child[i] + 1, parent2[(i + 1) % child.Length] + 1, child)) { 83 83 child[(i + 1) % child.Length] = parent1[(i + 1) % child.Length]; 84 84 Swap(parent2, parent2[(i + 1) % child.Length], parent1[(i + 1) % child.Length]); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Zhu/Crossovers/ZhuHeuristicCrossover2.cs
r6771 r6851 79 79 80 80 if (ProblemInstance.GetDistance( 81 child[i] + 1, p1[parent1Index] + 1 )81 child[i] + 1, p1[parent1Index] + 1, child) 82 82 < 83 83 ProblemInstance.GetDistance( 84 child[i] + 1, p2[parent2Index] + 1 )) {84 child[i] + 1, p2[parent2Index] + 1, child)) { 85 85 child[(i + 1) % child.Length] = p1[parent1Index]; 86 86 } else { -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/HeuristicLab.Problems.VehicleRouting-3.4.csproj
r6838 r6851 170 170 <Compile Include="Encodings\Alba\Moves\ThreeOpt\AlbaStochasticTranslocationSingleMoveGenerator.cs" /> 171 171 <Compile Include="Encodings\Alba\Moves\ThreeOpt\IAlbaTranslocationMoveOperator.cs" /> 172 <Compile Include="Encodings\ExtendedPotvin\Creators\ExtendedPotvinCreator.cs" /> 173 <Compile Include="Encodings\ExtendedPotvin\Crossovers\ExtendedPotvinCrossover.cs" /> 174 <Compile Include="Encodings\ExtendedPotvin\IExtendedPotvinOperator.cs" /> 175 <Compile Include="Encodings\ExtendedPotvin\ExtendedPotvinEncoding.cs" /> 176 <Compile Include="Encodings\ExtendedPotvin\Manipulators\ExtendedPotvinManipulator.cs" /> 172 177 <Compile Include="Encodings\General\Creators\MultiVRPSolutionCreator.cs" /> 173 178 <Compile Include="Encodings\General\Creators\VRPCreator.cs" /> … … 202 207 <Compile Include="Encodings\GVR\Manipulators\GVRManipulator.cs" /> 203 208 <Compile Include="Encodings\GVR\Manipulators\GVRSwapManipulator.cs" /> 204 <Compile Include="Encodings\ Potvin\Creators\PushForwardInsertionCreator.cs" />209 <Compile Include="Encodings\ExtendedPotvin\Creators\PushForwardInsertionCreator.cs" /> 205 210 <Compile Include="Encodings\Potvin\Creators\PotvinCreator.cs" /> 206 <Compile Include="Encodings\ Potvin\Creators\IterativeInsertionCreator.cs" />211 <Compile Include="Encodings\ExtendedPotvin\Creators\IterativeInsertionCreator.cs" /> 207 212 <Compile Include="Encodings\Potvin\Crossovers\PotvinCrossover.cs" /> 208 213 <Compile Include="Encodings\Potvin\Crossovers\PotvinInsertionBasedCrossover.cs" /> … … 292 297 <Compile Include="Interfaces\IVRPEncoding.cs" /> 293 298 <Compile Include="Interfaces\IVRPProblemInstance.cs" /> 299 <Compile Include="Parsers\CordeauParser.cs" /> 294 300 <Compile Include="Parsers\LiLimParser.cs" /> 301 <Compile Include="ProblemInstances\MultiDepotVRP\MDCVRP\MDCVRPEvaluator.cs" /> 302 <Compile Include="ProblemInstances\MultiDepotVRP\MDCVRP\MDCVRPProblemInstance.cs" /> 303 <Compile Include="ProblemInstances\MultiDepotVRP\MultiDepotVRPProblemInstance.cs" /> 304 <Compile Include="ProblemInstances\MultiDepotVRP\MultiDepotVRPEvaluator.cs" /> 295 305 <Compile Include="ProblemInstances\SingleDepotVRP\CVRP\CVRPTW\CVRPPDTW\CVRPPDTWProblemInstance.cs" /> 296 306 <Compile Include="ProblemInstances\SingleDepotVRP\CVRP\CVRPTW\CVRPPDTW\CVRPPDTWEvaluation.cs" /> 297 307 <Compile Include="ProblemInstances\SingleDepotVRP\CVRP\CVRPTW\CVRPPDTW\CVRPPDTWEvaluator.cs" /> 308 <Compile Include="ProblemInstances\SingleDepotVRP\SingleDepotVRPEvaluator.cs" /> 298 309 <Compile Include="SolutionParser.cs" /> 299 310 <Compile Include="Variants\Capacitated\Heterogenous\IHeterogenousCapacitatedProblemInstance.cs" /> 300 311 <Compile Include="Variants\Capacitated\Heterogenous\IHeterogenousCapacitatedOperator.cs" /> 301 <Compile Include="Variants\Capacitated\Heterogenous\IHeterogenousCapacitatedEncoding.cs" />302 312 <Compile Include="Variants\Capacitated\Homogenous\IHomogenousCapacitatedOperator.cs" /> 303 313 <Compile Include="Variants\Capacitated\Homogenous\IHomogenousCapacitatedProblemInstance.cs" /> … … 305 315 <Compile Include="Variants\Capacitated\ICapacitatedOperator.cs" /> 306 316 <Compile Include="Variants\General\IGeneralVRPOperator.cs" /> 317 <Compile Include="Variants\MultiDepot\IMultiDepotOperator.cs" /> 318 <Compile Include="Variants\MultiDepot\IMultiDepotProblemInstance.cs" /> 307 319 <Compile Include="Variants\PickupAndDelivery\IPickupAndDeliveryOperator.cs" /> 308 320 <Compile Include="Variants\PickupAndDelivery\IPickupAndDeliveryProblemInstance.cs" /> … … 318 330 <Compile Include="ProblemInstances\SingleDepotVRP\CVRP\CVRPTW\CVRPTWEvaluator.cs" /> 319 331 <Compile Include="ProblemInstances\SingleDepotVRP\CVRP\CVRPEvaluator.cs" /> 320 <Compile Include="ProblemInstances\SingleDepotVRP\SingleDepotVRPEvaluator.cs" />321 332 <Compile Include="ProblemInstances\VRPEvaluator.cs" /> 322 333 <Compile Include="ProblemInstances\VRPEvaluation.cs" /> -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Interfaces/IVRPEncoding.cs
r4363 r6851 29 29 public interface IVRPEncoding: IItem { 30 30 List<Tour> GetTours(); 31 int GetTourIndex(Tour tour); 32 int GetVehicleAssignment(int tour); 31 33 } 32 34 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Interfaces/IVRPEvaluator.cs
r6838 r6851 35 35 VRPEvaluation EvaluateTour(IVRPProblemInstance instance, Tour tour, IVRPEncoding solution); 36 36 bool Feasible(VRPEvaluation evaluation); 37 double GetInsertionCosts(IVRPProblemInstance instance, VRPEvaluation eval, int customer, int tour, int index, out bool feasible);37 double GetInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, VRPEvaluation eval, int customer, int tour, int index, out bool feasible); 38 38 } 39 39 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Interfaces/IVRPProblemInstance.cs
r6838 r6851 48 48 DoubleValue DistanceFactor { get; } 49 49 50 double GetDistance(int start, int end); 50 double[] GetCoordinates(int city); 51 double GetDemand(int city); 52 double GetDistance(int start, int end, IVRPEncoding solution); 53 double GetInsertionDistance(int start, int customer, int end, IVRPEncoding solution); 51 54 bool Feasible(IVRPEncoding solution); 52 55 bool TourFeasible(Tour tour, IVRPEncoding solution); … … 54 57 VRPEvaluation EvaluateTour(Tour tour, IVRPEncoding solution); 55 58 bool Feasible(VRPEvaluation eval); 56 double GetInsertionCosts(VRPEvaluation eval, int customer, int tour, int index, out bool feasible);59 double GetInsertionCosts(VRPEvaluation eval, IVRPEncoding solution, int customer, int tour, int index, out bool feasible); 57 60 } 58 61 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPEvaluator.cs
r6838 r6851 38 38 [Item("CVRPEvaluator", "Represents a single depot CVRP evaluator.")] 39 39 [StorableClass] 40 public class CVRPEvaluator: SingleDepotVRPEvaluator {40 public class CVRPEvaluator: VRPEvaluator { 41 41 public ILookupParameter<DoubleValue> OverloadParameter { 42 42 get { return (ILookupParameter<DoubleValue>)Parameters["Overload"]; } … … 79 79 80 80 //drive there 81 double currentDistace = instance.GetDistance(start, end );81 double currentDistace = instance.GetDistance(start, end, solution); 82 82 distance += currentDistace; 83 83 … … 103 103 } 104 104 105 protected override double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer,105 protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 106 106 out bool feasible) { 107 107 CVRPInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPInsertionInfo; … … 113 113 double overloadPenalty = cvrp.OverloadPenalty.Value; 114 114 115 double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End );115 double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End, solution); 116 116 double newDistance = 117 instance.GetDistance(insertionInfo.Start, customer ) +118 instance.GetDistance(customer, insertionInfo.End );117 instance.GetDistance(insertionInfo.Start, customer, solution) + 118 instance.GetDistance(customer, insertionInfo.End, solution); 119 119 costs += instance.DistanceFactor.Value * (newDistance - distance); 120 120 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWEvaluator.cs
r6838 r6851 85 85 86 86 //drive there 87 double currentDistace = vrptw.GetDistance(start, end );87 double currentDistace = vrptw.GetDistance(start, end, solution); 88 88 time += currentDistace; 89 89 distance += currentDistace; … … 166 166 } 167 167 168 protected override double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer,168 protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 169 169 out bool feasible) { 170 170 CVRPPDTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPPDTWInsertionInfo; … … 187 187 double pickupPenalty = pdp.PickupViolationPenalty.Value; 188 188 189 double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End );189 double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End, solution); 190 190 double newDistance = 191 instance.GetDistance(insertionInfo.Start, customer ) +192 instance.GetDistance(customer, insertionInfo.End );191 instance.GetDistance(insertionInfo.Start, customer, solution) + 192 instance.GetDistance(customer, insertionInfo.End, solution); 193 193 costs += instance.DistanceFactor.Value * (newDistance - distance); 194 194 … … 215 215 if (index > 0) 216 216 time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime; 217 time += instance.GetDistance(insertionInfo.Start, customer );217 time += instance.GetDistance(insertionInfo.Start, customer, solution); 218 218 if (time > dueTime[customer]) { 219 219 tardiness += time - dueTime[customer]; … … 222 222 time += readyTime[customer] - time; 223 223 time += serviceTimes[customer]; 224 time += instance.GetDistance(customer, insertionInfo.End );224 time += instance.GetDistance(customer, insertionInfo.End, solution); 225 225 226 226 double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWEvaluator.cs
r6838 r6851 92 92 93 93 //drive there 94 double currentDistace = vrptw.GetDistance(start, end );94 double currentDistace = vrptw.GetDistance(start, end, solution); 95 95 time += currentDistace; 96 96 distance += currentDistace; … … 150 150 } 151 151 152 protected override double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer,152 protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 153 153 out bool feasible) { 154 154 CVRPTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo; … … 166 166 double tardinessPenalty = vrptw.TardinessPenalty.Value; 167 167 168 double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End );168 double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End, solution); 169 169 double newDistance = 170 instance.GetDistance(insertionInfo.Start, customer ) +171 instance.GetDistance(customer, insertionInfo.End );170 instance.GetDistance(insertionInfo.Start, customer, solution) + 171 instance.GetDistance(customer, insertionInfo.End, solution); 172 172 costs += instance.DistanceFactor.Value * (newDistance - distance); 173 173 … … 186 186 if (index > 0) 187 187 time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime; 188 time += instance.GetDistance(insertionInfo.Start, customer );188 time += instance.GetDistance(insertionInfo.Start, customer, solution); 189 189 if (time > dueTime[customer]) { 190 190 tardiness += time - dueTime[customer]; … … 193 193 time += readyTime[customer] - time; 194 194 time += serviceTimes[customer]; 195 time += instance.GetDistance(customer, insertionInfo.End );195 time += instance.GetDistance(customer, insertionInfo.End, solution); 196 196 197 197 double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/SingleDepotVRPEvaluator.cs
r6838 r6851 57 57 58 58 //drive there 59 double currentDistace = instance.GetDistance(start, end );59 double currentDistace = instance.GetDistance(start, end, solution); 60 60 distance += currentDistace; 61 61 … … 75 75 } 76 76 77 protected override double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer,77 protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 78 78 out bool feasible) { 79 79 StopInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index); … … 82 82 feasible = true; 83 83 84 double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End );84 double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End, solution); 85 85 double newDistance = 86 instance.GetDistance(insertionInfo.Start, customer ) +87 instance.GetDistance(customer, insertionInfo.End );86 instance.GetDistance(insertionInfo.Start, customer, solution) + 87 instance.GetDistance(customer, insertionInfo.End, solution); 88 88 89 89 costs += instance.DistanceFactor.Value * (newDistance - distance); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPEvaluator.cs
r6838 r6851 103 103 } 104 104 105 protected abstract double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer, out bool feasible);105 protected abstract double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer, out bool feasible); 106 106 107 public double GetInsertionCosts(IVRPProblemInstance instance, VRPEvaluation eval, int customer, int tour, int index, out bool feasible) {107 public double GetInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, VRPEvaluation eval, int customer, int tour, int index, out bool feasible) { 108 108 bool tourFeasible; 109 109 double costs = GetTourInsertionCosts( 110 110 instance, 111 solution, 111 112 eval.InsertionInfo.GetTourInsertionInfo(tour), index, 112 113 customer, out tourFeasible); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs
r6838 r6851 188 188 } 189 189 190 public virtual double[] GetCoordinates(int city) { 191 double[] coordinates = new double[Coordinates.Columns]; 192 193 for (int i = 0; i < Coordinates.Columns; i++) { 194 coordinates[i] = Coordinates[city, i]; 195 } 196 197 return coordinates; 198 } 199 200 public virtual double GetDemand(int city) { 201 return Demand[city]; 202 } 203 190 204 //cache for performance improvement 191 205 private DoubleMatrix distanceMatrix = null; 192 206 private IVRPEvaluator evaluator = null; 193 207 194 public double GetDistance(int start, int end) {208 public virtual double GetDistance(int start, int end, IVRPEncoding solution) { 195 209 double distance = 0.0; 196 210 if (distanceMatrix == null && UseDistanceMatrix.Value) { … … 206 220 } 207 221 222 public virtual double GetInsertionDistance(int start, int customer, int end, IVRPEncoding solution) { 223 double distance = GetDistance(start, end, solution); 224 double newDistance = 225 GetDistance(start, customer, solution) + 226 GetDistance(customer, end, solution); 227 228 return newDistance - distance; 229 } 230 208 231 public bool Feasible(IVRPEncoding solution) { 209 232 return evaluator.Feasible( … … 230 253 } 231 254 232 public double GetInsertionCosts(VRPEvaluation eval, int customer, int tour, int index, out bool feasible) {233 return evaluator.GetInsertionCosts(this, eval, customer, tour, index, out feasible);255 public double GetInsertionCosts(VRPEvaluation eval, IVRPEncoding solution, int customer, int tour, int index, out bool feasible) { 256 return evaluator.GetInsertionCosts(this, solution, eval, customer, tour, index, out feasible); 234 257 } 235 258 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs
r6710 r6851 243 243 #endregion 244 244 245 public void ImportFromCordeau(string cordeauFileName) { 246 CordeauParser parser = new CordeauParser(cordeauFileName); 247 parser.Parse(); 248 249 MDCVRPProblemInstance problem = new MDCVRPProblemInstance(); 250 251 problem.Coordinates = new DoubleMatrix(parser.Coordinates); 252 problem.Vehicles.Value = parser.Vehicles; 253 problem.Capacity = new DoubleArray(parser.Capacity); 254 problem.Demand = new DoubleArray(parser.Demands); 255 problem.Depots.Value = parser.Depots; 256 problem.VehicleDepotAssignment = new IntArray(parser.Vehicles); 257 int depot = 0; 258 int i = 0; 259 while(i < parser.Vehicles) { 260 problem.VehicleDepotAssignment[i] = depot; 261 262 i++; 263 if (i % (parser.Vehicles / parser.Depots) == 0) 264 depot++; 265 } 266 267 this.ProblemInstance = problem; 268 269 OnReset(); 270 } 271 245 272 public void ImportFromLiLim(string liLimFileName) { 246 273 LiLimParser parser = new LiLimParser(liLimFileName); 247 274 parser.Parse(); 248 275 249 276 CVRPPDTWProblemInstance problem = new CVRPPDTWProblemInstance(); 250 277 … … 372 399 } else { 373 400 problem.Demand[i] = rand.Next(10, 50); 374 problem.DueTime[i] = rand.Next((int)Math.Ceiling(problem.GetDistance(0, i )), 1200);401 problem.DueTime[i] = rand.Next((int)Math.Ceiling(problem.GetDistance(0, i, null)), 1200); 375 402 problem.ReadyTime[i] = problem.DueTime[i] - rand.Next(0, 100); 376 403 problem.ServiceTime[i] = 90;
Note: See TracChangeset
for help on using the changeset viewer.