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