如果我有用CElement类定义的n个元素,如何用boost图创建这些元素的顶点并将它们连接起来? 我看过boost图形捆绑道具,但我无法弄清楚这一点。将自定义顶点添加到提升图
16
A
回答
50
我不明白你想要做什么。你想把一些数据关联到顶点吗?然后使用捆绑的属性。
//Define a class that has the data you want to associate to every vertex and edge
struct Vertex{ int foo;}
struct Edge{std::string blah;}
//Define the graph using those classes
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, Vertex, Edge > Graph;
//Some typedefs for simplicity
typedef boost::graph_traits<Graph>::vertex_descriptor vertex_t;
typedef boost::graph_traits<Graph>::edge_descriptor edge_t;
//Instanciate a graph
Graph g;
// Create two vertices in that graph
vertex_t u = boost::add_vertex(g);
vertex_t v = boost::add_vertex(g);
// Create an edge conecting those two vertices
edge_t e; bool b;
boost::tie(e,b) = boost::add_edge(u,v,g);
// Set the properties of a vertex and the edge
g[u].foo = 42;
g[e].blah = "Hello world";
其他的方法来设置属性,但你有一个引导示例。
我希望我没有误解这个问题。
相关问题
- 1. 添加自定义顶点:INPUTFILE图标/图像
- 2. 如何将自定义顶点标签添加到R中的ggnet图形?
- 3. 将自定义属性添加到Boost图库中的网格顶点
- 4. 将视图添加到自定义ViewGroup
- 5. 将图像添加到自定义baseadapter
- 6. 将图像添加到自定义AlertDialog
- 7. 将edittext添加到自定义视图
- 8. 将editText添加到自定义视图
- 9. Magento - 将自定义模块添加到Google站点地图
- 10. 将自定义图像添加到节点
- 11. 将子节点添加到XML结构的顶部。提升属性树
- 12. 将jqGrid自定义导航添加到顶部工具栏
- 13. 将自定义视图绑定到点
- 14. 将自定义视图附加到Android键盘的顶部
- 15. 将自定义标签添加到堆积条形图的顶部或底部
- 16. 如何将自定义图标添加到JqGrid顶级工具栏按钮?
- 17. 如何在顶点Salesforce页面添加自定义TextInput字段?
- 18. 将自定义属性添加到Serilog
- 19. 将自定义控件添加到DataGridViewCell
- 20. 将KeyListener添加到自定义对象
- 21. 将自定义按钮添加到SlickGrid?
- 22. 将自定义Cookie添加到Wordpress
- 23. 将语音添加到自定义UIMenuController
- 24. 将自定义事件添加到Object3D
- 25. 将自定义对象添加到NSMutableArray
- 26. 将UIImageView添加到自定义UITableView Cell
- 27. 将UITextField添加到自定义TableViewCell
- 28. 将自定义行添加到GridView表
- 29. 将自定义属性添加到UserControl
- 30. 将自定义设置添加到PreferenceFragment
抱歉不清楚。 CElements的实例是顶点。我希望能够添加,删除,连接和断开CElements的这些实例。我真的需要定义具有pt到CElement实例的struct Vertex,还是有更优雅的方法? – dodol 2010-06-23 09:04:44