本文整理汇总了C#中AdjacencyGraph.AddEdge方法的典型用法代码示例。如果您正苦于以下问题:C# AdjacencyGraph.AddEdge方法的具体用法?C# AdjacencyGraph.AddEdge怎么用?C# AdjacencyGraph.AddEdge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdjacencyGraph
的用法示例。
在下文中一共展示了AdjacencyGraph.AddEdge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Removing_Explicit_Edges_2
public void Removing_Explicit_Edges_2()
{
var graph = new AdjacencyGraph<int, Edge<int>>();
graph.AddVertex(1);
graph.AddVertex(2);
graph.AddVertex(3);
graph.AddVertex(4);
graph.AddVertex(5);
graph.AddVertex(6);
graph.AddVertex(7);
graph.AddEdge(new Edge<int>(1, 3));
graph.AddEdge(new Edge<int>(1, 4));
graph.AddEdge(new Edge<int>(1, 6));
graph.AddEdge(new Edge<int>(3, 6));
graph.AddEdge(new Edge<int>(4, 6));
graph.AddEdge(new Edge<int>(2, 4));
graph.AddEdge(new Edge<int>(2, 5));
graph.AddEdge(new Edge<int>(2, 7));
graph.AddEdge(new Edge<int>(4, 7));
graph.AddEdge(new Edge<int>(5, 7));
GraphHelper.RemoveExplicitEdges(graph);
Assert.AreEqual(8, graph.EdgeCount);
Assert.IsTrue(graph.ContainsEdge(1, 3));
Assert.IsTrue(graph.ContainsEdge(1, 4));
Assert.IsTrue(graph.ContainsEdge(2, 4));
Assert.IsTrue(graph.ContainsEdge(2, 5));
Assert.IsTrue(graph.ContainsEdge(3, 6));
Assert.IsTrue(graph.ContainsEdge(4, 6));
Assert.IsTrue(graph.ContainsEdge(4, 7));
Assert.IsTrue(graph.ContainsEdge(5, 7));
}
示例2: CheckPredecessorLineGraph
public void CheckPredecessorLineGraph()
{
AdjacencyGraph<int, Edge<int>> g = new AdjacencyGraph<int, Edge<int>>(true);
g.AddVertex(1);
g.AddVertex(2);
g.AddVertex(3);
Edge<int> e12 = new Edge<int>(1, 2); g.AddEdge(e12);
Edge<int> e23 = new Edge<int>(2, 3); g.AddEdge(e23);
var dij = new DijkstraShortestPathAlgorithm<int, Edge<int>>(g, e => 1);
var vis = new VertexPredecessorRecorderObserver<int, Edge<int>>();
using(vis.Attach(dij))
dij.Compute(1);
IEnumerable<Edge<int>> path;
Assert.IsTrue(vis.TryGetPath(2, out path));
var col = path.ToList();
Assert.AreEqual(1, col.Count);
Assert.AreEqual(e12, col[0]);
Assert.IsTrue(vis.TryGetPath(3, out path));
col = path.ToList();
Assert.AreEqual(2, col.Count);
Assert.AreEqual(e12, col[0]);
Assert.AreEqual(e23, col[1]);
}
示例3: createGraphWizDotFile
//DC this version was using the old QuickGraph MarkedEdge
public static void createGraphWizDotFile(AdjacencyGraph<String, TaggedEdge<String, String>> gGraphWizToPopulate,
TreeNode tnTreeNode, bool bOrder, bool bFilterName, bool bFilterClass,
int iFilterClassLevel)
{
if (bFilterClass)
tnTreeNode.Text = FilteredSignature.filterName(tnTreeNode.Text, false, false, true, 0, true, true,
iFilterClassLevel);
TaggedEdge<String, string> meTemp;
if (gGraphWizToPopulate.ContainsVertex(tnTreeNode.Text))
{
}
else
gGraphWizToPopulate.AddVertex(tnTreeNode.Text);
foreach (TreeNode tnChild in tnTreeNode.Nodes)
{
if (bFilterClass)
tnChild.Text = FilteredSignature.filterName(tnChild.Text, false, false, true, 0, true, true,
iFilterClassLevel);
createGraphWizDotFile(gGraphWizToPopulate, tnChild, bOrder, bFilterName, bFilterClass, iFilterClassLevel);
if (bOrder)
{
if (false == gGraphWizToPopulate.TryGetEdge(tnTreeNode.Text, tnChild.Text, out meTemp))
gGraphWizToPopulate.AddEdge(new TaggedEdge<String, string>(tnTreeNode.Text, tnChild.Text,
"marker"));
}
else if (false == gGraphWizToPopulate.TryGetEdge(tnChild.Text, tnTreeNode.Text, out meTemp))
gGraphWizToPopulate.AddEdge(new TaggedEdge<String, string>(tnChild.Text, tnTreeNode.Text, "marker"));
//gGraphToPopulate.AddEdge(tnTreeNode.Text, tnChild.Text);
// gGraphToPopulate.AddEdge(Analysis_CallFlow.display.filterName(tnChild.Text, false, false, false), Analysis_CallFlow.display.filterName(tnTreeNode.Text, false, false, false));
//else
}
}
示例4: TwoVertexCycle
public void TwoVertexCycle()
{
AdjacencyGraph<string, Edge<string>> g = new AdjacencyGraph<string, Edge<string>>(true);
g.AddVertex("v1");
g.AddVertex("v2");
g.AddEdge(new Edge<string>("v1", "v2"));
g.AddEdge(new Edge<string>("v2", "v1"));
StronglyConnectedComponentsAlgorithm<string, Edge<String>> strong = new StronglyConnectedComponentsAlgorithm<string, Edge<String>>(g);
strong.Compute();
Assert.AreEqual(1, strong.ComponentCount);
checkStrong(strong);
}
示例5: BuildDependencyGraph
public static AdjacencyGraph<PropertyInfo, STaggedEdge<PropertyInfo, string>> BuildDependencyGraph(Type viewModelType)
{
var directDependencies = ViewModelConventions.GetViewModelProperties(viewModelType).ToDictionary(p => p, GetDirectDependentProperties);
var graph = new AdjacencyGraph<PropertyInfo, STaggedEdge<PropertyInfo, string>>();
foreach (var directDependency in directDependencies)
{
var property = directDependency.Key;
graph.AddVertex(property);
foreach (var dependentProperty in directDependency.Value)
{
var sub = dependentProperty.SubPath;
var propertyType = property.PropertyType;
if (GetCollectionType(propertyType) != null) propertyType = GetCollectionType(propertyType);
if (String.IsNullOrEmpty(sub) && ViewModelConventions.IsViewModel(propertyType))
sub = "*";
graph.AddEdge(new STaggedEdge<PropertyInfo, string>(property, dependentProperty.Property, sub));
}
}
return graph;
}
示例6: GenerateDotFile
public void GenerateDotFile()
{
var graph = new AdjacencyGraph<string, TaggedEdge<string, string>>();
for (int i = 0; i < Math.Sqrt(Convert.ToDouble(m_Matrix.Length)); i++)
{
graph.AddVertex(String.Format("{0}", i));
}
for (int i = 0; i < Math.Sqrt(Convert.ToDouble(m_Matrix.Length)); i++)
{
for (int j = 0; j < Math.Sqrt(Convert.ToDouble(m_Matrix.Length)); j++)
{
if ((m_Matrix[i, j] == true) & (i < j))
{
graph.AddEdge(new TaggedEdge<string, string>(String.Format("{0}", i), String.Format("{0}", j), String.Format("{0}", i)));
}
}
}
var graphViz = new GraphvizAlgorithm<string, TaggedEdge<string, string>>(graph, @".\", QuickGraph.Graphviz.Dot.GraphvizImageType.Png);
graphViz.FormatVertex += (sender, e) =>
{
e.VertexFormatter.Shape = QuickGraph.Graphviz.Dot.GraphvizVertexShape.Circle;
};
graphViz.FormatEdge += (sender, e) =>
{
e.EdgeFormatter.Dir = QuickGraph.Graphviz.Dot.GraphvizEdgeDirection.None;
};
graphViz.Generate(new FileDotEngine(), m_Name);
}
示例7: Removing_Explicit_Edges_1
public void Removing_Explicit_Edges_1()
{
var graph = new AdjacencyGraph<int, Edge<int>>();
graph.AddVertex(1);
graph.AddVertex(2);
graph.AddVertex(3);
graph.AddEdge(new Edge<int>(1, 2));
graph.AddEdge(new Edge<int>(2, 3));
graph.AddEdge(new Edge<int>(1, 3));
GraphHelper.RemoveExplicitEdges(graph);
Assert.AreEqual(2, graph.EdgeCount);
Assert.IsTrue(graph.ContainsEdge(1, 2));
Assert.IsTrue(graph.ContainsEdge(2, 3));
}
示例8: RunOnLineGraph
public void RunOnLineGraph()
{
AdjacencyGraph<int, Edge<int>> g = new AdjacencyGraph<int, Edge<int>>(true);
g.AddVertex(1);
g.AddVertex(2);
g.AddVertex(3);
g.AddEdge(new Edge<int>(1,2));
g.AddEdge(new Edge<int>(2,3));
var dij = new DijkstraShortestPathAlgorithm<int, Edge<int>>(g, e => 1);
dij.Compute(1);
Assert.AreEqual<double>(0, dij.Distances[1]);
Assert.AreEqual<double>(1, dij.Distances[2]);
Assert.AreEqual<double>(2, dij.Distances[3]);
}
示例9: OneTwo
public void OneTwo()
{
var graph = new AdjacencyGraph<int, Edge<int>>();
graph.AddVertex(1);
graph.AddVertex(2);
graph.AddEdge(new Edge<int>(1, 2));
var t = new TopologicalSortAlgorithm<int, Edge<int>>(graph);
t.Compute();
}
示例10: RunOnDoubleLineGraph
public void RunOnDoubleLineGraph()
{
AdjacencyGraph<int, Edge<int>> g = new AdjacencyGraph<int, Edge<int>>(true);
g.AddVertex(1);
g.AddVertex(2);
g.AddVertex(3);
Edge<int> e12 = new Edge<int>(1, 2); g.AddEdge(e12);
Edge<int> e23 = new Edge<int>(2, 3); g.AddEdge(e23);
Edge<int> e13 = new Edge<int>(1, 3); g.AddEdge(e13);
var dij = new DijkstraShortestPathAlgorithm<int, Edge<int>>(g, e => 1);
dij.Compute(1);
Assert.AreEqual(0.0, dij.Distances[1]);
Assert.AreEqual(1.0, dij.Distances[2]);
Assert.AreEqual(1.0, dij.Distances[3]);
}
示例11: ComputeShortestPaths
public static FloydWarshallAllShortestPathAlgorithm<int, UndirectedEdge<int>> ComputeShortestPaths(Dictionary<int, Node> nodes, IEnumerable<Edge> edges)
{
var graph = new AdjacencyGraph<int, UndirectedEdge<int>>();
foreach (int nodeId in nodes.Keys)
{
graph.AddVertex(nodeId);
}
foreach (Edge edge in edges)
{
graph.AddEdge(new UndirectedEdge<int>(edge.StartNodeId, edge.EndNodeId));
graph.AddEdge(new UndirectedEdge<int>(edge.EndNodeId, edge.StartNodeId));
}
Func<UndirectedEdge<int>, double> edgeCost = e => GetEdgeCost(nodes, e);
var pathFinder = new FloydWarshallAllShortestPathAlgorithm<int, UndirectedEdge<int>>(graph, edgeCost);
pathFinder.Compute();
return pathFinder;
}
示例12: AddEdgeToBoth
//graph, tgraph, sourceNode, endNode, weight
public static void AddEdgeToBoth(AdjacencyGraph<string, Edge<string>> graph, AdjacencyGraph<string, Edge<string>> tGraph, Dictionary<Edge<string>, double> edgeCost, Dictionary<Edge<string>, double> tEdgeCost, string sourceString, string endString, int weight)
{
Edge<string> curEdge = new Edge<string>(sourceString, endString);
graph.AddEdge(curEdge);
edgeCost.Add(curEdge, weight);
Edge<string> transposeEdge = new Edge<string>(endString, sourceString);
tGraph.AddEdge(transposeEdge);
tEdgeCost.Add(transposeEdge, weight);
}
示例13: RunOnLineGraph
public void RunOnLineGraph()
{
AdjacencyGraph<int, Edge<int>> g = new AdjacencyGraph<int, Edge<int>>(true);
g.AddVertex(1);
g.AddVertex(2);
g.AddVertex(3);
g.AddEdge(new Edge<int>(1,2));
g.AddEdge(new Edge<int>(2,3));
Dictionary<Edge<int>,double> weights =
DijkstraShortestPathAlgorithm<int,Edge<int>>.UnaryWeightsFromEdgeList(g);
DijkstraShortestPathAlgorithm<int, Edge<int>> dij = new DijkstraShortestPathAlgorithm<int, Edge<int>>(g, weights);
dij.Compute(1);
Assert.AreEqual<double>(0, dij.Distances[1]);
Assert.AreEqual<double>(1, dij.Distances[2]);
Assert.AreEqual<double>(2, dij.Distances[3]);
}
示例14: RootIsNotAccessible
public void RootIsNotAccessible()
{
AdjacencyGraph<int, Edge<int>> g = new AdjacencyGraph<int, Edge<int>>(true);
g.AddVertex(0);
g.AddVertex(1);
g.AddEdge(new Edge<int>(0, 1));
target = new CyclePoppingRandomTreeAlgorithm<int, Edge<int>>(g);
target.RandomTreeWithRoot(0);
}
示例15: IncrementalConnectedComponent
public void IncrementalConnectedComponent()
{
var g = new AdjacencyGraph<int, SEquatableEdge<int>>();
g.AddVertexRange(new int[] { 0, 1, 2, 3 });
var components = AlgorithmExtensions.IncrementalConnectedComponents(g);
var current = components();
Assert.AreEqual(4, current.Key);
g.AddEdge(new SEquatableEdge<int>(0, 1));
current = components();
Assert.AreEqual(3, current.Key);
g.AddEdge(new SEquatableEdge<int>(2, 3));
current = components();
Assert.AreEqual(2, current.Key);
g.AddEdge(new SEquatableEdge<int>(1, 3));
current = components();
Assert.AreEqual(1, current.Key);
}