boost-graph

Weight map as function in Boost Graph Dijkstra algorithm

£可爱£侵袭症+ 提交于 2019-11-29 11:09: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) { return K*weight; } }; int main(int, char**){ typedef boost::adjacency_list < boost::vecS, boost::vecS, boost

How to print a graph in graphviz with multiple properties displayed

空扰寡人 提交于 2019-11-29 04:52:35
My question is based off of: How to print a graph with a single property displayed I am using bundled properties: typedef struct vert{ std::string name; }; typedef struct edge{ int capacity; int weight; }; typedef adjacency_list<listS, vecS, undirectedS, vert, edge> Graph; Graph g; vector<int,int> ele; I have the following called in a loop that should create the edges: edge prop; prop.weight = 5; prop.capacity = 4; add_edge(ele.first,ele.second, prop, g); This segment is what prints the graph to dot format. ofstream dot("graph.dot"); write_graphviz(dot, g, boost::make_label_writer(boost::get(

Dijkstra graph with a table of weights on each edge

一世执手 提交于 2019-11-28 21:59:50
I have a boost graph with multiples weights for each edges (imagine one set of weights per hour of the day). Every one of those weights values is stored in a propretyEdge class : class propretyEdge { std::map<std::string,double> weights; // Date indexed } I created a graph with those properties, and then filled it with the right values. The problem is now that I want to launch the Dijkstra algorithm over a particular set of weight on the graph : for example a function that could be : void Dijkstra (string date, parameters ... ) That would use the weights[date] value for each Edge of the graph.

boost minimum spanning tree, how to do depth first?

☆樱花仙子☆ 提交于 2019-11-28 11:45:05
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? Update : sehe gives an updated and more efficient solution here: https://stackoverflow.com/a/49429372/85371 Here is a solution to the problem and good example of Kruskal and writing a

BGL dijkstra_shortest_path algorithm method does not accept my color map exterior property

橙三吉。 提交于 2019-11-28 11:38:44
I have been trying to get boost graph lib's dijkstra_shortest_paths to compile for about a week now without avail. I am trying to use exterior property maps for the different named parameters required by the templated method. My graph uses bundled properties for the vertex and the edges and I have been able to build the graph successfully. I will show you what I have for the code: // vertex bundled properties struct BusStop { unsigned int id; //used for creating vertex index property map string name; Location* pLocation; }; // edge bundled properties: struct Route { string routeName; BusType

Modifying vertex properties in a Boost::Graph

…衆ロ難τιáo~ 提交于 2019-11-27 17:24:12
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. What about using bundled properties? using namespace boost; struct vertex_info { std::string whatever; int othervalue; std::vector<int> some_values; }; typedef adjacency_list<vecS, vecS, undirectedS, vertex_info> graph_t; graph_t g(n); g[0].whatever = "Vertex 0"; [...]

How to create a C++ Boost undirected graph and traverse it in depth first search (DFS) order?

隐身守侯 提交于 2019-11-27 07:06:10
How to create a C++ Boost undirected graph and traverse it in depth first search (DFS) order? // Boost DFS example on an undirected graph. // Create a sample graph, traverse its nodes // in DFS order and print out their values. #include <boost/graph/adjacency_list.hpp> #include <boost/graph/depth_first_search.hpp> #include <iostream> using namespace std; typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS> MyGraph; typedef boost::graph_traits<MyGraph>::vertex_descriptor MyVertex; class MyVisitor : public boost::default_dfs_visitor { public: void discover_vertex(MyVertex

BGL dijkstra_shortest_path algorithm method does not accept my color map exterior property

房东的猫 提交于 2019-11-27 06:21:53
问题 I have been trying to get boost graph lib's dijkstra_shortest_paths to compile for about a week now without avail. I am trying to use exterior property maps for the different named parameters required by the templated method. My graph uses bundled properties for the vertex and the edges and I have been able to build the graph successfully. I will show you what I have for the code: // vertex bundled properties struct BusStop { unsigned int id; //used for creating vertex index property map

How to create a C++ Boost undirected graph and traverse it in depth first search (DFS) order?

只谈情不闲聊 提交于 2019-11-26 17:37:08
问题 How to create a C++ Boost undirected graph and traverse it in depth first search (DFS) order? 回答1: // Boost DFS example on an undirected graph. // Create a sample graph, traverse its nodes // in DFS order and print out their values. #include <boost/graph/adjacency_list.hpp> #include <boost/graph/depth_first_search.hpp> #include <iostream> using namespace std; typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS> MyGraph; typedef boost::graph_traits<MyGraph>::vertex

how provide a vertex_index property for my graph

假装没事ソ 提交于 2019-11-26 12:31:55
问题 Since my graph use setS for vertex, I have to either provide a vertex_index property map for my graph, or give an explicit vertex_id argument to write_graphviz, to be able to use write_graphviz. My graph is defined as: typedef adjacency_list<setS, setS, undirectedS, NodeData, EdgeData> Graph; Where NodeData and EdgeData are structures. Can you please give me a very simple example of how to provide a vertex_index property map for my graph ? or how to give an explicit vertex_id argument to