boost-graph

adjacency_list with VertexList different from vecS

强颜欢笑 提交于 2019-12-01 23:38:01
I have two structs containing some fields: struct MyNodeData, and struct MyEdgeData. When I create a graph with VertexList as vecS, there is no problem to access the descriptor of vertices etc. For example: typedef adjacency_list<setS, vecS, undirectedS, MyNodeData, MyEdgeData> Graph; typedef Graph::vertex_descriptor MyNodeDataID; typedef Graph::edge_descriptor MyEdgeDataID; typedef graph_traits < Graph >::vertex_iterator VertexIterator; typedef graph_traits < Graph >::edge_iterator EdgeIterator; typedef graph_traits < Graph >::adjacency_iterator AdjacencyIterator; typedef property_map < Graph

Get node label from boost::labeled_graph

廉价感情. 提交于 2019-12-01 22:43:18
问题 I would like to retrieve the label of a labeled node in BGL's labeled_graph but cannot find a method to do this. The following MWE demonstrates what I am looking for: //g++ -O3 question.cpp -o question.exe -I. --std=c++11 -lprotobuf-lite -lpthread -lz -losmpbf #include <iostream> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/labeled_graph.hpp> #include <boost/graph/iteration_macros.hpp> typedef long long node_id_t; typedef boost::adjacency_list< boost::listS, // Store out

Adding custom properties to vertex of a grid in Boost Graph Library

醉酒当歌 提交于 2019-12-01 21:52:24
I am using Boost Graph Library for map management in my robotics project. I intend to use Boost Grid and I am finding the Boost Graph documentation really hard to understand so I need a little help. This is the way I have created the grid, and printing it : struct sampleVertex { int row; int col; bool occupied; }; boost::array<std::size_t, 2> lengths = { { 3, 2 } }; boost::grid_graph<2> gridD(lengths); boost::write_graphviz(fout, gridD); Now, I want to add custom properties to the vertices, as defined as a struct - 'sampleVertex'. Please show me some code snippet or example to do this. I am

boost graph library directed multigraph edge_range bug

对着背影说爱祢 提交于 2019-12-01 21:15:52
I have a directed multigraph with vertices A..C and edges E1..E4 A ---E1--> B A ---E2--> B A ---E3--> B B ---E4--> C I wanted to iterate over the edges that connect A and B. In BGL, I expressed this as: #include <boost/graph/adjacency_list.hpp> struct Vertex { std::string code; }; struct Edge { double distance; std::string code; }; int main() { using namespace boost; typedef adjacency_list<listS, vecS, directedS, Vertex, Edge> Graph; Graph g; auto a= add_vertex(Vertex{ "A" }, g); auto b= add_vertex(Vertex{ "B" }, g); auto c= add_vertex(Vertex{ "C" }, g); add_edge(a, b, Edge{ 10, "E1" }, g);

Get node label from boost::labeled_graph

坚强是说给别人听的谎言 提交于 2019-12-01 18:31:00
I would like to retrieve the label of a labeled node in BGL's labeled_graph but cannot find a method to do this. The following MWE demonstrates what I am looking for: //g++ -O3 question.cpp -o question.exe -I. --std=c++11 -lprotobuf-lite -lpthread -lz -losmpbf #include <iostream> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/labeled_graph.hpp> #include <boost/graph/iteration_macros.hpp> typedef long long node_id_t; typedef boost::adjacency_list< boost::listS, // Store out-edges of each vertex in a std::list boost::listS, // Store vertex set in a std::list boost:

boost graph library - minimal example of vertex colors and graphviz output

流过昼夜 提交于 2019-12-01 17:42:21
Being new to the boost graph library, I find it's often difficult to tease out what pieces of the examples are tied to the particular example and which parts are universal to usage. As an exercise, I'm trying to make a simple graph, assign a color property to the vertices, and output the result to graphviz so colors appear as color attributes that get rendered. Any help would be appreciated! Here's what I have so far (more specific usage questions are in the comments here): #include "fstream" #include "boost/graph/graphviz.hpp" #include "boost/graph/adjacency_list.hpp" struct vertex_info { int

Adding a vertex_index to listS graph on the fly for betweenness centrality

久未见 提交于 2019-12-01 15:15:46
Update : The issue may be in the betweenness code. If I comment out the call to brandes_betweenness_centrality the code will compile. the problem may not be the index set up as previously thought. I'll award bounty if you can come up with an alternative call to brandes_betweenness_centrality that will allow keeping the index external. I'm trying to convert some of my old vecS code to work with listS, specifically the brandes_betweenness_centrality algorithm. I'm trying to keep the Vertex and Edge properties very light weight and work mainly with external properties. The reason for this is that

How to calculate betweenness using boostlib for adjacency list?

余生长醉 提交于 2019-12-01 13:55:23
I'm trying to write a simple program to calculate betweeness using brandes_betweenness_centrality from boostlib. I got stuck at getting an output (CentralityMap). I've been reading the documentation but I can't figure out how to put it all together. Here is my simple code: #include <iostream> // std::cout #include <utility> // std::pair #include <boost/graph/graph_traits.hpp> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/betweenness_centrality.hpp> using namespace boost; int main() { int nVertices = 100; srand ( time(NULL) ); typedef std::pair<int, int> Edge; std::vector<Edge

Using boost graph library with a custom class for vertices

我与影子孤独终老i 提交于 2019-12-01 08:15:06
I am currently trying to use the boost graph library in an existing c++ project. I would like to store objects of a custom class in a boost graph. Below is a small example with a custom class definition with two members (a string and an int) and their corresponding getter methods. I have a few questions: How can I include the string and int value in the Graphviz output? I found this answer to a similar question using boost::make_label_writer but I not really sure if my example can be adopted to this (I am using a custom class and shared pointers). It should not be possible to store an

On C++ Boost Graph Creation and the vertex_index Property.

风流意气都作罢 提交于 2019-12-01 06:18:41
I am boost noob. I am wondering why compilation fails in the following code. I am creating a set of vertices, and trying to assign my own vertex indices and vertex names. (I am following this page: http://fireflyblue.blogspot.com/2008/01/boost-graph-library.html . ) I understand that vertS vertex lists in Boost does not need explicit vertex id creations, and I have also seen this very related question in Stackoverflow ( how provide a vertex_index property for my graph ) which discusses how to use an associative_property_map to assign vertex indices. The following though - getting the vertex