c# - 快速图中的无向图表示

标签 c# c++ boost boost-graph quickgraph

我正在使用 QuickGraph .NET library这是 boost (C++) 图形库的克隆,但我有几个问题,因为我是这个库的新手 1- 我如何在 QucikGraph 中表示无向图?我发现您可以使用以下方法在 boost 中轻松做到这一点: adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> Graph; 2- 我将如何为顶点赋值我有兴趣将整数值附加到顶点,但我无法弄清楚如何执行此操作:

AdjacencyGraph graph = new AdjacencyGraph(new VertexAndEdgeProvider(), false);//I'm not sure about the proper value of this boolean 
IVertex u = graph.AddVertex();// here I'm adding vertex to 'graph' but with no value 
IVertex v = graph.AddVertex();// here also I'm doing the same thing but without assigning any value to vertex v
graph.AddEdge(u, v);

最佳答案

这是如何去做的:假设你的顶点 vertex1vertex2T 类型,你应该使用下面的代码(注意:命名空间将使用 QuickGraph;):

AdjacencyGraph<T, Edge<T>> newGraphInstance = new AdjacencyGraph<int, Edge<int>>();
newGraphInstance.AddVerticesAndEdge(new Edge<T>(vertex1, vertex2));

这将同时添加顶点和相应的边。

关于c# - 快速图中的无向图表示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28740154/

相关文章:

c++ - __cplusplus < 201402L 在 gcc 中返回真,即使我指定了 -std=c++14

c++ - ublas::vector push_back 在哪里?

c++ - 用于创建混合类的 MPL 工厂方法

python - boost python - 提取ndarray时nullptr

javascript - 如何创建函数以在后端验证下拉列表

c++ - CGAL 二次规划包找到不正确的解决方案

c# - 在 Windows Phone 8.1 中使用什么进行 Paypal 付款

c++ - 在派生类中可见的私有(private) typedef

c# - 我们是否能够从应用程序在 Linux Ubuntu for windows 中安装 Microsoft Visual Studio(不是 Visual Studio 代码)?

c# - 在c# Visual Studio中的一个连接中创建多个mysql命令&where子句中的未知列