Skip to content

Instantly share code, notes, and snippets.

@daviddoria
Created November 9, 2016 02:53
Show Gist options
  • Save daviddoria/3a95428c85057c2b404ef9193083a6c3 to your computer and use it in GitHub Desktop.
Save daviddoria/3a95428c85057c2b404ef9193083a6c3 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
typedef boost::property<boost::edge_weight_t, double> EdgeWeightProperty;
/*
adjacency_list<OutEdgeList, VertexList, Directed,
VertexProperties, EdgeProperties,
GraphProperties, EdgeList>
*/
typedef boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS, boost::no_property, EdgeWeightProperty> Graph;
int main(int,char*[])
{
// Create a graph object
Graph g(3);
std::cout << num_edges(g) << std::endl; // outputs 0
EdgeWeightProperty e1 = 5;
add_edge(0, 1, e1, g);
std::cout << num_edges(g) << std::endl; // outputs 1
EdgeWeightProperty e2 = 3;
add_edge(1, 2, e2, g);
std::cout << num_edges(g) << std::endl; // outputs 2
EdgeWeightProperty e2b = 3;
add_edge(1, 2, e2b, g);
std::cout << num_edges(g) << std::endl; // outputs 2
EdgeWeightProperty e2c = 3;
add_edge(2, 1, e2c, g);
std::cout << num_edges(g) << std::endl; // outputs 2
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment