本文整理汇总了C#中HeuristicLab.Problems.VehicleRouting.Encodings.Potvin.PotvinEncoding.GetVehicleAssignment方法的典型用法代码示例。如果您正苦于以下问题:C# PotvinEncoding.GetVehicleAssignment方法的具体用法?C# PotvinEncoding.GetVehicleAssignment怎么用?C# PotvinEncoding.GetVehicleAssignment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HeuristicLab.Problems.VehicleRouting.Encodings.Potvin.PotvinEncoding
的用法示例。
在下文中一共展示了PotvinEncoding.GetVehicleAssignment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Apply
public static void Apply(PotvinEncoding solution, PotvinPDShiftMove move, IVRPProblemInstance problemInstance) {
bool newTour = false;
if (move.Tour >= solution.Tours.Count) {
solution.Tours.Add(new Tour());
newTour = true;
}
Tour tour = solution.Tours[move.Tour];
Tour oldTour = solution.Tours.Find(t => t.Stops.Contains(move.City));
oldTour.Stops.Remove(move.City);
if (problemInstance is IPickupAndDeliveryProblemInstance) {
IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance;
int location = pdp.GetPickupDeliveryLocation(move.City);
Tour oldTour2 = solution.Tours.Find(t => t.Stops.Contains(location));
oldTour2.Stops.Remove(location);
solution.InsertPair(tour, move.City, location, problemInstance);
} else {
int place = solution.FindBestInsertionPlace(tour, move.City);
tour.Stops.Insert(place, move.City);
}
if (newTour) {
List<int> vehicles = new List<int>();
for (int i = move.Tour; i < problemInstance.Vehicles.Value; i++) {
vehicles.Add(solution.GetVehicleAssignment(i));
}
double bestQuality = double.MaxValue;
int bestVehicle = -1;
int originalVehicle = solution.GetVehicleAssignment(move.Tour);
foreach (int vehicle in vehicles) {
solution.VehicleAssignment[move.Tour] = vehicle;
double quality = problemInstance.EvaluateTour(tour, solution).Quality;
if (quality < bestQuality) {
bestQuality = quality;
bestVehicle = vehicle;
}
}
solution.VehicleAssignment[move.Tour] = originalVehicle;
int index = -1;
for (int i = move.Tour; i < solution.VehicleAssignment.Length; i++) {
if (solution.VehicleAssignment[i] == bestVehicle) {
index = i;
break;
}
}
solution.VehicleAssignment[index] = originalVehicle;
solution.VehicleAssignment[move.Tour] = bestVehicle;
}
solution.Repair();
}