Aleph-w  1.9
General library for algorithms and data structures
aleph-graph.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 ALEPH_GRAPH_H
28 # define ALEPH_GRAPH_H
29 
30 # include <cassert>
31 # include <cstring>
32 # include <stdexcept>
33 # include <memory>
34 # include <string>
35 
36 namespace Aleph {
37 
38 
39 static const long No_Visited = 0; // nodo o arco no ha sido visitado
40 
55 {
56  Depth_First,
57  Breadth_First,
58  Test_Cycle,
59  Find_Path,
60  Euler,
61  Maximum_Flow,
62  Spanning_Tree,
63  Build_Subtree,
64  Convert_Tree,
65  Cut,
66  Min,
67 
68  Num_Bits_Graph
69 };
70 
71 
75  extern const unsigned char Processed;
76 
82  extern const unsigned char Processing;
83 
89  extern const unsigned char Unprocessed;
90 
91 
116 {
117 public:
118 
119  unsigned int depth_first : 1;
120  unsigned int breadth_first : 1;
121  unsigned int test_cycle : 1;
122  unsigned int find_path : 1;
123  unsigned int euler : 1;
124  unsigned int maximum_flow : 1;
125  unsigned int spanning_tree : 1;
126  unsigned int build_subtree : 1;
127  unsigned int convert_tree : 1;
128  unsigned int cut : 1;
129  unsigned int min : 1;
130 
136  unsigned int state : 2;
137 
139  Bit_Fields() noexcept
140  {
141  memset(this, 0, sizeof *this);
142  }
143 
154  bool get_bit(int bit) const noexcept
155  {
156  switch (bit)
157  {
158  case Aleph::Depth_First: return depth_first;
159  case Aleph::Breadth_First: return breadth_first;
160  case Aleph::Test_Cycle: return test_cycle;
161  case Aleph::Find_Path: return find_path;
162  case Aleph::Euler: return euler;
163  case Aleph::Maximum_Flow: return maximum_flow;
164  case Aleph::Spanning_Tree: return spanning_tree;
165  case Aleph::Build_Subtree: return build_subtree;
166  case Aleph::Convert_Tree: return convert_tree;
167  case Aleph::Cut: return cut;
168  case Aleph::Min: return min;
169  default: assert(false);
170  }
171  return false;
172  }
173 
185  void set_bit(int bit, int value) noexcept
186  {
187  assert(value == 0 or value == 1);
188  switch (bit)
189  {
190  case Aleph::Depth_First: depth_first = value; break;
191  case Aleph::Breadth_First: breadth_first = value; break;
192  case Aleph::Test_Cycle: test_cycle = value; break;
193  case Aleph::Find_Path: find_path = value; break;
194  case Aleph::Euler: euler = value; break;
195  case Aleph::Maximum_Flow: maximum_flow = value; break;
196  case Aleph::Spanning_Tree: spanning_tree = value; break;
197  case Aleph::Build_Subtree: build_subtree = value; break;
198  case Aleph::Convert_Tree: convert_tree = value; break;
199  case Aleph::Cut: cut = value; break;
200  case Aleph::Min: min = value; break;
201  default: assert(false);
202  }
203  }
204 
206  unsigned int get_state() const noexcept { return state; }
207 
209  std::string str_state() const
210  {
211  switch (state)
212  {
213  case 0: return std::string("Unprocessed");
214  case 1: return std::string("Processing");
215  case 2: return std::string("Processed");
216  default: break;
217  }
218  return std::string("Undefined");
219  }
220 
222  void set_state(unsigned char s) noexcept
223  {
224  assert(s < 4);
225  state = s;
226  }
227 
229  void reset(int bit) noexcept { set_bit(bit, 0); }
230 
232  void reset() noexcept
233  {
234  memset(this, 0, sizeof *this);
235  }
236 };
237 
238 
286 {
287  Bit_Fields control_bits;
288  long counter = 0;
289  void * cookie = nullptr;
290 
292  void reset()
293  {
294  control_bits.reset();
295  counter = 0;
296  cookie = nullptr;
297  }
298 };
299 
300 
305 # define NODE_BITS(p) ((p)->attrs.control_bits)
306 
311 # define NODE_COUNTER(p) ((p)->attrs.counter)
312 
317 # define NODE_COLOR(p) ((p)->attrs.counter)
318 
327 # define IS_NODE_VISITED(p, bit) (NODE_BITS(p).get_bit(bit))
328 
333 # define NODE_COOKIE(p) ((p)->attrs.cookie)
334 
339 # define ARC_COUNTER(p) ((p)->attrs.counter)
340 
345 # define ARC_COLOR(p) ((p)->attrs.counter)
346 
351 # define ARC_BITS(p) ((p)->attrs.control_bits)
352 
360 # define IS_ARC_VISITED(p, bit) (ARC_BITS(p).get_bit(bit))
361 
366 # define ARC_COOKIE(p) ((p)->attrs.cookie)
367 
368 
369 
370 } // end namespace Aleph
371 
372 
373 
374 
375 
376 # endif
const unsigned char Processing
unsigned int min
Used for cut points computing.
Definition: aleph-graph.H:129
unsigned int breadth_first
Depth first search.
Definition: aleph-graph.H:120
Definition: aleph-graph.H:285
unsigned int convert_tree
Used by subtree or subgraph building.
Definition: aleph-graph.H:127
void reset() noexcept
Reset all bits and state to zero.
Definition: aleph-graph.H:232
unsigned int state
Definition: aleph-graph.H:136
unsigned int cut
Used for Tree_Node conversion.
Definition: aleph-graph.H:128
void reset()
Reset all attributes to their default value.
Definition: aleph-graph.H:292
void reset(int bit) noexcept
Reset bit to zero.
Definition: aleph-graph.H:229
const unsigned char Unprocessed
std::string str_state() const
Return a stringficated version of state.
Definition: aleph-graph.H:209
const unsigned char Processed
unsigned int test_cycle
Breadth first search.
Definition: aleph-graph.H:121
unsigned int find_path
Cycle existence test.
Definition: aleph-graph.H:122
Definition: ah-comb.H:35
unsigned int build_subtree
Used by spannign tree algorithms.
Definition: aleph-graph.H:126
unsigned int spanning_tree
Used by the maximum flow algorithms.
Definition: aleph-graph.H:125
unsigned int get_state() const noexcept
Return the state value.
Definition: aleph-graph.H:206
Graph_Bits
Definition: aleph-graph.H:54
void set_state(unsigned char s) noexcept
Set the state to the value s
Definition: aleph-graph.H:222
bool get_bit(int bit) const noexcept
Definition: aleph-graph.H:154
void set_bit(int bit, int value) noexcept
Definition: aleph-graph.H:185
unsigned int maximum_flow
Used during eulerian searching.
Definition: aleph-graph.H:124
unsigned int euler
Path searching (there are several types)
Definition: aleph-graph.H:123
Definition: aleph-graph.H:115
Bit_Fields() noexcept
All the bits are set to zero.
Definition: aleph-graph.H:139

Leandro Rabindranath León