boost-graph

How to calculate betweenness using boostlib for adjacency list?

孤人 提交于 2019-12-04 02:38:31
问题 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

Use a Graph Library/Node Network Library or Write My Own?

给你一囗甜甜゛ 提交于 2019-12-03 18:30:21
问题 I'm trying to decide between going with a pre-made graph/node network library or to roll my own. I'm implementing some graph search algorithms which might require some significant customization to the class structure of the node and/or edges. The reason I'm not sure what to do is that I'm unsure if customization of a pre-made might be more expensive/trouble than making my own in the first place. I'm also curious, but less so, of the performance trade-offs. Is there anyone out there have

Modifying bundled properties from visitor

孤人 提交于 2019-12-03 15:51:47
How should I modify the bundled properties of a vertex from inside a visitor? I would like to use the simple method of sub-scripting the graph, but the graph parameter passed into the visitor is const, so compiler disallows changes. I can store a reference to the graph in the visitor, but this seems weird. /** A visitor which identifies vertices as leafs or trees */ class bfs_vis_leaf_finder:public default_bfs_visitor { public: /** Constructor @param[in] total reference to int variable to store total number of leaves @param[in] g reference to graph ( used to modify bundled properties ) */ bfs

Boost dijkstra shortest_path - how can you get the shortest path and not just the distance?

柔情痞子 提交于 2019-12-03 13:15:30
I have a need to use the Boost library to get the shortest path from one point to another. I've looked over the example code and it is decently easy to follow. However, the example only shows how to get the overall distances. I'm trying to figure out how to iterate over the predecessor map to actually get the shortest path and I can't seem to figure it out. I've read these two questions on the subject: Dijkstra Shortest Path with VertexList = ListS in boost graph Boost:: Dijkstra Shortest Path, how to get vertice index from path iterator? But in both of the examples provided, the IndexMap

Iterating over edges of a graph using range-based for

回眸只為那壹抹淺笑 提交于 2019-12-03 12:26:35
I have a representation of a graph as a std::vector<std::unordered_set<unsigned>> neighbors , that is, vertices are integers, and for each vertex we keep a set of its neighbors. Thus, to walk all edges, I would do something like for (unsigned u = 0; u < neighbors.size(); ++u) for (unsigned v : neighbors[u]) if (u <= v) std::cout << u << ' ' << v << std::endl; Now, I would like to be able to get the same effect from for (auto e: g.edges()) std::cout << e.first << ' ' << e.second << std::endl; where g is from a class encapsulating the neighbors vector. However, everything I tried seems extremely

How to fit a custom graph to the boost graph library template?

可紊 提交于 2019-12-03 12:21:00
问题 I'm rusty on C++ templates and I'm using the boost graph library (a fatal combination). I've searched the web and can't find any direct instructions on how to take a custom graph structure and fit enough of it to BGL (boost graph library) that I can use boosts graph traversing algorithms. Anyone familiar enough with the library to help me out? EDIT: So, the main problem I've been having is where to find a source where the total requirements to map an arbitrary graph to a BGL graph. I'm really

How to fit a custom graph to the boost graph library template?

亡梦爱人 提交于 2019-12-03 03:43:39
I'm rusty on C++ templates and I'm using the boost graph library (a fatal combination). I've searched the web and can't find any direct instructions on how to take a custom graph structure and fit enough of it to BGL (boost graph library) that I can use boosts graph traversing algorithms. Anyone familiar enough with the library to help me out? EDIT: So, the main problem I've been having is where to find a source where the total requirements to map an arbitrary graph to a BGL graph. I'm really new to templates so it's hard for me to read BGL's specification/examples. Maybe I should look for a

What is a property map in BOOST?

冷暖自知 提交于 2019-12-02 19:36:13
Can someone explain to a Boost beginner like me what is a property map is in Boost? I came across this when trying to use the BGL for calculating strong connected components. I went throw the documentation for the property map and graph module and still don't know what to make of it. Take this code, for example: - what is the make_iterator_property_map function doing? - and what is the meaning of this code: get(vertex_index, G) ? #include <boost/config.hpp> #include <vector> #include <iostream> #include <boost/graph/strong_components.hpp> #include <boost/graph/adjacency_list.hpp> int main() {

Recording predecessors in a DFS search in an undirected graph

笑着哭i 提交于 2019-12-02 18:04:41
问题 I was trying to use the code from this thread: Boost DFS back_edge, to record the cycles in an undirected graph. To do this I need to store the predecessors for each dfs tree when it finds a back_edge. Since this is an undirected graph I think we can not use directly on_back_edge() from EventVisitor Concept. So I was thinking to record the predecessors in the void back_edge() method of below code. But I am not sure how to do this and return the cycle vertices. Here is the code and the part I

boost::associative_property_map() compile error

寵の児 提交于 2019-12-02 17:45:35
问题 using this link on boost website, I am able to compile the code here. and even get the answer (example). But when I do the same by defining in a class, I get the error as follows: #include < as usual in the code > class Test{ std::map<std::string, std::string> name2address; boost::const_associative_property_map< std::map<std::string, std::string> > address_map(name2address); }; error is as follows: error: ‘name2address’ is not a type I have to use typedef and typename as follows to compile