Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
warshall.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
50# ifndef WARSHALL_H
51# define WARSHALL_H
52
53# include <tpl_graph.H>
54# include <tpl_matgraph.H>
55
56namespace Aleph {
57
79 template <class GT, class SA = Dft_Show_Arc<GT> >
82{
84 if (mat.get_list_graph() != &g)
85 mat.set_list_graph(g);
86 const size_t & n = mat.get_num_nodes();
87 for (int k = 0; k < n; k++)
88 {
89 for (int i = 0; i < n; i++)
90 for (int j = 0; j < n; j++)
91 mat(i, j) = mat_prev(i, j) or
92 (mat_prev(i, k) and mat_prev(k, j));
93
94 mat_prev = mat;
95 }
96}
97
112 template <class GT, class SA = Dft_Show_Arc<GT> >
114{
115public:
116
127 void operator () (GT & g, Bit_Mat_Graph<GT> & mat) const
128 {
130 }
131};
132
133} // end namespace Aleph
134# endif // WARSHALL_H
135
Bit matrix for graph connectivity.
size_t get_num_nodes() const noexcept
Get number of nodes (matrix dimension)
GT * get_list_graph() noexcept
Get pointer to associated graph (nullptr if none)
void set_list_graph(GT &g)
Associate with a graph.
Computes the transitive closure of a graph using Warshall's algorithm.
Definition warshall.H:114
void operator()(GT &g, Bit_Mat_Graph< GT > &mat) const
Invokes the computation of the transitive closure of a graph.
Definition warshall.H:127
void warshall_compute_transitive_clausure(GT &g, Bit_Mat_Graph< GT, SA > &mat)
Computes the transitive closure of a graph using Warshall's algorithm.
Definition warshall.H:80
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
DynList< T > maps(const C &c, Op op)
Classic map operation.
Generic graph and digraph implementations.
Adjacency matrix representations for graphs.