本文整理汇总了C#中Graph.InsertNewVertex方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.InsertNewVertex方法的具体用法?C# Graph.InsertNewVertex怎么用?C# Graph.InsertNewVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph.InsertNewVertex方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: hasAdjacentNodeTest
public void hasAdjacentNodeTest()
{
try
{
Graph g = new Graph();
Node n1 = new PointOfInterest(1, 0, 0, 1);
Node n2 = new PointOfInterest(2, 0, 0, 1);
Node n3 = new PointOfInterest(3, 0, 0, 1);
g.InsertNewVertex(n1);
g.InsertNewVertex(n2);
g.InsertNewVertex(n3);
n1.addListOfAdjacentNodes(new Dictionary<Node, float>() { { n2, 4 } });
n2.addListOfAdjacentNodes(new Dictionary<Node, float>() { { n1, 3 } });
Assert.IsNotNull(g);
Assert.IsNotNull(n1);
Assert.IsNotNull(n2);
Assert.IsNotNull(n3);
Assert.True(n1.isAdjacent(n2),
"This tests if isAdjacent returns true if a node is adjacent to a given one.");
}
catch (SecurityException e)
{
Console.WriteLine("Security Exception:\n\n{0}", e.Message);
}
}
示例2: addNodeTest
public void addNodeTest()
{
try
{
Map map = new Map();
Graph g = new Graph();
Node n1 = new PointOfInterest(1, 0, 0, 1);
Node n2 = new PointOfInterest(2, 0, 0, 1);
List<Node> nodeList = new List<Node>();
nodeList.Add(n1);
nodeList.Add(n2);
g.InsertNewVertex(n1);
g.InsertNewVertex(n2);
map.addNode(n1);
map.addNode(n2);
Graph mapGraph = map.getGraph();
List<Node> mapNodes = map.GetPoiNodes();
Assert.IsNotNull(nodeList);
Assert.IsNotNull(g);
Assert.IsNotNull(mapGraph);
Assert.IsNotNull(mapNodes);
Assert.Equals(nodeList, mapNodes);
Assert.Equals(g, mapGraph);
}
catch (SecurityException e)
{
Console.WriteLine("Security Exception:\n\n{0}", e.Message);
}
}
示例3: BFSTestOneNodeIsVisited
public void BFSTestOneNodeIsVisited()
{
try
{
Graph g = new Graph();
Node n1 = new PointOfInterest(1, 0, 0, 1);
Node n2 = new PointOfInterest(2, 0, 0, 1);
Node n3 = new PointOfInterest(3, 0, 0, 1);
Node n4 = new PointOfInterest(4, 0, 0, 1);
Node n5 = new PointOfInterest(5, 0, 0, 1);
g.InsertNewVertex(n1);
g.InsertNewVertex(n2);
g.InsertNewVertex(n3);
g.InsertNewVertex(n4);
g.InsertNewVertex(n5);
n1.addListOfAdjacentNodes(new Dictionary<Node, float>() {{n2, 4}, {n3, 2}});
n2.addListOfAdjacentNodes(new Dictionary<Node, float>() {{n3, 3}, {n5, 3}, {n4, 2}});
n3.addListOfAdjacentNodes(new Dictionary<Node, float>() {{n4, 4}, {n5, 5}, {n2, 1}});
n4.addListOfAdjacentNodes(new Dictionary<Node, float>() {});
n5.addListOfAdjacentNodes(new Dictionary<Node, float>() {{n4, 1}});
g.BFS(n1);
State status = n4.getState();
Assert.IsNotNull(g);
Assert.IsNotNull(n1);
Assert.IsNotNull(n2);
Assert.IsNotNull(n3);
Assert.IsNotNull(n4);
Assert.IsNotNull(n5);
Assert.IsNotNull(status);
Assert.Equals(State.Visited, status);
}
catch (SecurityException e)
{
Console.WriteLine("Security Exception:\n\n{0}", e.Message);
}
}
示例4: BFSTestOneNodeNoPath
public void BFSTestOneNodeNoPath()
{
try
{
Graph g = new Graph();
Node n1 = new PointOfInterest(1, 0, 0, 1);
g.InsertNewVertex(n1);
State status = n1.getState();
Assert.Equals(State.UnVisited, status);
}
catch (SecurityException e)
{
Console.WriteLine("Security Exception:\n\n{0}", e.Message);
}
}
示例5: shortest_pathTestWithOneNode
public void shortest_pathTestWithOneNode()
{
try
{
Graph g = new Graph();
Node n1 = new PointOfInterest(1, 0, 0, 1);
Node n2 = new PointOfInterest(2, 0, 0, 1);
List<Node> nodelist = new List<Node>();
nodelist.Add(n1);
nodelist.Add(n2);
g.InsertNewVertex(n1);
n1.addListOfAdjacentNodes(new Dictionary<Node, float>() {{n1, 4}});
Assert.Equals(nodelist, g.shortest_path(n1, n1));
}
catch (SecurityException e)
{
Console.WriteLine("Security Exception:\n\n{0}", e.Message);
}
}
示例6: shortest_pathTestNoPath
public void shortest_pathTestNoPath()
{
try
{
Graph g = new Graph();
Node n1 = new PointOfInterest(1, 0, 0, 1);
Node n2 = new PointOfInterest(2, 0, 0, 1);
Node n3 = new PointOfInterest(3, 0, 0, 1);
Node n4 = new PointOfInterest(4, 0, 0, 1);
Node n5 = new PointOfInterest(5, 0, 0, 1);
g.InsertNewVertex(n1);
g.InsertNewVertex(n2);
g.InsertNewVertex(n3);
g.InsertNewVertex(n4);
g.InsertNewVertex(n5);
n1.addListOfAdjacentNodes(new Dictionary<Node, float>() {{n2, 4}, {n3, 2}});
n2.addListOfAdjacentNodes(new Dictionary<Node, float>() {{n3, 3}, {n4, 2}});
n3.addListOfAdjacentNodes(new Dictionary<Node, float>() {{n4, 4}, {n2, 1}});
n4.addListOfAdjacentNodes(new Dictionary<Node, float>() {});
n5.addListOfAdjacentNodes(new Dictionary<Node, float>() {});
Assert.IsNotNull(g);
Assert.IsNotNull(n1);
Assert.IsNotNull(n2);
Assert.IsNotNull(n3);
Assert.IsNotNull(n4);
Assert.IsNotNull(n5);
Assert.Equals(null, g.shortest_path(n1, n5));
}
catch (SecurityException e)
{
Console.WriteLine("Security Exception:\n\n{0}", e.Message);
}
}
示例7: shortest_pathTestIsNull
public void shortest_pathTestIsNull()
{
try
{
Graph g = new Graph();
Node n1 = new PointOfInterest(1, 0, 0, 1);
Node n2 = new PointOfInterest(2, 0, 0, 1);
g.InsertNewVertex(n1);
g.InsertNewVertex(n2);
Assert.Equals(null, g.shortest_path(n1, n2));
}
catch (SecurityException e)
{
Console.WriteLine("Security Exception:\n\n{0}", e.Message);
}
}
示例8: FindByKeyTest
public void FindByKeyTest()
{
try
{
Graph g = new Graph();
Node n1 = new PointOfInterest(1, 0, 0, 1);
Node n2 = new PointOfInterest(2, 0, 0, 1);
Node n3 = new PointOfInterest(3, 0, 0, 1);
g.InsertNewVertex(n1);
g.InsertNewVertex(n2);
g.InsertNewVertex(n3);
Assert.Equals(n2, g.FindByKey(2));
}
catch (SecurityException e)
{
Console.WriteLine("Security Exception:\n\n{0}", e.Message);
}
}
示例9: ExistKeyTest
public void ExistKeyTest()
{
try
{
Graph g = new Graph();
Node n1 = new PointOfInterest(1, 0, 0, 1);
Node n2 = new PointOfInterest(2, 0, 0, 1);
g.InsertNewVertex(n1);
g.InsertNewVertex(n2);
Assert.True(false);
}
catch (SecurityException e)
{
Console.WriteLine("Security Exception:\n\n{0}", e.Message);
}
}
示例10: getGraphTest
public void getGraphTest()
{
try
{
Map map = new Map();
Node n1 = new PointOfInterest(1, 0, 0, 1);
Node n2 = new PointOfInterest(2, 0, 0, 1);
map.addNode(n1);
map.addNode(n2);
Graph g = new Graph();
g.InsertNewVertex(n1);
g.InsertNewVertex(n2);
Assert.Equals(g, map.getGraph());
}
catch (SecurityException e)
{
Console.WriteLine("Security Exception:\n\n{0}", e.Message);
}
}