本文整理汇总了C#中Graph.AddDirectedEdge方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.AddDirectedEdge方法的具体用法?C# Graph.AddDirectedEdge怎么用?C# Graph.AddDirectedEdge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph.AddDirectedEdge方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: should_add_the_to_node_from_nodes_neighborlist
public void should_add_the_to_node_from_nodes_neighborlist()
{
var graph = new Graph<string>();
graph.AddNode("Berlin");
graph.AddNode("Paris");
graph.AddDirectedEdge("Berlin", "Paris", 0);
Assert.That(graph.NodeCount, Is.EqualTo(2));
}
示例2: should_also_add_the_weight_to_the_edge
public void should_also_add_the_weight_to_the_edge()
{
var graph = new Graph<string>();
graph.AddNode("Berlin");
graph.AddNode("Paris");
graph.AddDirectedEdge("Berlin", "Paris", 0);
Assert.That(graph.NodeCount, Is.EqualTo(2));
Assert.That(graph.DrawAdjcentLists(), Is.EqualTo("Berlin->Paris\nParis\n"));
}
示例3: Solve
static void Solve(string[] args)
{
Graph<int> graph = new Graph<int>();
graph.AddNode(1);
graph.AddNode(2);
GraphNodeDictionary<int> gNodes = graph.Nodes;
graph.AddDirectedEdge(gNodes[1], gNodes[2]);
}
示例4: read
public static void read(XmlTextReader reader, string source, string target, string name, string extension, string instruction, Graph<string> graph)
{
try{
while (reader.Read()){
switch (reader.NodeType){
case XmlNodeType.Element: // The node is an element.
Console.Write("<" + reader.Name);
if (reader.Name == "node")
{
while (reader.MoveToNextAttribute()){// Read the attributes.
if (reader.Name == "name"){
name = reader.Value;
extension = System.IO.Path.GetExtension(reader.Value);
}
}
}
if (reader.Name == "edge"){
while (reader.MoveToNextAttribute()){
if (reader.Name == "source"){
source = reader.Value;
}
else if (reader.Name == "target"){
target = reader.Value;
}
}
graph.AddDirectedEdge(new GraphNode<string>(source), new GraphNode<string>(target), 1);
source = "";
target = "";
}
break;
}
}
}
catch (Exception e) { }
return new KeyValuePair<Graph<string>, Dictionary<string, BuildElement>>(graph, elements);
}
示例5: PopulateTownNodes
public void PopulateTownNodes()
{
TrainStations = new Graph<string>();
TrainStations.AddNode("A");
TrainStations.AddNode("B");
TrainStations.AddNode("C");
TrainStations.AddNode("D");
TrainStations.AddNode("E");
TrainStations.AddNode("F");
TrainStations.AddDirectedEdge((GraphNode<string>)TrainStations.Nodes.FindByValue("A"),
(GraphNode<string>)TrainStations.Nodes.FindByValue("B"), 5);
TrainStations.AddDirectedEdge((GraphNode<string>)TrainStations.Nodes.FindByValue("B"),
(GraphNode<string>)TrainStations.Nodes.FindByValue("C"), 4);
TrainStations.AddDirectedEdge((GraphNode<string>)TrainStations.Nodes.FindByValue("C"),
(GraphNode<string>)TrainStations.Nodes.FindByValue("D"), 8);
TrainStations.AddDirectedEdge((GraphNode<string>)TrainStations.Nodes.FindByValue("D"),
(GraphNode<string>)TrainStations.Nodes.FindByValue("C"), 8);
TrainStations.AddDirectedEdge((GraphNode<string>)TrainStations.Nodes.FindByValue("D"),
(GraphNode<string>)TrainStations.Nodes.FindByValue("E"), 6);
TrainStations.AddDirectedEdge((GraphNode<string>)TrainStations.Nodes.FindByValue("A"),
(GraphNode<string>)TrainStations.Nodes.FindByValue("D"), 5);
TrainStations.AddDirectedEdge((GraphNode<string>)TrainStations.Nodes.FindByValue("C"),
(GraphNode<string>)TrainStations.Nodes.FindByValue("E"), 2);
TrainStations.AddDirectedEdge((GraphNode<string>)TrainStations.Nodes.FindByValue("E"),
(GraphNode<string>)TrainStations.Nodes.FindByValue("B"), 3);
TrainStations.AddDirectedEdge((GraphNode<string>)TrainStations.Nodes.FindByValue("A"),
(GraphNode<string>)TrainStations.Nodes.FindByValue("E"), 7);
}
示例6: readbuildfile
public KeyValuePair<Graph<string>, Dictionary<string, BuildElement>> readbuildfile(string absfilepath)
{
XmlTextReader reader = new XmlTextReader(absfilepath);
Graph<string> buildgraph = new Graph<string>();
Dictionary<string, BuildElement> buildelements = new Dictionary<string, BuildElement>();
string name = "";
string extension = "";
string instruction = "";
string source = "";
string target = "";
try
{
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
Console.Write("<" + reader.Name);
if (reader.Name == "node")
{
while (reader.MoveToNextAttribute())// Read the attributes.
{
if (reader.Name == "name")
{
name = reader.Value;
extension = System.IO.Path.GetExtension(reader.Value);
}
Console.Write(" " + reader.Name + "='" + reader.Value + "'");
}
}
if (reader.Name == "edge")
{
while (reader.MoveToNextAttribute())// Read the attributes.
{
if (reader.Name == "source")
{
source = reader.Value;
}
else if (reader.Name == "target")
{
target = reader.Value;
}
//Console.Write(" " + reader.Name + "='" + reader.Value + "'");
}
buildgraph.AddDirectedEdge(new GraphNode<string>(source), new GraphNode<string>(target), 1);
source = "";
target = "";
}
Console.WriteLine(">");
break;
case XmlNodeType.Text: //Display the text in each element.
instruction = reader.Value;
Console.WriteLine(reader.Value);
break;
case XmlNodeType.EndElement: //Display the end of the element.
if (reader.Name == "node")
{
buildgraph.AddNode(name);
buildelements.Add(name, new BuildElement(name, extension, instruction));
name = "";
extension = "";
instruction = "";
}
Console.Write("</" + reader.Name);
Console.WriteLine(">");
break;
}
}
}
catch (Exception e)
{
Console.WriteLine("Exception in XmlReader");
}
return new KeyValuePair<Graph<string>, Dictionary<string, BuildElement>>(buildgraph, buildelements);
}
示例7: ConstructADirectedGraph
private static Graph<int> ConstructADirectedGraph()
{
var directedGraph = new Graph<int>();
directedGraph.AddNode(1);
directedGraph.AddNode(2);
directedGraph.AddNode(3);
directedGraph.AddNode(4);
directedGraph.AddNode(5);
directedGraph.AddNode(6);
directedGraph.AddNode(7);
directedGraph.AddNode(8);
directedGraph.AddDirectedEdge(1, 2);
directedGraph.AddDirectedEdge(1, 3);
directedGraph.AddDirectedEdge(3, 4);
directedGraph.AddDirectedEdge(4, 5);
directedGraph.AddDirectedEdge(5, 6);
directedGraph.AddDirectedEdge(6, 7);
directedGraph.AddDirectedEdge(2, 8);
directedGraph.AddDirectedEdge(2, 5);
directedGraph.AddDirectedEdge(8, 7);
directedGraph.AddDirectedEdge(2, 4);
return directedGraph;
}
示例8: Setup
public void Setup()
{
_web = new Graph<string>();
_web.AddNode("1");
_web.AddNode("2");
_web.AddNode("3");
_web.AddNode("4");
_web.AddNode("5");
_web.AddNode("6");
_web.AddDirectedEdge("1", "3",5);
_web.AddDirectedEdge("3", "6",6);
_web.AddDirectedEdge("6", "1",1);
_web.AddDirectedEdge("2", "1",8);
_web.AddDirectedEdge("2", "6",0);
_web.AddDirectedEdge("2", "4",2);
_web.AddDirectedEdge("6", "4",17);
_web.AddDirectedEdge("6", "5",1);
_web.AddDirectedEdge("5", "4",2);
}
示例9: readbuildfile
public KeyValuePair<Graph<string>, Dictionary<string, BuildElement>> readbuildfile(string absfilepath)
{
XmlTextReader reader = new XmlTextReader(absfilepath);
Graph<string> buildgraph = new Graph<string>();
Dictionary<string, BuildElement> buildelements = new Dictionary<string, BuildElement>();
string name = "";
string extension = "";
string instruction = "";
string source = "";
string target = "";
bool dep = false;
bool command = false;
BuildElement element = null;
try
{
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
Console.Write("<" + reader.Name);
if (reader.Name == "file")
{
element = new BuildElement();
while (reader.MoveToNextAttribute())// Read the attributes.
{
if (reader.Name == "name")
{
name = reader.Value;
source = reader.Value;
extension = System.IO.Path.GetExtension(reader.Value);
element.setName(name);
element.setExtension(extension);
buildelements.Add(name, element);
//buildgraph.AddNode(name);
}
Console.Write(" " + reader.Name + "='" + reader.Value + "'");
}
}
if (reader.Name == "dep")
{
dep = true;
}
if (reader.Name == "command")
{
command = true;
}
Console.WriteLine(">");
break;
case XmlNodeType.Text: //Display the text in each element.
if (dep)
{
target = reader.Value;
if (!buildgraph.Contains(source))
buildgraph.AddNode(source);
if (!buildgraph.Contains(target))
buildgraph.AddNode(target);
buildgraph.AddDirectedEdge((GraphNode<string>)buildgraph.GetNode(source), (GraphNode<string>)buildgraph.GetNode(target), 1);
buildelements[source].dependencies.Add(target);
target = "";
dep = false;
}
if (command)
{
buildelements[name].setBuildInstruction(reader.Value);
command = false;
}
Console.WriteLine(reader.Value);
break;
case XmlNodeType.EndElement: //Display the end of the element.
if (reader.Name == "file")
{
element = null;
}
Console.Write("</" + reader.Name);
Console.WriteLine(">");
break;
}
}
}
catch (Exception e)
{
Console.WriteLine("Exception in XmlReader: "+e.Message);
}
return new KeyValuePair<Graph<string>, Dictionary<string, BuildElement>>(buildgraph, buildelements);
}