本文整理汇总了C#中Route.SwapOrders方法的典型用法代码示例。如果您正苦于以下问题:C# Route.SwapOrders方法的具体用法?C# Route.SwapOrders怎么用?C# Route.SwapOrders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Route
的用法示例。
在下文中一共展示了Route.SwapOrders方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: executeStrategy
public override Solution executeStrategy(Solution toStartFrom)
{
Planning = toStartFrom.GetRandomPlanning();
if (Planning.Item3.Count == 0)
return toStartFrom;
old_route = Planning.Item3[random.Next(Planning.Item3.Count)];
if (old_route == null || old_route.Orders.Count < 4)
return toStartFrom; // Could not find a valid route to shuffle
new_route = new Route(Planning.Item1);
foreach (Order order in old_route.Orders)
new_route.AddOrder(order);
int firstIndex = random.Next(old_route.Orders.Count - 1);
int secondIndex = random.Next(old_route.Orders.Count - 1);
int thirdIndex = random.Next(old_route.Orders.Count - 1);
if (firstIndex == secondIndex || firstIndex == thirdIndex || secondIndex == thirdIndex)
return toStartFrom;
double timeLimit = 0.0d; // Check if route can be swapped traveltime-wise
foreach (Route route in Planning.Item3)
if (route != old_route)
timeLimit += route.TravelTime;
timeLimit = 43200.0d - timeLimit;
if (new_route.CanSwapOrder(old_route.Orders[firstIndex], old_route.Orders[secondIndex], old_route.Orders[thirdIndex], timeLimit))
{
new_route.SwapOrders(old_route.Orders[firstIndex], old_route.Orders[secondIndex], old_route.Orders[thirdIndex]);
toStartFrom.AddRoute(new_route);
toStartFrom.RemoveRouteFromPlanning(Planning.Item1, Planning.Item2, old_route);
toStartFrom.AddRouteToPlanning(Planning.Item1, Planning.Item2, new_route);
toStartFrom.RemoveRoute(old_route);
strategyHasExecuted = true;
}
return toStartFrom;
}
示例2: swapOrders
private void swapOrders(Order A, Order B, Route route)
{
route.SwapOrders(A, B);
}