Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
aleph-graph.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
44# ifndef ALEPH_GRAPH_H
45# define ALEPH_GRAPH_H
46
47# include <cassert>
48# include <cstring>
49# include <stdexcept>
50# include <memory>
51# include <string>
52
53namespace Aleph {
54
55
56static const long No_Visited = 0; // nodo o arco no ha sido visitado
57
87
88
92 extern const unsigned char Processed;
93
99 extern const unsigned char Processing;
100
106 extern const unsigned char Unprocessed;
107
108
133{
134public:
135
136 unsigned int depth_first : 1;
137 unsigned int breadth_first : 1;
138 unsigned int test_cycle : 1;
139 unsigned int find_path : 1;
140 unsigned int euler : 1;
141 unsigned int maximum_flow : 1;
142 unsigned int spanning_tree : 1;
143 unsigned int build_subtree : 1;
144 unsigned int convert_tree : 1;
145 unsigned int cut : 1;
146 unsigned int min : 1;
148
153 unsigned int state : 2;
154
157 {
158 reset();
159 }
160
171 [[nodiscard]] bool get_bit(int bit) const noexcept
172 {
173 switch (bit)
174 {
175 case Aleph::Depth_First: return depth_first;
177 case Aleph::Test_Cycle: return test_cycle;
178 case Aleph::Find_Path: return find_path;
179 case Aleph::Euler: return euler;
184 case Aleph::Cut: return cut;
185 case Aleph::Min: return min;
186 default: assert(false);
187 }
188 return false;
189 }
190
202 void set_bit(int bit, int value) noexcept
203 {
204 assert(value == 0 or value == 1);
205 switch (bit)
206 {
207 case Aleph::Depth_First: depth_first = value; break;
208 case Aleph::Breadth_First: breadth_first = value; break;
209 case Aleph::Test_Cycle: test_cycle = value; break;
210 case Aleph::Find_Path: find_path = value; break;
211 case Aleph::Euler: euler = value; break;
212 case Aleph::Maximum_Flow: maximum_flow = value; break;
213 case Aleph::Spanning_Tree: spanning_tree = value; break;
214 case Aleph::Build_Subtree: build_subtree = value; break;
215 case Aleph::Convert_Tree: convert_tree = value; break;
216 case Aleph::Cut: cut = value; break;
217 case Aleph::Min: min = value; break;
218 default: assert(false);
219 }
220 }
221
223 [[nodiscard]] unsigned int get_state() const noexcept { return state; }
224
226 [[nodiscard]] std::string str_state() const
227 {
228 switch (state)
229 {
230 case 0: return {"Unprocessed"};
231 case 1: return {"Processing"};
232 case 2: return {"Processed"};
233 default: break;
234 }
235 return {"Undefined"};
236 }
237
239 void set_state(unsigned char s) noexcept
240 {
241 assert(s < 4);
242 state = s;
243 }
244
246 void reset(int bit) noexcept { set_bit(bit, 0); }
247
250 {
251 depth_first = 0;
252 breadth_first = 0;
253 test_cycle = 0;
254 find_path = 0;
255 euler = 0;
256 maximum_flow = 0;
257 spanning_tree = 0;
258 build_subtree = 0;
259 convert_tree = 0;
260 cut = 0;
261 min = 0;
262 state = 0;
263 }
264};
265
266
314{
316 long counter = 0;
317 void * cookie = nullptr;
318
320 void reset()
321 {
323 counter = 0;
324 cookie = nullptr;
325 }
326};
327
328
333# define NODE_BITS(p) ((p)->attrs.control_bits)
334
339# define NODE_COUNTER(p) ((p)->attrs.counter)
340
345# define NODE_COLOR(p) ((p)->attrs.counter)
346
355# define IS_NODE_VISITED(p, bit) (NODE_BITS(p).get_bit(bit))
356
361# define NODE_COOKIE(p) ((p)->attrs.cookie)
362
367# define ARC_COUNTER(p) ((p)->attrs.counter)
368
373# define ARC_COLOR(p) ((p)->attrs.counter)
374
379# define ARC_BITS(p) ((p)->attrs.control_bits)
380
388# define IS_ARC_VISITED(p, bit) (ARC_BITS(p).get_bit(bit))
389
394# define ARC_COOKIE(p) ((p)->attrs.cookie)
395
396
397
398} // end namespace Aleph
399
400
401
402
403
404# endif
Bit fields for nodes and arcs used for marking visit state during processing.
void reset(int bit) noexcept
Reset bit to zero.
unsigned int find_path
Cycle existence test.
unsigned int convert_tree
Used by subtree or subgraph building.
void set_bit(int bit, int value) noexcept
Set a control bit.
Bit_Fields() noexcept
All the bits are set to zero.
unsigned int state
Used for min path or min spanning.
unsigned int cut
Used for Tree_Node conversion.
unsigned int min
Used for cut points computing.
bool get_bit(int bit) const noexcept
Get a control bit.
unsigned int depth_first
void reset() noexcept
Reset all bits and state to zero.
unsigned int euler
Path searching (there are several types)
unsigned int get_state() const noexcept
Return the state value.
unsigned int breadth_first
Depth first search.
void set_state(unsigned char s) noexcept
Set the state to the value s
std::string str_state() const
Return a stringification version of state.
unsigned int maximum_flow
Used during eulerian searching.
unsigned int build_subtree
Used by spannign tree algorithms.
unsigned int test_cycle
Breadth first search.
unsigned int spanning_tree
Used by the maximum flow algorithms.
const unsigned char Processed
The node or arc has already been processed.
Definition aleph-graph.C:39
const unsigned char Processing
The node are being processed; probably it is inside a queue, stack or heap.
Definition aleph-graph.C:38
Graph_Bits
Bit numbers of nodes or arcs.
Definition aleph-graph.H:72
const unsigned char Unprocessed
The node have not bees processed.
Definition aleph-graph.C:37
@ Depth_First
Definition aleph-graph.H:73
@ Build_Subtree
Definition aleph-graph.H:80
@ Breadth_First
Definition aleph-graph.H:74
@ Maximum_Flow
Definition aleph-graph.H:78
@ Test_Cycle
Definition aleph-graph.H:75
@ Num_Bits_Graph
Definition aleph-graph.H:85
@ Spanning_Tree
Definition aleph-graph.H:79
@ Convert_Tree
Definition aleph-graph.H:81
@ Find_Path
Definition aleph-graph.H:76
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
static const long No_Visited
Definition aleph-graph.H:56
DynList< T > maps(const C &c, Op op)
Classic map operation.
General attributes for nodes and arc of graphs.
Bit_Fields control_bits
void reset()
Reset all attributes to their default value.