本文整理匯總了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();
}
}
}