Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
shortest_path_common.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
48#ifndef SHORTEST_PATH_COMMON_H
49#define SHORTEST_PATH_COMMON_H
50
51# include <ah-graph-concepts.H>
52
53#include <limits>
54#include <sstream>
55#include <stdexcept>
56#include <type_traits>
57#include <ah-errors.H>
58#include <tpl_graph.H>
59#include <tpl_find_path.H>
60#include <tpl_dynListQueue.H>
61#include <tpl_dynSetTree.H>
62#include <cookie_guard.H>
63
64namespace Aleph
65{
66
67// =============================================================================
68// Cookie Access Macros (internal use)
69// =============================================================================
70
71// These macros provide unified access to node/arc cookies across algorithms
72
74#define SP_NODE_INFO(p) (static_cast<typename Shortest_Path_Base::Node_Info*>(NODE_COOKIE(p)))
75
77#define SP_TREE_NODE_INFO(p) (static_cast<typename Shortest_Path_Base::Tree_Node_Info*>(NODE_COOKIE(p)))
78
80#define SP_ACC(p) (SP_NODE_INFO(p)->dist)
81
83#define SP_HEAPNODE(p) (SP_NODE_INFO(p)->heap_node)
84
86#define SP_PARENT(p) (SP_NODE_INFO(p)->ret_node)
87
89#define SP_TREENODE(p) (SP_TREE_NODE_INFO(p)->tree_node)
90
92#define SP_ARC_INFO(p) (static_cast<typename Shortest_Path_Base::Arc_Info*>(ARC_COOKIE(p)))
93
95#define SP_TREE_ARC_INFO(p) (static_cast<typename Shortest_Path_Base::Tree_Arc_Info*>(ARC_COOKIE(p)))
96
98#define SP_POT(p) (SP_ARC_INFO(p)->pot)
99
101#define SP_TREEARC(p) (SP_TREE_ARC_INFO(p)->tree_arc)
102
103
104// =============================================================================
105// Overflow-Checked Arithmetic
106// =============================================================================
107
109namespace shortest_path_detail
110{
111
123template <typename T>
124[[nodiscard]] inline T checked_add(const T& a, const T& b)
125{
126 if constexpr (std::is_integral_v<T>)
127 {
128 ah_overflow_error_if(b > 0 and a > std::numeric_limits<T>::max() - b)
129 << "Integer overflow in distance addition: " << a << " + " << b;
130
131 ah_overflow_error_if(b < 0 and a < std::numeric_limits<T>::min() - b)
132 << "Integer underflow in distance addition: " << a << " + " << b;
133 }
134
135 return a + b;
136}
137
150template <typename T>
151[[nodiscard]] inline bool add_if_fits(const T& a, const T& b, T& out)
152{
153 if constexpr (std::is_integral_v<T>)
154 if (b > 0 and a > std::numeric_limits<T>::max() - b)
155 return false;
156
157 out = a + b;
158 return true;
159}
160
168struct Beyond_Max_Error : std::overflow_error
170 using std::overflow_error::overflow_error;
171};
172
173} // namespace shortest_path_detail
174
175
176// =============================================================================
177// Base Class for Shortest Path Algorithms
178// =============================================================================
179
198template <AlephGraph GT,
199 ArcDistance<GT> Distance,
200 template <typename, class> class Itor,
201 ArcFilter<GT> SA,
202 template <class, class, class> class HeapT>
204{
205public:
206 // =========================================================================
207 // Cookie Structures
208 // =========================================================================
209
216 struct Arc_Info
217 {
219 };
220
225 struct Tree_Arc_Info : public Arc_Info
226 {
227 typename GT::Arc* tree_arc = nullptr;
228 };
229
236 {
238 void* heap_node = nullptr;
239 void* ret_node = nullptr;
240 };
241
246 struct Tree_Node_Info : public Node_Info
247 {
248 typename GT::Node* tree_node = nullptr;
249 };
250
251 // =========================================================================
252 // Heap Access Functor
253 // =========================================================================
254
257 {
258 void*& operator()(typename GT::Node* p) const noexcept
259 {
260 return SP_HEAPNODE(p);
261 }
262 };
263
264 // =========================================================================
265 // Get Potential Functor
266 // =========================================================================
267
270 {
271 Get_Potential_Arc() = default;
272
273 Get_Potential_Arc(Distance& d) noexcept : Distance(d) { }
274
276 operator()(typename GT::Arc* a) const noexcept
277 {
278 return SP_POT(a);
279 }
280 };
281
282 // =========================================================================
283 // Initialize Functors
284 // =========================================================================
285
288 {
289 void operator()(const GT& g, typename GT::Node* p) const
290 {
292 NODE_COOKIE(p) = new Node_Info;
293 }
294
296 static void release(typename GT::Node* p) noexcept
297 {
298 delete SP_NODE_INFO(p);
299 NODE_COOKIE(p) = nullptr;
300 }
301 };
302
305 {
306 void operator()(const GT& g, typename GT::Arc* a) const
307 {
309 ARC_COOKIE(a) = new Arc_Info;
310 SP_POT(a) = 0;
311 }
312
314 static void release(typename GT::Arc* a) noexcept
315 {
316 delete SP_ARC_INFO(a);
317 ARC_COOKIE(a) = nullptr;
318 }
319 };
320
323 {
324 void operator()(const GT& g, typename GT::Node* p) const
325 {
328 }
329
331 static void release(typename GT::Node* p) noexcept
332 {
333 delete SP_TREE_NODE_INFO(p);
334 NODE_COOKIE(p) = nullptr;
335 }
336 };
337
340 {
341 void operator()(const GT& g, typename GT::Arc* a) const
342 {
344 ARC_COOKIE(a) = new Tree_Arc_Info;
345 SP_POT(a) = 0;
346 SP_TREEARC(a) = nullptr;
347 }
348
350 static void release(typename GT::Arc* a) noexcept
351 {
352 delete SP_TREE_ARC_INFO(a);
353 ARC_COOKIE(a) = nullptr;
354 }
355 };
356
357 // =========================================================================
358 // Destroy Functors
359 // =========================================================================
360
363 {
364 void operator()(const GT&, typename GT::Node* p) const noexcept
365 {
366 void* tmp = SP_PARENT(p);
367 delete SP_NODE_INFO(p);
368 NODE_COOKIE(p) = tmp;
369 }
370 };
371
374 {
375 void operator()(const GT&, typename GT::Arc* ga) const noexcept
376 {
377 delete SP_ARC_INFO(ga);
378 ARC_COOKIE(ga) = nullptr;
379 }
380 };
381
384 {
385 void operator()(const GT&, typename GT::Node* p) const noexcept
386 {
387 auto aux = SP_TREE_NODE_INFO(p);
388 auto tp = SP_TREENODE(p);
389 if (tp != nullptr)
390 {
391 NODE_COOKIE(p) = NODE_COOKIE(tp) = nullptr;
392 GT::map_nodes(p, tp);
393 }
394 else
395 NODE_COOKIE(p) = nullptr;
396
397 delete aux;
398 }
399 };
400
403 {
404 void operator()(const GT&, typename GT::Arc* ga) const noexcept
405 {
406 auto aux = SP_TREE_ARC_INFO(ga);
407 typename GT::Arc* ta = SP_TREEARC(ga);
408 ARC_COOKIE(ga) = nullptr; // else map_arcs() would chain ta to aux
409 if (ta != nullptr)
410 {
412 GT::map_arcs(ga, ta);
413 }
414
415 delete aux;
416 }
417 };
418
419 // =========================================================================
420 // Type Aliases
421 // =========================================================================
422
423 using Heap = HeapT<GT, Get_Potential_Arc, Heap_Info>;
424
425protected:
426 // =========================================================================
427 // Member Variables
428 // =========================================================================
429
430 SA sa;
434 bool painted = false;
435 GT* ptr_g = nullptr;
436 typename GT::Node* s = nullptr;
437 bool beyond_max = false;
438
450
451 // =========================================================================
452 // Protected Methods
453 // =========================================================================
454
472 template <class IN, class IA>
473 void init(const GT& g, typename GT::Node* start)
474 {
475 heap.empty();
476 painted = false;
477 beyond_max = false;
478
479 ptr_g = &const_cast<GT&>(g);
480 s = start;
481
482 // the first num_nodes nodes have a new cookie, and the first num_arcs
483 // arcs that the filter shows; with a filter that can throw, those of
484 // the first num_arcs arcs that have the bit Min
485 size_t num_nodes = 0, num_arcs = 0;
486 try
487 {
488 for (Node_Iterator<GT> it(g); it.has_curr(); it.next_ne(), ++num_nodes)
489 IN()(g, it.get_curr());
490 // A hidden arc may have the bit of an earlier painting, which the
491 // tree, unfiltered, would take; one pass, with the filter called
492 // as an Arc_Iterator<GT, SA> calls it
493 if constexpr (nothrow_arc_filter_v<GT, SA>)
494 for (Arc_Iterator<GT> it(g); it.has_curr(); it.next_ne())
495 if (auto a = it.get_curr_ne(); sa(a))
496 {
497 IA()(g, a);
498 ++num_arcs;
499 }
500 else
502 else
503 for (Arc_Iterator<GT> it(g); it.has_curr(); it.next_ne(), ++num_arcs)
504 if (auto a = it.get_curr_ne(); sa(a))
505 {
506 IA()(g, a);
507 g.set_bit(a, Aleph::Min, true);
508 }
509 else
510 {
511 g.reset_bit(a, Aleph::Min);
513 }
514 }
515 catch (...)
516 {
517 Node_Iterator<GT> nit(g);
518 for (size_t i = 0; i < num_nodes; ++i, nit.next_ne())
519 IN::release(nit.get_curr());
520 if constexpr (nothrow_arc_filter_v<GT, SA>)
521 {
522 Arc_Iterator<GT, SA> ait(g, sa);
523 for (size_t i = 0; i < num_arcs; ++i, ait.next_ne())
524 IA::release(ait.get_curr());
525 }
526 else
527 {
528 Arc_Iterator<GT> ait(g);
529 for (size_t i = 0; i < num_arcs; ++i, ait.next_ne())
530 if (auto a = ait.get_curr_ne(); IS_ARC_VISITED(a, Aleph::Min))
531 IA::release(a);
532 }
533 throw;
534 }
535 }
536
546 template <class DN, class DA>
547 [[nodiscard]] auto uninit_on_exit()
548 {
549 return Scope_Guard(*ptr_g, [this](const GT &) { uninit<DN, DA>(); });
550 }
551
561 template <class DN, class DA>
562 void uninit()
563 {
564 // Clear heap first to avoid use-after-free when heap destructor
565 // tries to compare arcs whose cookies have been freed
566 heap.empty();
567
568 Operate_On_Nodes<GT, DN>()(*ptr_g);
569 if constexpr (nothrow_arc_filter_v<GT, SA>)
571 else
572 for (Arc_Iterator<GT> it(*ptr_g); it.has_curr(); it.next_ne())
573 if (auto a = it.get_curr_ne(); IS_ARC_VISITED(a, Aleph::Min))
574 DA()(*ptr_g, a);
575 }
576
590 [[gnu::always_inline]] bool
592 const typename Distance::Distance_Type& b,
594 {
595 using T = typename Distance::Distance_Type;
596 if constexpr (std::is_integral_v<T>)
597 {
598 if (b > 0 and a > std::numeric_limits<T>::max() - b) [[unlikely]]
599 {
600 beyond_max = true;
601 return false;
602 }
603 ah_overflow_error_if(b < 0 and a < std::numeric_limits<T>::min() - b)
604 << "Integer underflow in distance addition: " << a << " + " << b;
605 }
606 out = a + b; // the checks of checked_add(), each once
607 return true;
608 }
609
625 [[gnu::noinline, gnu::cold]]
626 void check_beyond_max(const GT& g, typename GT::Node* start,
627 typename GT::Node* end = nullptr) const
628 {
630 return;
631
632 using Node = typename GT::Node;
635 seen.insert(start);
636 queue.put(start);
637 while (not queue.is_empty())
638 {
639 Node* p = queue.get();
640 if (end == nullptr ? not IS_NODE_VISITED(p, Aleph::Spanning_Tree) : p == end)
641 [[unlikely]]
643 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
644 << "the distance from the start to a node does not fit in its type";
645 for (Itor<GT, SA> it(p, sa); it.has_curr(); it.next_ne())
646 if (Node* t = it.get_tgt_node(); seen.insert(t) != nullptr)
647 queue.put(t);
648 }
649 (void) g;
650 }
651
661 const typename Distance::Distance_Type& b) const
662 {
664 }
665
666public:
667 // =========================================================================
668 // Constructors
669 // =========================================================================
670
676 Shortest_Path_Base(Distance dist = Distance(), SA __sa = SA())
677 : sa(__sa), distance(dist), get_pot(dist), heap(get_pot, Heap_Info()),
678 painted(false), ptr_g(nullptr), s(nullptr)
679 {
680 // empty
681 }
682
683 // =========================================================================
684 // State Getters
685 // =========================================================================
686
690 [[nodiscard]] bool has_computation() const noexcept { return ptr_g != nullptr; }
691
700 [[nodiscard]] bool is_painted() const noexcept { return painted; }
701
705 [[nodiscard]] typename GT::Node* get_start_node() const noexcept { return s; }
706
710 [[nodiscard]] GT* get_graph() const noexcept { return ptr_g; }
711
712 // =========================================================================
713 // Distance Calculation
714 // =========================================================================
715
730 get_distance(typename GT::Node* node)
731 {
732 ah_domain_error_if(not painted) << "Graph has not been painted";
733 ah_domain_error_if(node == nullptr) << "node cannot be null";
734
735 if (node == s)
736 return 0;
737
739 << "node is not reachable from start";
740
741 typename Distance::Distance_Type total = 0;
742
743 for (auto curr = node; curr != s;)
744 {
745 auto parent = static_cast<typename GT::Node*>(NODE_COOKIE(curr));
746 if (parent == nullptr)
747 break;
748
749 for (Itor<GT, SA> it(parent, sa); it.has_curr(); it.next_ne())
750 {
751 auto arc = it.get_current_arc_ne();
752 auto tgt = it.get_tgt_node();
753 if (tgt == curr and IS_ARC_VISITED(arc, Aleph::Spanning_Tree))
754 {
755 total += distance(arc);
756 break;
757 }
758 }
759 curr = parent;
760 }
761
762 return total;
763 }
764
765 // =========================================================================
766 // Path Extraction from Painted Graph
767 // =========================================================================
768
781 get_min_path(typename GT::Node* end, Path<GT>& path)
782 {
783 ah_domain_error_if(ptr_g == nullptr) << "Min path has not been computed";
784 ah_domain_error_if(not painted) << "Graph has not been painted";
785
786 return Aleph::get_min_path<GT, Distance>(s, end, path, distance);
787 }
788
789 // =========================================================================
790 // Copy Painted Tree
791 // =========================================================================
792
798 struct Total
799 {
801
804
808 Total() = default;
809
814 explicit Total(Distance __distance) : distance(__distance) {}
815
822 bool operator()(typename GT::Arc* a)
823 {
824 dist += distance(a);
825 return true;
826 }
827 };
828
831 {
832 bool operator()(typename GT::Arc* a) const noexcept
833 {
835 }
836 };
837
840 {
841 bool operator()(typename GT::Node* p) const noexcept
842 {
844 }
845 };
846
864 {
865 ah_domain_error_if(not painted) << "Graph has not been painted";
866
867 // Copy_Graph works on a copy of its filter, so the filter cannot be
868 // the one that adds up the weights.
869 typename Distance::Distance_Type total = 0;
870 for (Arc_Iterator<GT, Painted_Arc> it(g); it.has_curr(); it.next_ne())
871 {
872 auto a = it.get_curr();
873 total += distance(a);
874 ARC_COOKIE(a) = nullptr;
875 }
876
877 // null cookies make Copy_Graph map both ways instead of chaining the
878 // parents of the painting
879 painted = false;
880 for (Node_Iterator<GT> it(g); it.has_curr(); it.next_ne())
881 NODE_COOKIE(it.get_curr()) = nullptr;
882
884 copy_painted_arcs(tree, g);
885
886 return total;
887 }
888
901 get_min_path(const GT& tree, typename GT::Node* end, Path<GT>& path)
902 {
903 ah_domain_error_if(ptr_g == nullptr) << "Min path has not been computed";
904
905 typename Distance::Distance_Type total_dist = 0;
906 path.empty();
907 if (end == s)
908 {
909 path.init(s);
910 return total_dist;
911 }
912
913 auto ts = mapped_node<GT>(s);
914 auto te = mapped_node<GT>(end);
915 ah_domain_error_if(ts == nullptr or te == nullptr)
916 << "get_min_path(): the end is not in the tree";
917
918 // Every arc of the tree is one of the paths: the filter of the
919 // painting has nothing to hide in it
920 Path<GT> tree_path(tree);
921 ah_domain_error_if(not (Find_Path_Depth_First<GT, Itor>()(tree, ts, te, tree_path)))
922 << "get_min_path(): the end is not reached in the tree";
923
924 // The arcs of g that those of the tree map to, which one of their
925 // parallel arcs, searched by their ends, may not be
926 path.init(s);
927 for (typename Path<GT>::Iterator it(tree_path); it.has_current_arc(); it.next_ne())
928 {
929 auto ga = mapped_arc<GT>(it.get_current_arc_ne());
930 path.append(ga);
931 total_dist += distance(ga);
932 }
933
934 return total_dist;
935 }
936};
937
938
939// Cleanup macros (they are redefined in derived classes with appropriate types)
940#undef SP_NODE_INFO
941#undef SP_TREE_NODE_INFO
942#undef SP_ACC
943#undef SP_HEAPNODE
944#undef SP_PARENT
945#undef SP_TREENODE
946#undef SP_ARC_INFO
947#undef SP_TREE_ARC_INFO
948#undef SP_POT
949#undef SP_TREEARC
950
951} // namespace Aleph
952
953#endif // SHORTEST_PATH_COMMON_H
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
Definition ah-errors.H:611
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Definition ah-errors.H:670
C++20 concepts for the protocol shared by graph algorithms.
WeightedDigraph::Node Node
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
int num_nodes
Definition btreepic.C:410
size_t size_t int32_t * out
Definition ca-c-api.h:120
Filtered copy of graphs.
Definition tpl_graph.H:4951
Dynamic queue of elements of generic type T based on single linked list.
T & put(const T &data)
The type of element.
T get()
Remove the oldest item of the queue.
bool is_empty() const noexcept
Return true if this is empty.
Dynamic set backed by balanced binary search trees with automatic memory management.
Key * insert(const Key &key)
Inserts a key into the dynamic set.
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
Performs a depth-first search for a path between a pair of nodes.
Filtered iterator on the nodes of a graph.
Definition tpl_graph.H:1287
Functor that traverses the arcs of a graph and performs an operation.
Definition tpl_graph.H:3743
Functor that traverses the nodes of a graph and performs an operation.
Definition tpl_graph.H:3698
Iterator on nodes and arcs of a path.
Definition tpl_graph.H:4395
bool has_current_arc() const noexcept
Return true if iterator has current arc.
Definition tpl_graph.H:4506
Path on a graph.
Definition tpl_graph.H:3832
void empty()
Clean the path: all the nodes and arc are removed.
Definition tpl_graph.H:3999
void init(Node *start_node)
Set the first node of a path.
Definition tpl_graph.H:3947
void append(Arc *arc)
Append an arc to the path.
Definition tpl_graph.H:4052
Generic RAII scope guard for cleanup operations on graphs.
Base class providing common infrastructure for shortest path algorithms.
Shortest_Path_Base(Distance dist=Distance(), SA __sa=SA())
Default constructor.
Distance::Distance_Type get_min_path(typename GT::Node *end, Path< GT > &path)
Extracts a shortest path to end from a previously painted graph.
void check_beyond_max(const GT &g, typename GT::Node *start, typename GT::Node *end=nullptr) const
After a painting in which a sum went beyond max(), throws if a node that start reaches was left out,...
Get_Potential_Arc get_pot
Potential accessor.
Distance::Distance_Type copy_painted_min_paths_tree(GT &g, GT &tree)
Extracts the painted shortest paths tree and puts it in tree.
bool is_painted() const noexcept
Check if the graph has been painted.
auto uninit_on_exit()
Returns a guard that calls uninit() when it goes out of scope.
Distance::Distance_Type get_min_path(const GT &tree, typename GT::Node *end, Path< GT > &path)
Extracts path from tree to end node.
bool has_computation() const noexcept
Check if a computation has been performed.
Distance::Distance_Type checked_add(const typename Distance::Distance_Type &a, const typename Distance::Distance_Type &b) const
Checked addition to prevent integer overflow.
GT * get_graph() const noexcept
Get the graph of the last computation.
Distance::Distance_Type get_distance(typename GT::Node *node)
Gets the accumulated distance to a node after painting.
bool leave_out_beyond_max
Whether a painting leaves out without throwing the nodes whose distance does not fit.
GT::Node * get_start_node() const noexcept
Get the start node of the last computation.
bool add_if_fits(const typename Distance::Distance_Type &a, const typename Distance::Distance_Type &b, typename Distance::Distance_Type &out)
Adds a tentative distance that may go beyond max().
bool beyond_max
A sum of the painting went beyond max()
void uninit()
Cleanup algorithm state.
GT * ptr_g
Pointer to the graph.
bool painted
Whether graph has been painted.
HeapT< GT, Get_Potential_Arc, Heap_Info > Heap
void init(const GT &g, typename GT::Node *start)
Initialize algorithm state.
void set_bit(Node *node, int bit, int value) const noexcept
Set the control bit of node to value
Definition graph-dry.H:1105
static void map_arcs(A1 *p, A2 *q) noexcept
Map the arcs through their cookies.
Definition graph-dry.H:1312
void reset_bit(Node *node, int bit) const noexcept
Reset the bit of node (to zero)
Definition graph-dry.H:1087
static void map_nodes(N1 *p, N2 *q) noexcept
Map the nodes through their cookies.
Definition graph-dry.H:1281
RAII guards for graph node/arc cookies.
#define ARC_COOKIE(p)
Return the arc cookie
#define IS_NODE_VISITED(p, bit)
Determine whether the control bit is set or not to one.
#define NODE_COOKIE(p)
Return the node cookie
#define IS_ARC_VISITED(p, bit)
Determine whether the bit field is or not set to one.
@ Spanning_Tree
Definition aleph-graph.H:79
bool add_if_fits(const T &a, const T &b, T &out)
Adds two distance values when the sum fits.
T checked_add(const T &a, const T &b)
Safely add two distance values with overflow checking.
Main namespace for Aleph-w library functions.
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:152
and
Check uniqueness with explicit hash + equality functors.
#define SP_TREE_ARC_INFO(p)
Convert arc cookie to Tree_Arc_Info pointer.
#define SP_TREE_NODE_INFO(p)
Convert node cookie to Tree_Node_Info pointer.
#define SP_ARC_INFO(p)
Convert arc cookie to Arc_Info pointer.
#define SP_PARENT(p)
Access parent pointer from node cookie.
#define SP_POT(p)
Access arc potential from arc cookie.
#define SP_TREEARC(p)
Access tree arc mapping from arc cookie.
#define SP_NODE_INFO(p)
Convert node cookie to Node_Info pointer.
#define SP_HEAPNODE(p)
Access heap node handle from node cookie.
#define SP_TREENODE(p)
Access tree node mapping from node cookie.
Filtered iterator on all the arcs of a graph.
Definition tpl_graph.H:1200
Exception constructor with formatted message.
Definition ah-errors.H:226
Information stored in arc cookies for painting version.
Distance::Distance_Type pot
Arc potential (priority)
Arc cleanup for painting version.
void operator()(const GT &, typename GT::Arc *ga) const noexcept
Node cleanup for painting version.
void operator()(const GT &, typename GT::Node *p) const noexcept
Arc cleanup and mapping for tree-building version.
void operator()(const GT &, typename GT::Arc *ga) const noexcept
Node cleanup and mapping for tree-building version.
void operator()(const GT &, typename GT::Node *p) const noexcept
Functor to get arc potential for heap ordering.
Distance::Distance_Type operator()(typename GT::Arc *a) const noexcept
Functor to access heap node handle from node cookie.
void *& operator()(typename GT::Node *p) const noexcept
Arc initialization for painting version.
void operator()(const GT &g, typename GT::Arc *a) const
static void release(typename GT::Arc *a) noexcept
Frees the cookie of a and leaves it null.
Node initialization for painting version.
void operator()(const GT &g, typename GT::Node *p) const
static void release(typename GT::Node *p) noexcept
Frees the cookie of p and leaves it null.
Arc initialization for tree-building version.
void operator()(const GT &g, typename GT::Arc *a) const
static void release(typename GT::Arc *a) noexcept
Frees the cookie of a and leaves it null.
Node initialization for tree-building version.
static void release(typename GT::Node *p) noexcept
Frees the cookie of p and leaves it null.
void operator()(const GT &g, typename GT::Node *p) const
Information stored in node cookies for painting version.
Distance::Distance_Type dist
Accumulated distance from start.
void * heap_node
Handle in priority queue.
void * ret_node
Parent node (for backtracking)
Arc filter that shows the arcs of the painted tree.
bool operator()(typename GT::Arc *a) const noexcept
Node filter that shows the nodes of the painted tree.
bool operator()(typename GT::Node *p) const noexcept
Distance totalizer class for path copying.
bool operator()(typename GT::Arc *a)
Adds the weight of an arc to dist.
Total()=default
Builds the totalizer with a distance accessor built by Distance().
Distance distance
Distance accessor for the arc weights.
Total(Distance __distance)
Builds the totalizer with a distance accessor.
Extended arc info with tree arc mapping.
GT::Arc * tree_arc
Corresponding arc in spanning tree.
Extended node info with tree node mapping.
GT::Node * tree_node
Corresponding node in spanning tree.
The std::overflow_error of a painting that leaves out a node whose distance does not fit.
Distance accessor.
Dynamic queue implementation based on linked lists.
Dynamic set implementations based on balanced binary search trees.
Path finding algorithms in graphs.
Generic graph and digraph implementations.