| 1 | //======================================================================= |
|---|
| 2 | // Copyright 1997, 1998, 1999, 2000 University of Notre Dame. |
|---|
| 3 | // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek |
|---|
| 4 | // |
|---|
| 5 | // Distributed under the Boost Software License, Version 1.0. (See |
|---|
| 6 | // accompanying file LICENSE_1_0.txt or copy at |
|---|
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 8 | //======================================================================= |
|---|
| 9 | // |
|---|
| 10 | // This example is similar to the one in edge_property.cpp. |
|---|
| 11 | // The only difference is that this example uses exterior |
|---|
| 12 | // property storage instead of interior (properties). |
|---|
| 13 | // |
|---|
| 14 | // Sample output: |
|---|
| 15 | // |
|---|
| 16 | // 0 --(10, 8)--> 1 |
|---|
| 17 | // |
|---|
| 18 | // 1 --(20, 12)--> 4 --(40, 12)--> 3 |
|---|
| 19 | // <--(10,8)-- 0 <--(20,16)-- 2 |
|---|
| 20 | // 2 --(20, 16)--> 1 |
|---|
| 21 | // <--(20,16)-- 5 |
|---|
| 22 | // 3 --(40, 12)--> 6 |
|---|
| 23 | // <--(40,12)-- 1 |
|---|
| 24 | // 4 --(20, 12)--> 7 |
|---|
| 25 | // <--(20,12)-- 1 |
|---|
| 26 | // 5 --(20, 16)--> 2 |
|---|
| 27 | // <--(20,16)-- 6 |
|---|
| 28 | // 6 --(20, 16)--> 5 --(10, 8)--> 8 |
|---|
| 29 | // <--(20,12)-- 7 <--(40,12)-- 3 |
|---|
| 30 | // 7 --(20, 12)--> 6 |
|---|
| 31 | // <--(20,12)-- 4 |
|---|
| 32 | // 8 |
|---|
| 33 | // <--(10,8)-- 6 |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | #include <boost/config.hpp> |
|---|
| 37 | #include <iostream> |
|---|
| 38 | #include <boost/graph/adjacency_list.hpp> |
|---|
| 39 | #include <boost/property_map.hpp> |
|---|
| 40 | |
|---|
| 41 | template <class Graph, class Capacity, class Flow> |
|---|
| 42 | void print_network(Graph& G, Capacity capacity, Flow flow) |
|---|
| 43 | { |
|---|
| 44 | typedef typename boost::graph_traits<Graph>::vertex_iterator Viter; |
|---|
| 45 | typedef typename boost::graph_traits<Graph>::out_edge_iterator OutEdgeIter; |
|---|
| 46 | typedef typename boost::graph_traits<Graph>::in_edge_iterator InEdgeIter; |
|---|
| 47 | |
|---|
| 48 | Viter ui, uiend; |
|---|
| 49 | for (boost::tie(ui, uiend) = boost::vertices(G); ui != uiend; ++ui) { |
|---|
| 50 | OutEdgeIter out, out_end; |
|---|
| 51 | std::cout << *ui << "\t"; |
|---|
| 52 | |
|---|
| 53 | for(boost::tie(out, out_end) = boost::out_edges(*ui, G); out != out_end; ++out) |
|---|
| 54 | std::cout << "--(" << boost::get(capacity, *out) << ", " |
|---|
| 55 | << boost::get(flow, *out) << ")--> " << boost::target(*out,G) << "\t"; |
|---|
| 56 | std::cout << std::endl << "\t"; |
|---|
| 57 | |
|---|
| 58 | InEdgeIter in, in_end; |
|---|
| 59 | for(boost::tie(in, in_end) = boost::in_edges(*ui, G); in != in_end; ++in) |
|---|
| 60 | std::cout << "<--(" << boost::get(capacity, *in) << "," << boost::get(flow, *in) << ")-- " |
|---|
| 61 | << boost::source(*in, G) << "\t"; |
|---|
| 62 | std::cout << std::endl; |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | int main(int , char* []) { |
|---|
| 68 | |
|---|
| 69 | typedef boost::adjacency_list<boost::vecS, boost::vecS, |
|---|
| 70 | boost::bidirectionalS, boost::no_property, |
|---|
| 71 | boost::property<boost::edge_index_t, std::size_t> > Graph; |
|---|
| 72 | |
|---|
| 73 | const int num_vertices = 9; |
|---|
| 74 | Graph G(num_vertices); |
|---|
| 75 | |
|---|
| 76 | /* 2<----5 |
|---|
| 77 | / ^ |
|---|
| 78 | / \ |
|---|
| 79 | V \ |
|---|
| 80 | 0 ---->1---->3----->6--->8 |
|---|
| 81 | \ ^ |
|---|
| 82 | \ / |
|---|
| 83 | V / |
|---|
| 84 | 4----->7 |
|---|
| 85 | */ |
|---|
| 86 | |
|---|
| 87 | int capacity[] = { 10, 20, 20, 20, 40, 40, 20, 20, 20, 10 }; |
|---|
| 88 | int flow[] = { 8, 12, 12, 12, 12, 12, 16, 16, 16, 8 }; |
|---|
| 89 | |
|---|
| 90 | // insert edges into the graph, and assign each edge an ID number |
|---|
| 91 | // to index into the property arrays |
|---|
| 92 | boost::add_edge(0, 1, 0, G); |
|---|
| 93 | |
|---|
| 94 | boost::add_edge(1, 4, 1, G); |
|---|
| 95 | boost::add_edge(4, 7, 2, G); |
|---|
| 96 | boost::add_edge(7, 6, 3, G); |
|---|
| 97 | |
|---|
| 98 | boost::add_edge(1, 3, 4, G); |
|---|
| 99 | boost::add_edge(3, 6, 5, G); |
|---|
| 100 | |
|---|
| 101 | boost::add_edge(6, 5, 6, G); |
|---|
| 102 | boost::add_edge(5, 2, 7, G); |
|---|
| 103 | boost::add_edge(2, 1, 8, G); |
|---|
| 104 | |
|---|
| 105 | boost::add_edge(6, 8, 9, G); |
|---|
| 106 | |
|---|
| 107 | typedef boost::property_map<Graph, boost::edge_index_t>::type EdgeIndexMap; |
|---|
| 108 | EdgeIndexMap edge_id = boost::get(boost::edge_index, G); |
|---|
| 109 | |
|---|
| 110 | typedef boost::iterator_property_map<int*, EdgeIndexMap, int, int&> IterMap; |
|---|
| 111 | |
|---|
| 112 | print_network(G, IterMap(capacity, edge_id), IterMap(flow, edge_id)); |
|---|
| 113 | |
|---|
| 114 | return 0; |
|---|
| 115 | } |
|---|