本文整理汇总了C#中AdjacencyGraph.DeserializeFromGraphML方法的典型用法代码示例。如果您正苦于以下问题:C# AdjacencyGraph.DeserializeFromGraphML方法的具体用法?C# AdjacencyGraph.DeserializeFromGraphML怎么用?C# AdjacencyGraph.DeserializeFromGraphML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdjacencyGraph
的用法示例。
在下文中一共展示了AdjacencyGraph.DeserializeFromGraphML方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadGraph
private static AdjacencyGraph<Node, Edge<Node>> ReadGraph(string filename)
{
var graph = new AdjacencyGraph<Node, Edge<Node>>();
using (var reader = XmlReader.Create(filename))
{
graph.DeserializeFromGraphML(reader,
id => new Node(),
(source, target, id) => new Edge<Node>(source, target));
}
return graph;
}
示例2: LoadGraph
public static AdjacencyGraph<string, Edge<string>> LoadGraph(string path)
{
// Save the graph
using (var xReader = XmlReader.Create(File.OpenText(path)))
{
var graph = new AdjacencyGraph<string, Edge<string>>();
graph.DeserializeFromGraphML<string, Edge<string>, AdjacencyGraph<string, Edge<string>>>(xReader,
id => id,
(source, target, id) => new Edge<string>(source, target));
return graph;
}
}
示例3: LoadGraph
public static AdjacencyGraph<string, Edge<string>> LoadGraph(string graphmlFile)
{
TestConsole.WriteLine(graphmlFile);
var g = new AdjacencyGraph<string, Edge<string>>();
using (var reader = new StreamReader(graphmlFile))
{
g.DeserializeFromGraphML(
reader,
id => id,
(source, target, id) => new Edge<string>(source, target)
);
}
return g;
}
示例4: DeserializeFromGraphMLNorth
public void DeserializeFromGraphMLNorth()
{
foreach (var graphmlFile in TestGraphFactory.GetFileNames())
{
Console.Write(graphmlFile);
var g = new AdjacencyGraph<string, Edge<string>>();
using (var reader = new StreamReader(graphmlFile))
{
g.DeserializeFromGraphML(
reader,
id => id,
(source, target, id) => new Edge<string>(source, target)
);
}
Console.Write(": {0} vertices, {1} edges", g.VertexCount, g.EdgeCount);
var vertices = new Dictionary<string, string>();
foreach(var v in g.Vertices)
vertices.Add(v, v);
// check all nodes are loaded
var settings = new XmlReaderSettings();
settings.XmlResolver = new GraphMLXmlResolver();
settings.DtdProcessing = DtdProcessing.Ignore;
settings.ValidationFlags = System.Xml.Schema.XmlSchemaValidationFlags.None;
using(var xreader = XmlReader.Create(graphmlFile, settings))
{
var doc = new XPathDocument(xreader);
foreach (XPathNavigator node in doc.CreateNavigator().Select("/graphml/graph/node"))
{
string id = node.GetAttribute("id", "");
Assert.IsTrue(vertices.ContainsKey(id));
}
TestConsole.Write(", vertices ok");
// check all edges are loaded
foreach (XPathNavigator node in doc.CreateNavigator().Select("/graphml/graph/edge"))
{
string source = node.GetAttribute("source", "");
string target = node.GetAttribute("target", "");
Assert.IsTrue(g.ContainsEdge(vertices[source], vertices[target]));
}
TestConsole.Write(", edges ok");
}
TestConsole.WriteLine();
}
}