undirected_graph.h
Go to the documentation of this file.
1 /*
2  * This file is part of the alglib project.
3  *
4  * (c) Divyanshu Kakwani <divkakwani@gmail.com>
5  *
6  * For the full copyright and license information, please view the LICENSE file
7  * that was distributed with this source code.
8  */
9 
10 #include <alglib/graph/edge.h>
12 
13 #pragma once
14 
15 namespace alglib {
16 namespace graph {
17 
18 template<typename vertex_t, typename attr_t = void,
19  template<typename, typename> class model = models::adj_list>
20 class undirected_graph : public model<vertex_t, edge_t<vertex_t, attr_t>> {
21 
22  typedef model<vertex_t, edge_t<vertex_t, attr_t>> super;
23  public:
25 
26  void add_edge(const vertex_t& u, const vertex_t& v, const attr_t& attr) {
27  super::add_edge(u, v, edge_type(u, v, attr));
28  super::add_edge(v, u, edge_type(v, u, attr));
29  }
30  int num_edges() const override {
31  return super::num_edges() / 2;
32  }
33 };
34 
35 // Partial specialzation for void attributes (or not attributes)
36 template<typename vertex_t, template<typename, typename> class model>
37 class undirected_graph<vertex_t, void, model> : public model<vertex_t, edge_t<vertex_t>> {
38 
39  typedef model<vertex_t, edge_t<vertex_t, void>> super;
40  public:
42 
43  void add_edge(const vertex_t& u, const vertex_t& v) {
44  super::add_edge(u, v, edge_type(u, v));
45  super::add_edge(v, u, edge_type(v, u));
46  }
47  int num_edges() const override {
48  return super::num_edges() / 2;
49  }
50 };
51 
52 
53 } // end of graph namespace
54 } // end of alglib namespace
55 
56 
57 
Definition: undirected_graph.h:20
Definition: bimap.h:17
int num_edges() const override
Definition: undirected_graph.h:30
int num_edges() const override
Definition: undirected_graph.h:47
Definition: edge.h:19
void add_edge(const vertex_t &u, const vertex_t &v, const attr_t &attr)
Definition: undirected_graph.h:26
edge_t< vertex_t, void > edge_type
Definition: undirected_graph.h:41
edge_t< vertex_t, attr_t > edge_type
Definition: undirected_graph.h:24
void add_edge(const vertex_t &u, const vertex_t &v)
Definition: undirected_graph.h:43