boost-graph

boost minimum spanning tree, how to do depth first?

时光毁灭记忆、已成空白 提交于 2019-12-17 19:54:09
问题 I would like to construct a minimum spanning tree using the kruskal_minimum_spanning_tree algorithm available in the boost graph library. The output of the kruskal_minimum_spanning_tree(g, std::back_inserter(spanning_tree)); from the BGL example is a simple list of edges. However, I would like to process the tree with a depth first algorithm and do not know how to do that. Could someone give me a hint on this? 回答1: Update : sehe gives an updated and more efficient solution here: https:/

Modifying vertex properties in a Boost::Graph

一曲冷凌霜 提交于 2019-12-17 15:27:07
问题 I am trying to figure out how to use boost::graph to store some information. However, there is information I want tied to each vertex. Staring at the documentation for the library reveals either(a)badly written documentation, or (b), I'm obviously not as good at C++ as I thought. Pick two. I am looking for a simple example use. 回答1: What about using bundled properties? using namespace boost; struct vertex_info { std::string whatever; int othervalue; std::vector<int> some_values; }; typedef

Detect cycles in undirected graph using boost graph library

こ雲淡風輕ζ 提交于 2019-12-14 03:49:01
问题 I've been stuck since yesterday with this problem. Unfortunately/fortunately this problem makes only about 0.5% of the my super huge (for me, a c++ newbie) algorithm thus the need for a library of existing code that one can just adapt and get things working. I'll like to detect and give out all the circles in an undirected graph. My edges are not weighted. Yes, what I need is really all the cycles i.e. somthing like all the hamiltonian cycles of a directed graph I've been playing aroung with

Boost.Graph and Graphviz nested subgraphs

点点圈 提交于 2019-12-14 02:20:23
问题 I expected the code #include <boost/graph/graphviz.hpp> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/subgraph.hpp> #include <iostream> using namespace boost; using attrs_t = std::map<std::string, std::string>; using graph_t = adjacency_list< vecS, vecS, directedS, property<vertex_attribute_t, attrs_t>, property<edge_index_t, int, property<edge_attribute_t, attrs_t>>, property<graph_name_t, std::string, property<graph_graph_attribute_t, attrs_t, property<graph_vertex

What should be the return value of a custom function addEdge in a new class based on BGL?

五迷三道 提交于 2019-12-13 15:25:14
问题 I try to implement a graph class based on https://stackoverflow.com/a/950173/7558038. When adding an edge I return the edge descriptor of the added edge, but if the edge already exists, it shouldn't be added. What shall I return then? Unfortunately, null_edge() does not exist (unlike null_vertex() ). It could be an std::pair<e_it_t,bool> with an appropriate edge iterator type e_it_t , but how can I get an iterator to the new edge? 回答1: Don't use that class that is almost 10 years old. It is

Boost Graph initialize_vertex change vertex color (visitor)

不羁岁月 提交于 2019-12-13 07:10:34
问题 I would like to build a visitor (for dikstra) with the initialise_vertex acting as 'colour map' modifier. I want to exclude some vertices from the search based on a condition. So I want to set some vertices 'black' in the init part of the algorithm. class dijkstra_2step : public boost::default_dijkstra_visitor { public: dijkstra_2step(std::vector<Weight> dists, double threshold): distances(dists), threshold(threshold) {} // THIS PART IS NOT CORRECT!!!! // void initialize_vertex(boost::graph

Yet another BGL's Betweenness centrality issue

青春壹個敷衍的年華 提交于 2019-12-13 00:54:15
问题 Drawing on this reply, I've tried to implement the Betweenness centrality as follows: typedef struct vpr_ { int id; } VProp; typedef boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, VProp, EProp> graph_t; boost::shared_array_property_map<double, boost::property_map<graph_t, int>::const_type> centrality_map(num_vertices(g), get(VProp::id, g)); But the following error was returned. In file included from /usr/local/include/boost/graph/adjacency_list.hpp:246:0, from /usr

Using boost connected components with cartesian points

邮差的信 提交于 2019-12-12 23:26:29
问题 I found http://www.boost.org/doc/libs/1_49_0/libs/graph/example/incremental_components.cpp and want to check if it will work for me. How to convert this example to cope with cartesian points with (x,y) or (x,y,z). I can't find such example in documentation of boost. I see that i must redefine vertice in some way, so change in adjacency_list is needed. Tried to change vecS with Point definifion, but i think also some changes in add_edge functions are needed. 回答1: I made a couple minor changes

boost::graph compilation issue with dynamic_properties and write_graphviz

心不动则不痛 提交于 2019-12-12 19:41:59
问题 This question is about boost::graph and how to handle properties associated to vertices (and/or edges). I am quite confused about handling this, but I suspect it could be a template-related issue. Let's say I have this graph definition: struct myVertex_t { int color; }; typedef boost::adjacency_list< boost::vecS, // edge container boost::vecS, // vertex container boost::undirectedS, // type of graph myVertex_t, // vertex properties boost::property< // edge properties boost::edge_color_t, // ?

Boost dijkstra string edge weight

孤街醉人 提交于 2019-12-12 18:43:53
问题 is it possible to use string value instead of double properties typedef adjacency_list < vecS, vecS, directedS, property<vertex_name_t, string>, property < edge_weight_t, string> > Graph; My goal is to use the dijkstra algorithm. PS: I already tried replacing the double with string and it generates an error within the algorithm. std::vector<vertexd> P(num_vertices(g)); std::vector<string> d(num_vertices(g)); vertexd s = vertex(0, g); dijkstra_shortest_paths(g, s, predecessor_map(boost::make