本文整理汇总了C#中AdjacencyGraph.AddVertex方法的典型用法代码示例。如果您正苦于以下问题:C# AdjacencyGraph.AddVertex方法的具体用法?C# AdjacencyGraph.AddVertex怎么用?C# AdjacencyGraph.AddVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdjacencyGraph
的用法示例。
在下文中一共展示了AdjacencyGraph.AddVertex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
Dictionary<Edge<int>, double> weights =
DijkstraShortestPathAlgorithm<int, Edge<int>>.UnaryWeightsFromEdgeList(g);
DijkstraShortestPathAlgorithm<int, Edge<int>> dij = new DijkstraShortestPathAlgorithm<int, Edge<int>>(g, weights);
VertexPredecessorRecorderObserver<int, Edge<int>> vis = new VertexPredecessorRecorderObserver<int, Edge<int>>();
vis.Attach(dij);
dij.Compute(1);
IList<Edge<int>> col = vis.Path(2);
Assert.AreEqual(1, col.Count);
Assert.AreEqual(e12, col[0]);
col = vis.Path(3);
Assert.AreEqual(2, col.Count);
Assert.AreEqual(e12, col[0]);
Assert.AreEqual(e23, col[1]);
}
示例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: 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();
}
示例4: IsolatedVerticesWithRoot
public void IsolatedVerticesWithRoot()
{
var g = new AdjacencyGraph<int, Edge<int>>(true);
g.AddVertex(0);
g.AddVertex(1);
var target = new CyclePoppingRandomTreeAlgorithm<int, Edge<int>>(g);
target.RandomTreeWithRoot(0);
}
示例5: 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);
}
示例6: TwoVertex
public void TwoVertex()
{
AdjacencyGraph<string, Edge<string>> g = new AdjacencyGraph<string, Edge<string>>(true);
g.AddVertex("v1");
g.AddVertex("v2");
StronglyConnectedComponentsAlgorithm<string, Edge<String>> strong = new StronglyConnectedComponentsAlgorithm<string, Edge<String>>(g);
strong.Compute();
Assert.AreEqual(2, strong.ComponentCount);
checkStrong(strong);
}
示例7: GenerateGraph
public static AdjacencyGraph<string, Edge<string>> GenerateGraph(IEnumerable<AssemblyInfo> assemblies, bool skipGacAssemblies = true)
{
// Detect all the GAC assemblies
var gacAssemblies = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
if (skipGacAssemblies)
{
foreach (var info in assemblies)
{
if (info.IsInGac)
gacAssemblies.Add(info.FullName);
}
}
var graph = new AdjacencyGraph<string, Edge<string>>();
var verticesOnGraph = new HashSet<string>();
foreach (var parent in assemblies)
{
string parentName = parent.FullName;
// Skip GAC assemblies
if (gacAssemblies.Contains(parentName))
continue;
if (!verticesOnGraph.Contains(parentName))
{
graph.AddVertex(parent.Name);
verticesOnGraph.Add(parentName);
}
foreach (var child in parent.Children)
{
string childName = child.FullName;
if (gacAssemblies.Contains(childName))
continue;
if (!verticesOnGraph.Contains(childName))
{
graph.AddVertex(child.Name);
verticesOnGraph.Add(childName);
}
// TODO: reduce two-way edges. This may happen in a rare case of circular dependency.
graph.AddEdge(new Edge<string>(parent.Name, child.Name));
}
}
return graph;
}
示例8: 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;
}
示例9: 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));
}
示例10: 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);
}
示例11: 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
}
}
示例12: CreateGraphOfPipeSystem
private static IVertexAndEdgeListGraph<PipeGraphVertex, Edge<PipeGraphVertex>> CreateGraphOfPipeSystem(PipeGraphVertex firstVertex)
{
var graph = new AdjacencyGraph<PipeGraphVertex, Edge<PipeGraphVertex>>(false);
var verticesSeen = new HashSet<PipeGraphVertex>();
var verticesToCheck = new Stack<PipeGraphVertex>();
verticesToCheck.Push(firstVertex);
while (verticesToCheck.Any())
{
var vertexToCheck = verticesToCheck.Pop();
if (verticesSeen.Contains(vertexToCheck)) continue;
var sendsTo = GetVerticesYouSendMessagesTo(vertexToCheck);
var receivesFrom = GetVerticesYouReceiveMessagesFrom(vertexToCheck);
foreach (var vertex in sendsTo) verticesToCheck.Push(vertex);
foreach (var vertex in receivesFrom) verticesToCheck.Push(vertex);
graph.AddVertex(vertexToCheck);
graph.AddVerticesAndEdgeRange(sendsTo.Select(v => new Edge<PipeGraphVertex>(vertexToCheck, v)));
graph.AddVerticesAndEdgeRange(receivesFrom.Select(v => new Edge<PipeGraphVertex>(v, vertexToCheck)));
verticesSeen.Add(vertexToCheck);
}
return graph;
}
示例13: CreateGraphFromNode
private AdjacencyGraph<Node, Edge<Node>> CreateGraphFromNode(XDocument xDocument, XNode parent)
{
var graph = new AdjacencyGraph<Node, Edge<Node>>();
var nodes = xDocument.Descendants().Where(x => x.Parent != null && (x.Parent.Parent != null && (x.Parent != null && x.Parent.Parent.Parent == parent)));
var fromList = nodes.Where(x => x.Parent != null && (x.Name.LocalName == "ControlFlow" && x.Parent.Name.LocalName =="FromSimpleRelationships") );
var toList = nodes.Where(x => x.Parent != null && (x.Name.LocalName == "ControlFlow" && x.Parent.Name.LocalName =="ToSimpleRelationships") );
foreach (var fromNode in fromList)
{
var xNode1 = fromNode.Parent.Parent;
string idref = fromNode.Attribute("Idref").Value;
var xNode2 =
toList.Where(x => x.Parent != null && (x.Attribute("Idref").Value.ToString() == idref))
.Select(x => x.Parent.Parent).FirstOrDefault();
if (xNode1 == null || xNode2 == null)
continue;
Node node1 = new Node(xNode1.Attribute("Name").Value, GetNodeType(xNode1));
Node node2 = new Node(xNode2.Attribute("Name").Value, GetNodeType(xNode2));
if (!graph.Vertices.Any(x => x.Name==node1.Name && x.Type==node1.Type))
{
graph.AddVertex(node1);
}
else
{
node1 = graph.Vertices.FirstOrDefault(x => x.Name == node1.Name && x.Type == node1.Type);
}
if (!graph.Vertices.Any(x => x.Name == node2.Name && x.Type == node2.Type))
{
graph.AddVertex(node2);
}
else
{
node2 = graph.Vertices.FirstOrDefault(x => x.Name == node2.Name && x.Type == node2.Type);
}
var newEdge = new Edge<Node>(node1, node2);
if(!graph.ContainsEdge(newEdge))
graph.AddEdge(newEdge);
}
return graph;
}
示例14: IsolatedVertex
public void IsolatedVertex()
{
AdjacencyGraph<int, Edge<int>> g = new AdjacencyGraph<int, Edge<int>>(true);
g.AddVertex(0);
target = new CyclePoppingRandomTreeAlgorithm<int, Edge<int>>(g);
target.RandomTree();
}
示例15: 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]);
}