• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

graph.cc

00001 // Copyright (C) 2007, 2008, 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 <iostream>
00028 
00029 int main ()
00030 {
00031   using namespace mln;
00032 
00033   util::graph g;
00034 
00035   g.add_vertices(6);
00036   g.add_edge (0, 1);
00037   g.add_edge (0, 2);
00038   g.add_edge (3, 4);
00039   g.add_edge (4, 5);
00040   g.add_edge (5, 4);
00041   g.add_edge (1, 0);
00042   g.add_edge (5, 3);
00043   g.add_edge (2, 1);
00044 
00045 
00046   // Vertex iter and edge iter
00047   {
00048     unsigned i = 0;
00049     mln_vertex_fwd_iter_(util::graph) v(g);
00050     for_all(v)
00051       mln_assertion(i++ == v.id());
00052     mln_assertion(i != 0);
00053 
00054     i = 0;
00055     mln_edge_fwd_iter_(util::graph) e(g);
00056     for_all(e)
00057       mln_assertion(i++ == e.id());
00058     mln_assertion(i != 0);
00059   }
00060   {
00061     unsigned i = g.v_nmax() - 1;
00062     mln_vertex_bkd_iter_(util::graph) v(g);
00063     for_all(v)
00064       mln_assertion(i-- == v.id());
00065     mln_assertion(i != g.v_nmax() - 1);
00066 
00067     i = g.e_nmax() - 1;
00068     mln_edge_bkd_iter_(util::graph) e(g);
00069     for_all(e)
00070       mln_assertion(i-- == e.id());
00071     mln_assertion(i != g.e_nmax() - 1);
00072   }
00073 
00074   // vertex iter + Edge nbh iter
00075   {
00076     mln_vertex_fwd_iter_(util::graph) v(g);
00077     mln_vertex_nbh_edge_fwd_iter_(util::graph) n(v);
00078     for_all(v)
00079     {
00080       unsigned i = 0;
00081       for_all(n)
00082         mln_assertion(i++ == n.index());
00083       mln_assertion(i != 0);
00084     }
00085   }
00086   {
00087     mln_vertex_bkd_iter_(util::graph) v(g);
00088     mln_vertex_nbh_edge_bkd_iter_(util::graph) e(v);
00089     for_all(v)
00090     {
00091       unsigned i = v.nmax_nbh_edges();
00092       for_all(e)
00093         mln_assertion(--i == e.index());
00094       mln_assertion((v.nmax_nbh_edges() == 0 && i == 0) || i != v.nmax_nbh_edges());
00095     }
00096   }
00097 
00098   {
00099     mln_edge_fwd_iter_(util::graph) e(g);
00100     mln_edge_nbh_edge_fwd_iter_(util::graph) n(e);
00101     for_all(e)
00102     {
00103       unsigned i = 0;
00104       for_all(n)
00105         ++i;
00106       // we check i == e.nmax_nbh_edges() - 2 since e is it's own neighboor and the
00107       // iterator skip it.
00108       mln_assertion((i == 0 && e.nmax_nbh_edges() < 2) || i == e.nmax_nbh_edges() - 2);
00109     }
00110   }
00111   {
00112     mln_edge_bkd_iter_(util::graph) e(g);
00113     mln_edge_nbh_edge_bkd_iter_(util::graph) n(e);
00114     for_all(e)
00115     {
00116       //std::cout << "== e.id() = " << e.id() << std::endl;
00117       unsigned i = e.nmax_nbh_edges();
00118       for_all(n)
00119         --i;
00120       // we check i == e.nmax_nbh_edges() - 2 since e is it's own neighboor and the
00121       // iterator skip it.
00122       mln_assertion((i == e.nmax_nbh_edges() && e.nmax_nbh_edges() < 2) || i == 2);
00123 
00124     }
00125   }
00126 
00127   {
00128     mln_vertex_fwd_iter_(util::graph) v(g);
00129     mln_vertex_nbh_vertex_fwd_iter_(util::graph) n(v);
00130     for_all(v)
00131     {
00132       unsigned i = 0;
00133       for_all(n)
00134         ++i;
00135       mln_assertion(i == v.nmax_nbh_vertices());
00136     }
00137   }
00138   {
00139     mln_vertex_bkd_iter_(util::graph) v(g);
00140     mln_vertex_nbh_vertex_bkd_iter_(util::graph) n(v);
00141     for_all(v)
00142     {
00143       unsigned i = v.nmax_nbh_vertices();
00144       for_all(n)
00145         --i;
00146       mln_assertion(i == 0);
00147     }
00148   }
00149 }

Generated on Fri Sep 16 2011 16:33:32 for Milena (Olena) by  doxygen 1.7.1