Created
September 11, 2015 06:44
-
-
Save Zia-/13b66a342698783688c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/graph/adjacency_list.hpp> | |
template <typename DirectedGraph> | |
void directed_graph_demo(){ | |
/*The value of V is not imp, we need it just to pass into constructor at "UndirectedGraph undigraph(V);" to initialize it. | |
Later on we can add as many vertices as we want*/ | |
const int V = 0; | |
DirectedGraph digraph(V); | |
typename boost::graph_traits<DirectedGraph>::vertex_descriptor u, v; | |
//edge_property_type Weight will be used to pass weight values for each edge | |
typedef typename DirectedGraph::edge_property_type Weight; | |
//This weight obj will be used to extract the weight values for each edge later on | |
typename boost::property_map<DirectedGraph, boost::edge_weight_t>::type weight = get(boost::edge_weight, digraph); | |
typename boost::graph_traits<DirectedGraph>::edge_descriptor e1, e2; | |
bool found; | |
u = vertex(0, digraph); | |
v = vertex(1, digraph); | |
add_edge(u, v, Weight(1.2), digraph); | |
add_edge(v, u, Weight(2.4), digraph); | |
tie(e1, found) = edge(u, v, digraph); | |
tie(e2, found) = edge(v, u, digraph); | |
//Following "std::boolalpha << (e1==e2)" will compare the two edges are return a boolean type instead | |
std::cout<< std::boolalpha << (e1==e2) << std::endl; | |
std::cout<< get(weight, e1) << std::endl; | |
std::cout<< get(weight, e2) << std::endl; | |
} | |
int main(){ | |
//Here we are making a property obj. | |
typedef boost::property < boost::edge_weight_t, double >Weight; | |
//Passing above defined property obj into adjacency_list as edge's weight | |
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, | |
boost::no_property, Weight> DirectedGraph; | |
directed_graph_demo<DirectedGraph>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment