boost-graph

Iterating over edges of a graph using range-based for

試著忘記壹切 提交于 2019-12-21 03:51:07
问题 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;

What is a property map in BOOST?

北慕城南 提交于 2019-12-20 09:47:12
问题 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

edge_index zero for all edges?

瘦欲@ 提交于 2019-12-20 03:06:13
问题 Defining my boost::graph like the following, I get edge indices zero for all edges. Why? What am I doing wrong? #include <iostream> #include <boost/graph/adjacency_list.hpp> int main() { typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::no_property, boost::property<boost::edge_index_t, std::size_t> > Graph; typedef boost::graph_traits<Graph>::edge_descriptor Edge; Graph g(3); Edge e1 = boost::add_edge(0, 1, g).first; Edge e2 = boost::add_edge(1, 2, g).first;

Using boost graph library with a custom class for vertices

China☆狼群 提交于 2019-12-19 09:45:05
问题 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

how to write GraphViz subgraphs with boost::write_graphviz

自作多情 提交于 2019-12-19 07:56:09
问题 Is it possible to generate a DOT subgraph using ::boost::write_graphviz ? For instance, if I create a subgraph G0 in a graph G, can I get something like the following in the DOT output: graph G { subgraph G0 { ... } ... } 回答1: I finally figured out both how subgraphs work and how to use boost::write_graphviz to actually print these. The first requirement is "semi-documented" in a comment in the boost library source code: requires graph_name property . The most surprising requirement however

Boost graph list or vec

为君一笑 提交于 2019-12-19 03:21:16
问题 I've been spending quite a few days working with the boost graph library. As far as I understand, when considering VertexList and EdgeList storage : vecS : possess an index, so can be access with it when removing vertices, iterator are invalidated listS : no index does not invalidate iterator It's a bit short but that's to the point for my problem. I need those index number and I want to be able to easily remove vertices later on. I have a working algorithm with this graph structure : typedef

copy_graph - adjacency_list with bundled properties

浪子不回头ぞ 提交于 2019-12-18 09:16:13
问题 Here is a complete snippet to copy a graph with bundled properties, but results in bunch of compiler errors. What is needed to fix the problems? struct NodeInfo1 {}; struct EdgeInfo1 {}; typedef boost::labeled_graph< boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, NodeInfo1, EdgeInfo1>, std::string> Graph1; typedef std::pair<boost::graph_traits<Graph>::edge_descriptor, bool> Edge; void TestCases::TestCopyGraph() { Graph1 grid, g1; EdgeInfo1 ei; Edge e = add_edge_by_label(

Boost Graph accessing properties through vertex_descriptor

笑着哭i 提交于 2019-12-18 09:11:02
问题 I have my custom vertex and edge properties namespace boost { enum vertex_diagonal_t{vertex_diagonal = 999}; BOOST_INSTALL_PROPERTY(vertex, diagonal); } namespace boost { enum edge_dominance_t{edge_dominance = 998}; BOOST_INSTALL_PROPERTY(edge, dominance); } I create my adjacency list with boost::property typedef boost::adjacency_list< boost::listS, boost::vecS, boost::bidirectionalS, boost::property<boost::vertex_diagonal_t, const khut::diagonal*>, boost::property<boost::edge_dominance_t,

Weight map as function in Boost Graph Dijkstra algorithm

眉间皱痕 提交于 2019-12-18 06:53:58
问题 I'm using Boost Graph Libraries and need to use a weightmap which is not constant, but which is a function of a parameter K (i.e. the edge costs depend on K). In practice, given the following code: #include <boost/config.hpp> #include <iostream> #include <fstream> #include <boost/graph/graph_traits.hpp> #include <boost/graph/dijkstra_shortest_paths.hpp> #include <boost/graph/adjacency_list.hpp> struct Edge { Edge(float weight_) : weight(weight_) {} float weight; float getWeight(int K) {

Weight map as function in Boost Graph Dijkstra algorithm

旧时模样 提交于 2019-12-18 06:52:12
问题 I'm using Boost Graph Libraries and need to use a weightmap which is not constant, but which is a function of a parameter K (i.e. the edge costs depend on K). In practice, given the following code: #include <boost/config.hpp> #include <iostream> #include <fstream> #include <boost/graph/graph_traits.hpp> #include <boost/graph/dijkstra_shortest_paths.hpp> #include <boost/graph/adjacency_list.hpp> struct Edge { Edge(float weight_) : weight(weight_) {} float weight; float getWeight(int K) {