Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
mat_path.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
83#ifndef MAT_PATH_H
84#define MAT_PATH_H
85
86#include <tpl_matgraph.H>
87
88namespace Aleph
89{
90
129template <class Mat>
130void find_min_path(Mat & p, long src_idx, long tgt_idx,
132{
133 using GT = typename Mat::Graph_Type;
134 GT & g = p.get_list_graph();
135
136 // Handle trivial case: source equals target
137 if (src_idx == tgt_idx)
138 {
139 path.set_graph(g, p(src_idx));
140 return;
141 }
142
143 // Initialize path with source node
144 typename GT::Node * src = p(src_idx);
145 path.set_graph(g, src);
146
147 // Follow path matrix to reconstruct the path
148 for (long i = src_idx, j = p(i, tgt_idx); ; i = j, j = p(i, tgt_idx))
149 {
150 path.append(p(j));
151 if (j == tgt_idx)
152 break;
153 }
154}
155
166template <class Mat>
167void find_min_path(Mat & p,
168 typename Mat::Node * src_node,
169 typename Mat::Node * tgt_node,
171{
172 find_min_path(p, p(src_node), p(tgt_node), path);
173}
174
191template <class Mat>
193{
194public:
198 void operator()(Mat & p,
199 typename Mat::Node * src_node,
200 typename Mat::Node * tgt_node,
202 {
203 find_min_path<Mat>(p, src_node, tgt_node, path);
204 }
205
209 void operator()(Mat & p,
210 long src_index, long tgt_index,
212 {
214 }
215};
216
217} // namespace Aleph
218
219// Global namespace compatibility
222
223#endif // MAT_PATH_H
Functor wrapper for find_min_path.
Definition mat_path.H:193
void operator()(Mat &p, typename Mat::Node *src_node, typename Mat::Node *tgt_node, Path< typename Mat::Graph_Type > &path) const
Reconstruct path using node pointers.
Definition mat_path.H:198
void operator()(Mat &p, long src_index, long tgt_index, Path< typename Mat::Graph_Type > &path) const
Reconstruct path using matrix indices.
Definition mat_path.H:209
Path on a graph.
Definition tpl_graph.H:2669
void set_graph(const GT &__g, Node *start_node=nullptr)
Set the graph of the path.
Definition tpl_graph.H:2797
void append(Arc *arc)
Append an arc to the path.
Definition tpl_graph.H:2865
void find_min_path(Mat &p, const long src_index, const long tgt_index, Path< typename Mat::Graph_Type > &path)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
DynList< T > maps(const C &c, Op op)
Classic map operation.
Adjacency matrix representations for graphs.