Milena (Olena)
User documentation 2.0a Id
|
00001 #include <mln/core/concept/function.hh> 00002 #include <mln/util/graph.hh> 00003 00004 #include <vector> 00005 00006 #include <doc/tools/sample_utils.hh> 00007 00008 struct viota_t : public mln::Function_v2v< viota_t > 00009 { 00010 typedef unsigned result; 00011 00012 viota_t(unsigned size) 00013 { 00014 v_.resize(size); 00015 for(unsigned i = 0; i < size; ++i) 00016 v_[i] = 10 + i; 00017 } 00018 00019 unsigned 00020 operator()(const mln::util::vertex<mln::util::graph>& v) const 00021 { 00022 return v_[v.id()]; 00023 } 00024 00025 protected: 00026 std::vector<result> v_; 00027 }; 00028 00029 int main() 00030 { 00031 using namespace mln; 00032 00033 util::graph g; 00034 00035 for (unsigned i = 0; i < 5; ++i) 00036 g.add_vertex(); // Add vertex 'i'; 00037 00038 g.add_edge(0, 1); // Associated to edge 0. 00039 g.add_edge(1, 2); // Associated to edge 1. 00040 g.add_edge(1, 3); // Associated to edge 2. 00041 g.add_edge(3, 4); // Associated to edge 3. 00042 g.add_edge(4, 2); // Associated to edge 4. 00043 00044 00045 00046 doc::begin_output(); 00047 // \{ 00048 // Function which maps sites to data. 00049 viota_t viota(g.v_nmax()); 00050 00051 // Iterator on vertices. 00052 mln_vertex_iter_(util::graph) v(g); 00053 00054 // Prints each vertex and its associated value. 00055 for_all(v) 00056 std::cout << v << " : " << viota(v) << std::endl; 00057 // \} 00058 doc::end_output(); 00059 00060 00061 { 00062 doc::begin_output(); 00063 // \{ 00064 // Iterator on vertices. 00065 mln_vertex_iter_(util::graph) v(g); 00066 00067 // Iterator on v's edges. 00068 mln_vertex_nbh_edge_iter_(util::graph) e(v); 00069 00070 // Prints the graph 00071 // List all edges for each vertex. 00072 for_all(v) 00073 { 00074 std::cout << v << " : "; 00075 for_all(e) 00076 std::cout << e << " "; 00077 std::cout << std::endl; 00078 } 00079 // \} 00080 doc::end_output(); 00081 } 00082 00083 00084 00085 { 00086 doc::begin_output(); 00087 // \{ 00088 // Iterator on edges. 00089 mln_edge_iter_(util::graph) e(g); 00090 00091 // Iterator on edges adjacent to e. 00092 mln_edge_nbh_edge_iter_(util::graph) ne(e); 00093 00094 // Prints the graph 00095 // List all adjacent edges for each edge. 00096 for_all(e) 00097 { 00098 std::cout << e << " : "; 00099 for_all(ne) 00100 std::cout << ne << " "; 00101 std::cout << std::endl; 00102 } 00103 // \} 00104 doc::end_output(); 00105 } 00106 00107 00108 00109 { 00110 doc::begin_output(); 00111 // \{ 00112 // Iterator on vertices. 00113 mln_vertex_iter_(util::graph) v(g); 00114 00115 // Iterator on vertices adjacent to v. 00116 mln_vertex_nbh_vertex_iter_(util::graph) nv(v); 00117 00118 // Prints the graph 00119 // List all adjacent edges for each edge. 00120 for_all(v) 00121 { 00122 std::cout << v << " : "; 00123 for_all(nv) 00124 std::cout << nv << " "; 00125 std::cout << std::endl; 00126 } 00127 // \} 00128 doc::end_output(); 00129 } 00130 }