00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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();
00037 g.add_vertex();
00038 g.add_vertex();
00039 g.add_vertex();
00040 g.add_vertex();
00041 g.add_vertex();
00042 g.add_edge(0, 1);
00043 g.add_edge(1, 0);
00044 g.add_edge(0, 2);
00045 g.add_edge(3, 4);
00046 g.add_edge(4, 5);
00047 g.add_edge(5, 4);
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
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
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
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
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
00118
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
00128 unsigned i = e.nmax_nbh_edges();
00129 for_all(n)
00130 --i;
00131
00132
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 }