當前位置: 首頁>>代碼示例>>C#>>正文


C# Edge.ToGraph方法代碼示例

本文整理匯總了C#中System.Edge.ToGraph方法的典型用法代碼示例。如果您正苦於以下問題:C# Edge.ToGraph方法的具體用法?C# Edge.ToGraph怎麽用?C# Edge.ToGraph使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Edge的用法示例。


在下文中一共展示了Edge.ToGraph方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: testGraph

        private static void testGraph()
        {
            //see graph.png
            Edge<string, float>[] edges = new Edge<string, float>[] 
            {
                new Edge<string, float>("1", "2", 7),
                new Edge<string, float>("1", "3", 9),
                new Edge<string, float>("1", "6", 14),

                new Edge<string, float>("2", "3", 10),
                new Edge<string, float>("2", "4", 15),

                new Edge<string, float>("3", "6", 2),
                new Edge<string, float>("3", "4", 11),

                new Edge<string, float>("4", "5", 6),

                new Edge<string, float>("5", "6", 9)
            };

            var graph = edges.ToGraph<string, Edge<string, float>>();

            IDictionary<Pair<string>, double> costMatrix;
            var paths = graph.FindShortestPaths(x => x.Tag, out costMatrix);

            var vertices = graph.GetVertices<string, Edge<string, float>>();

            Console.WriteLine("Possible paths:");
            foreach (var v1 in vertices)
            {
                foreach (var v2 in vertices)
                {
                    var path = paths.Get(v1, v2);
                    var cost = costMatrix.ContainsKey(v1, v2) ? costMatrix.Get(v1, v2): Double.NaN;

                    Console.Write("{0} => {1}: Cost {2}. Edges:", v1, v2, cost.ToString().PadLeft(3));
                    foreach (var edge in path)
                    {
                        Console.Write("({0} => {1}) ", edge.Source, edge.Destination);
                    }
                    Console.WriteLine();
                }
            }
        }
開發者ID:Candy29,項目名稱:accord-net-extensions,代碼行數:44,代碼來源:Program.cs


注:本文中的System.Edge.ToGraph方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。