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


C# IRoute.GetNeigbours方法代码示例

本文整理汇总了C#中IRoute.GetNeigbours方法的典型用法代码示例。如果您正苦于以下问题:C# IRoute.GetNeigbours方法的具体用法?C# IRoute.GetNeigbours怎么用?C# IRoute.GetNeigbours使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IRoute的用法示例。


在下文中一共展示了IRoute.GetNeigbours方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Try3OptMoves

 /// <summary>
 /// Tries all 3Opt Moves for the neighbourhood of v_1 containing v_3.
 /// </summary>
 /// <param name="problem"></param>
 /// <param name="weights"></param>
 /// <param name="route"></param>
 /// <param name="v1"></param>
 /// <param name="v_2"></param>
 /// <param name="weight_1_2"></param>
 /// <param name="v_3"></param>
 /// <returns></returns>
 public bool Try3OptMoves(IProblemWeights problem, double[][] weights, IRoute route,
     int v1, int v_2, double weight_1_2,
     int v_3)
 {
     // get v_4.
     int v_4 = route.GetNeigbours(v_3)[0];
     double weight_1_2_plus_3_4 = weight_1_2 + weights[v_3][v_4];
     double weight_1_4 = weights[v1][v_4];
     double[] weights_3 = weights[v_3];
     return this.Try3OptMoves(problem, weights, route, v1, v_2, v_3, weights_3, v_4, weight_1_2_plus_3_4, weight_1_4);
 }
开发者ID:UnifyKit,项目名称:OsmSharp,代码行数:22,代码来源:HillClimbing3OptSolver.cs

示例2: Improve

        /// <summary>
        /// Tries to improve the existing route using CI and return true if succesful.
        /// </summary>
        /// <param name="problem"></param>
        /// <param name="route"></param>
        /// <param name="difference"></param>
        /// <returns></returns>
        public bool Improve(IProblemWeights problem, IRoute route, out double difference)
        {
            bool improvement = false;

            difference = 0;
            if (route.Count > 3)
            {
                // loop over all customers and try cheapest insertion.
                for (int customer = 0; customer < problem.Size; customer++)
                {
                    //string route_string = route.ToString();
                    //IRoute previous = route.Clone() as IRoute;
                    if (route.Contains(customer))
                    {
                        // remove customer and keep position.
                        int next = route.GetNeigbours(customer)[0];
                        route.Remove(customer);

                        // insert again.
                        ArbitraryInsertionSolver.InsertOne(problem, route, customer, out difference);

                        if (!route.IsValid())
                        {
                            throw new Exception();
                        }
                        if (route.GetNeigbours(customer)[0] != next
                            && difference < 0)
                        { // another customer was found as the best, improvement is succesful.
                            improvement = true;
                            break;
                        }
                    }
                }
            }
            return improvement;
        }
开发者ID:UnifyKit,项目名称:OsmSharp,代码行数:43,代码来源:ArbitraryInsertionSolver.cs


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