Aleph-w  1.9
General library for algorithms and data structures
eulerian.H
1 
2 /* Aleph-w
3 
4  / \ | | ___ _ __ | |__ __ __
5  / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6  / ___ \| | __/ |_) | | | |_____\ V V / version 1.9b
7  /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8  |_|
9 
10  This file is part of Aleph-w library
11 
12  Copyright (c) 2002-2018 Leandro Rabindranath Leon & Alejandro Mujica
13 
14  This program is free software: you can redistribute it and/or modify
15  it under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  This program is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27 # ifndef EULERIAN_H
28 # define EULERIAN_H
29 
30 # include <tpl_graph.H>
31 
32 namespace Aleph
33 {
34 
49 template <class GT,
50  class SN = Dft_Show_Node<GT>,
51  class SA = Dft_Show_Arc<GT> >
53 {
54  SN & sn;
55  SA & sa;
56 
57  bool test_graph(GT & g)
58  {
59  assert(not g.is_digraph());
60 
61  for (Node_Iterator<GT, SN> it(g, sn); it.has_curr(); it.next_ne())
62  if ((g.get_num_arcs(it.get_curr_ne()) % 2) == 1)
63  return false;
64 
65  return true;
66  }
67 
68  bool test_digraph(GT & g)
69  {
70  assert(g.is_digraph());
71 
72  g.reset_counter_nodes();
73 
74  // una primera pasada sobre arcos para contar grados de entrada
75  for (Arc_Iterator<GT, SA> it(g, sa); it.has_curr(); it.next_ne())
76  NODE_COUNTER(it.get_tgt_node_ne())++;
77 
78  for (Node_Iterator<GT, SN> it(g, sn); it.has_curr(); it.next_ne())
79  {
80  typename GT::Node * p = it.get_curr_ne();
81  if (g.get_num_arcs(p) != NODE_COUNTER(p))
82  return false;
83  }
84 
85  return true;
86  }
87 
88 public:
89 
90  Test_Eulerian(SN && __sn = SN(), SA && __sa = SA())
91  : sn(__sn), sa(__sa)
92  {
93  // empty
94  }
95 
96  // retorna true si el grafo el euleriano
97  bool operator () (GT & g)
98  {
99  if (g.is_digraph())
100  return test_digraph(g);
101  else
102  return test_graph(g);
103  }
104 };
105 
106 
107 } // end namespace Aleph
108 
109 # endif // EULERIAN_H
Definition: tpl_graph.H:1225
#define NODE_COUNTER(p)
Definition: aleph-graph.H:311
Definition: tpl_graph.H:1257
Definition: ah-comb.H:35
Definition: tpl_graph.H:1063
Definition: tpl_graph.H:1270
Definition: eulerian.H:52

Leandro Rabindranath León