Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #include <mln/util/graph.hh> 00027 #include <mln/util/line_graph.hh> 00028 #include <iostream> 00029 00030 int main() 00031 { 00032 using namespace mln; 00033 00034 util::graph g; 00035 00036 g.add_vertex(); // 0 00037 g.add_vertex(); // 1 00038 g.add_vertex(); // 2 00039 g.add_vertex(); // 3 00040 g.add_vertex(); // 4 00041 g.add_vertex(); // 5 00042 g.add_edge(0, 1); 00043 g.add_edge(1, 0); // Not inserted twice 00044 g.add_edge(0, 2); 00045 g.add_edge(3, 4); 00046 g.add_edge(4, 5); 00047 g.add_edge(5, 4); // Not inserted twice 00048 g.add_edge(5, 3); 00049 g.add_edge(2, 1); 00050 00051 typedef util::line_graph<util::graph> LG; 00052 LG lg(g); 00053 00054 // Vertex and edge forward iterators. 00055 { 00056 unsigned i = 0; 00057 mln_vertex_fwd_iter_(LG) v(lg); 00058 for_all(v) 00059 mln_assertion(i++ == v.id()); 00060 mln_assertion(i != 0); 00061 00062 i = 0; 00063 mln_edge_fwd_iter_(LG) e(lg); 00064 for_all(e) 00065 mln_assertion(i++ == e.id()); 00066 mln_assertion(i != 0); 00067 } 00068 00069 // Vertex and edge backward iterators. 00070 { 00071 unsigned i = lg.v_nmax() - 1; 00072 mln_vertex_bkd_iter_(LG) v(lg); 00073 for_all(v) 00074 mln_assertion(i-- == v.id()); 00075 mln_assertion(i != lg.v_nmax() - 1); 00076 00077 i = lg.e_nmax() - 1; 00078 mln_edge_bkd_iter_(LG) e(lg); 00079 for_all(e) 00080 mln_assertion(i-- == e.id()); 00081 mln_assertion(i != lg.e_nmax() - 1); 00082 } 00083 00084 // Vertex and edge nbh forward iterators 00085 { 00086 mln_vertex_fwd_iter_(LG) v(lg); 00087 mln_vertex_nbh_edge_fwd_iter_(LG) n(v); 00088 for_all(v) 00089 { 00090 unsigned i = 0; 00091 for_all(n) 00092 mln_assertion(i++ == n.index()); 00093 mln_assertion(i != 0); 00094 } 00095 } 00096 00097 // Vertex and edge nbh backward iterators. 00098 { 00099 mln_vertex_bkd_iter_(LG) v(lg); 00100 mln_vertex_nbh_edge_bkd_iter_(LG) e(v); 00101 for_all(v) 00102 { 00103 unsigned i = v.nmax_nbh_edges(); 00104 for_all(e) 00105 mln_assertion(--i == e.index()); 00106 mln_assertion((v.nmax_nbh_edges() == 0 && i == 0) || i != v.nmax_nbh_edges()); 00107 } 00108 } 00109 { 00110 mln_edge_fwd_iter_(LG) e(lg); 00111 mln_edge_nbh_edge_fwd_iter_(LG) n(e); 00112 for_all(e) 00113 { 00114 unsigned i = 0; 00115 for_all(n) 00116 ++i; 00117 // we check i == e.nmax_nbh_edges() - 2 since e is it's own neighboor and the 00118 // iterator skip it. 00119 mln_assertion((i == 0 && e.nmax_nbh_edges() < 2) || i == e.nmax_nbh_edges() - 2); 00120 } 00121 } 00122 { 00123 mln_edge_bkd_iter_(LG) e(lg); 00124 mln_edge_nbh_edge_bkd_iter_(LG) n(e); 00125 for_all(e) 00126 { 00127 //std::cout << "== e.id() = " << e.id() << std::endl; 00128 unsigned i = e.nmax_nbh_edges(); 00129 for_all(n) 00130 --i; 00131 // we check i == e.nmax_nbh_edges() - 2 since e is it's own neighboor and the 00132 // iterator skip it. 00133 mln_assertion((i == e.nmax_nbh_edges() && e.nmax_nbh_edges() < 2) || i == 2); 00134 00135 } 00136 } 00137 { 00138 mln_vertex_fwd_iter_(LG) v(lg); 00139 mln_vertex_nbh_vertex_fwd_iter_(LG) n(v); 00140 for_all(v) 00141 { 00142 unsigned i = 0; 00143 for_all(n) 00144 ++i; 00145 mln_assertion(i == v.nmax_nbh_vertices()); 00146 } 00147 } 00148 { 00149 mln_vertex_bkd_iter_(LG) v(lg); 00150 mln_vertex_nbh_vertex_bkd_iter_(LG) n(v); 00151 for_all(v) 00152 { 00153 unsigned i = v.nmax_nbh_vertices(); 00154 for_all(n) 00155 --i; 00156 mln_assertion(i == 0); 00157 } 00158 } 00159 }