|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Computes topological ordering using breadth-first search (Kahn's algorithm). More...
#include <topological_sort.H>
Public Member Functions | |
| Q_Topological_Sort (SA &&__sa=SA()) | |
| Constructor with rvalue arc filter. | |
| Q_Topological_Sort (SA &__sa) | |
| Constructor with lvalue arc filter. | |
| template<template< class > class List> | |
| List< typename GT::Node * > | perform (const GT &g) |
| Compute topological ordering using BFS (Kahn's algorithm). | |
| template<template< class > class RankList = DynList, template< class > class List = DynList> | |
| RankList< List< typename GT::Node * > > | ranks (const GT &g) |
| Compute rank-based topological ordering. | |
| void | operator() (const GT &g, DynDlist< DynList< typename GT::Node * > > &list) |
| Operator() overload returning ranks as DynDlist of DynList. | |
| void | operator() (const GT &g, DynList< DynList< typename GT::Node * > > &list) |
| Operator() overload returning ranks as DynList of DynList. | |
| void | operator() (const GT &g, DynDlist< typename GT::Node * > &list) |
| Operator() overload for backward compatibility (flat list). | |
Private Attributes | |
| Kept_Filter< SA > | sa |
Computes topological ordering using breadth-first search (Kahn's algorithm).
This class performs topological sorting using a queue-based approach. It repeatedly:
Also provides rank-based ordering where nodes at the same "level" (same topological depth) are grouped together, useful for identifying parallelizable tasks.
| GT | The directed graph type. |
| Itor | Iterator type for traversing outgoing arcs (default: Out_Iterator). |
| SA | Arc filter/selector (default: Dft_Show_Arc<GT>). |
Definition at line 242 of file topological_sort.H.
|
inline |
Constructor with rvalue arc filter.
| __sa | Arc filter/selector (moved). |
Definition at line 251 of file topological_sort.H.
|
inline |
Constructor with lvalue arc filter.
| __sa | Arc filter/selector (referenced). |
Definition at line 257 of file topological_sort.H.
|
inline |
Operator() overload returning ranks as DynDlist of DynList.
| g | The directed acyclic graph. |
| list | Output list to receive the rank-based ordering. |
Definition at line 385 of file topological_sort.H.
|
inline |
Operator() overload for backward compatibility (flat list).
| g | The directed acyclic graph. |
| list | Output list to receive the topological ordering. |
Definition at line 406 of file topological_sort.H.
|
inline |
Operator() overload returning ranks as DynList of DynList.
| g | The directed acyclic graph. |
| list | Output list to receive the rank-based ordering. |
Definition at line 397 of file topological_sort.H.
|
inline |
Compute topological ordering using BFS (Kahn's algorithm).
Uses in-degree counting and a queue to process source nodes, producing a valid topological ordering.
| g | The directed acyclic graph. |
| std::bad_alloc | If memory allocation fails. |
| std::domain_error | If g is not a digraph. |
Definition at line 276 of file topological_sort.H.
References Aleph::Dlink::append(), Aleph::DynListQueue< T >::get(), GraphCommon< GT, Node, Arc >::get_node_it(), Aleph::DynListQueue< T >::is_empty(), Aleph::Filter_Iterator< Container, It, Show_Item >::next_ne(), NODE_COUNTER, Aleph::DynListQueue< T >::put(), GraphCommon< GT, Node, Arc >::reset_counter_nodes(), and Aleph::Q_Topological_Sort< GT, Itor, SA >::sa.
Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().
|
inline |
Compute rank-based topological ordering.
Returns the topological ordering organized by ranks (levels). Each rank contains nodes that can be processed in parallel, as they have no dependencies on each other within the same rank.
| RankList | Outer container type for ranks (default: DynList). |
| List | Inner container type for nodes in each rank (default: DynList). |
| g | The directed acyclic graph. |
| std::bad_alloc | If memory allocation fails. |
| std::domain_error | If g is not a digraph. |
Definition at line 334 of file topological_sort.H.
References Aleph::Dlink::append(), Aleph::DynListQueue< T >::get(), Aleph::DynListQueue< T >::is_empty(), NODE_COUNTER, Aleph::DynListQueue< T >::put(), Aleph::Q_Topological_Sort< GT, Itor, SA >::ranks(), GraphCommon< GT, Node, Arc >::reset_counter_nodes(), Aleph::Q_Topological_Sort< GT, Itor, SA >::sa, and Aleph::DynListQueue< T >::swap().
Referenced by demo_bfs_topological_sort(), demo_course_scheduling(), Aleph::rank_graphviz(), Aleph::Q_Topological_Sort< GT, Itor, SA >::ranks(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().
|
private |
Definition at line 244 of file topological_sort.H.
Referenced by Aleph::Q_Topological_Sort< GT, Itor, SA >::perform(), and Aleph::Q_Topological_Sort< GT, Itor, SA >::ranks().