1 | #include <boost/config.hpp>
|
---|
2 | #include <boost/graph/adjacency_list.hpp>
|
---|
3 | #include <boost/graph/adjacency_matrix.hpp>
|
---|
4 | #include <boost/graph/graph_utility.hpp>
|
---|
5 | #include <iostream>
|
---|
6 |
|
---|
7 | int main () {
|
---|
8 | using namespace boost;
|
---|
9 |
|
---|
10 | // To get compiler errors, comment out the next line; and remove the comment of the next, next line
|
---|
11 | typedef adjacency_list < vecS, vecS, undirectedS, no_property, property < edge_weight_t, int > > Graph;
|
---|
12 | // typedef adjacency_matrix < undirectedS, no_property, property < edge_weight_t, int > > Graph;
|
---|
13 |
|
---|
14 | typedef graph_traits < Graph >::edge_descriptor Edge;
|
---|
15 | typedef graph_traits < Graph >::vertex_descriptor Vertex;
|
---|
16 | typedef std::pair<int, int> E;
|
---|
17 | typedef int weight_t;
|
---|
18 | typedef property<edge_weight_t,weight_t> EProperty;
|
---|
19 |
|
---|
20 | const int num_nodes = 5;
|
---|
21 | E edges[] = { E(0, 2), E(1, 3), E(1, 4), E(2, 1), E(2, 3), E(3, 4), E(4, 0) };
|
---|
22 | int weights[] = { 1, 1, 2, 7, 3, 1, 1 };
|
---|
23 | std::size_t num_edges = sizeof(edges) / sizeof(E);
|
---|
24 |
|
---|
25 | Graph g1 (num_nodes);
|
---|
26 | boost::property_map<Graph, vertex_index_t>::type vertex_id = get(vertex_index, g1);
|
---|
27 | for (unsigned int i = 0; i < num_edges; i++) {
|
---|
28 | add_edge (edges[i].first, edges[i].second, weights[i], g1);
|
---|
29 | }
|
---|
30 | print_graph (g1);
|
---|
31 |
|
---|
32 | Graph g2 (&edges[0], edges + num_nodes, weights, num_nodes);
|
---|
33 | print_graph (g2);
|
---|
34 |
|
---|
35 | return EXIT_SUCCESS;
|
---|
36 | }
|
---|