27 #ifndef MLN_UTIL_LINE_GRAPH_HH
28 # define MLN_UTIL_LINE_GRAPH_HH
34 # include <mln/util/internal/graph_base.hh>
35 # include <mln/util/internal/graph_iter.hh>
36 # include <mln/util/internal/graph_nbh_iter.hh>
37 # include <mln/util/ord_pair.hh>
57 typedef util::line_graph<G> lg_t;
58 typedef std::vector<std::vector<util::edge_id_t> > vertices_t;
59 typedef std::vector<util::ord_pair<util::vertex_id_t> > edges_t;
82 class line_graph :
public internal::graph_base< line_graph<G> >
85 typedef internal::graph_base< line_graph<G> > super;
87 typedef typename super::vertex_t vertex_t;
90 typedef typename super::vertex_data_t vertex_data_t;
91 typedef typename super::edge_data_t edge_data_t;
104 typedef mln::internal::vertex_fwd_iterator< line_graph<G> >
106 typedef mln::internal::vertex_bkd_iterator< line_graph<G> >
108 typedef vertex_fwd_iter vertex_iter;
113 typedef mln::internal::edge_fwd_iterator< line_graph<G> >
115 typedef mln::internal::edge_bkd_iterator< line_graph<G> >
122 typedef mln::internal::edge_nbh_edge_fwd_iterator< line_graph<G> >
124 typedef mln::internal::edge_nbh_edge_bkd_iterator< line_graph<G> >
125 edge_nbh_edge_bkd_iter;
131 typedef mln::internal::vertex_nbh_vertex_fwd_iterator< line_graph<G> >
133 typedef mln::internal::vertex_nbh_vertex_bkd_iterator< line_graph<G> >
134 vertex_nbh_vertex_bkd_iter;
140 typedef mln::internal::vertex_nbh_edge_fwd_iterator< line_graph<G> >
142 typedef mln::internal::vertex_nbh_edge_bkd_iterator< line_graph<G> >
143 vertex_nbh_edge_bkd_iter;
169 template <
typename G2>
174 size_t v_nmax_nbh_edges(
const vertex_id_t& id_v)
const;
180 size_t v_nmax_nbh_vertices(
const vertex_id_t& id_v)
const;
203 template <
typename G2>
214 size_t e_nmax_nbh_edges(
const edge_id_t& id_e)
const;
221 template <
typename G2>
225 const G&
graph()
const;
232 template <
typename G>
234 operator<<(std::ostream& ostr, const line_graph<G>& g);
240 # ifndef MLN_INCLUDE_ONLY
248 template <
typename G>
254 template <
typename G>
262 std::set<util::ord_pair<util::vertex_id_t> > edges_set;
264 vertices_.resize(g.e_nmax());
265 mln_edge_iter(G) e(g);
266 mln_edge_nbh_edge_iter(G) ne(e);
274 util::ord_pair<util::vertex_id_t>
edge(v1, v2);
275 if (edges_set.find(edge) == edges_set.end())
277 vertices_[v1].push_back(edges_.size());
278 vertices_[v2].push_back(edges_.size());
279 edges_set.insert(edge);
280 edges_.push_back(edge);
286 template <
typename G>
297 template <
typename G>
301 this->data_ =
new mln::internal::data< util::line_graph<G> >();
304 template <
typename G>
308 this->data_ =
new mln::internal::data< util::line_graph<G> >(g);
315 template <
typename G>
320 mln_assertion(has_v(id_v));
321 return vertex_t(*
this, id_v);
325 template <
typename G>
330 return data_->g_.e_nmax();
333 template <
typename G>
338 return data_->g_.has_v(id_v);
341 template <
typename G>
342 template <
typename G2>
348 return v.
graph().is_subgraph_of(*
this) && has_v(v.
id());
351 template <
typename G>
356 mln_precondition(has_v(id_v));
357 return data_->vertices_[id_v].size();
360 template <
typename G>
365 mln_precondition(has_v(id_v));
366 if (i >= v_nmax_nbh_edges(id_v))
368 return data_->vertices_[id_v][i];
371 template <
typename G>
376 mln_precondition(has_v(id_v));
377 return v_nmax_nbh_edges(id_v);
380 template <
typename G>
385 mln_precondition(has_v(id_v));
387 unsigned id_e = this->v_ith_nbh_edge(id_v, i);
388 return this->v_other(id_e, id_v);
396 template <
typename G>
401 mln_assertion(e < e_nmax());
405 template <
typename G>
410 return data_->edges_.size();
413 template <
typename G>
418 return id_e < data_->edges_.size();
421 template <
typename G>
422 template <
typename G2>
427 return e.
graph().is_subgraph_of(*
this) && has_e(e.
id());
430 template <
typename G>
435 mln_precondition(has_e(id_e));
436 return data_->edges_[id_e].first();
439 template <
typename G>
444 mln_precondition(has_e(id_e));
445 return data_->edges_[id_e].second();
448 template <
typename G>
453 mln_precondition(has_e(id_e));
454 return v_nmax_nbh_edges(v1(id_e)) + v_nmax_nbh_edges(v2(id_e));
457 template <
typename G>
462 mln_precondition(has_e(id_e));
463 if (i >= e_nmax_nbh_edges(id_e))
466 unsigned v1_nmax = v_nmax_nbh_edges(v1(id_e));
468 return v_ith_nbh_edge(v1(id_e), i);
469 return v_ith_nbh_edge(v2(id_e), i - v1_nmax);
473 template <
typename G>
474 template <
typename G2>
479 return g.id() == this->id();
482 template <
typename G>
487 return this->data_->g_;
491 template <
typename G>
494 operator<<(std::ostream& ostr, const line_graph<G>& g)
497 mln_vertex_iter(LG) v(g);
498 mln_vertex_nbh_edge_iter(LG) e(v);
501 ostr <<
"v(" << v <<
") : ";
514 # endif // ! MLN_INCLUDE_ONLY
517 #endif // ! MLN_UTIL_LINE_GRAPH_HH