当前位置: 首页>>代码示例>>C#>>正文


C# Route.SwapOrders方法代码示例

本文整理汇总了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;
        }
开发者ID:Gliath,项目名称:GroteOpdrachtOpt,代码行数:41,代码来源:RandomStepOpt3Strategy.cs

示例2: swapOrders

 private void swapOrders(Order A, Order B, Route route)
 {
     route.SwapOrders(A, B);
 }
开发者ID:Gliath,项目名称:GroteOpdrachtOpt,代码行数:4,代码来源:RandomRouteOpt2Strategy.cs


注:本文中的Route.SwapOrders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。