Directed graph with fixed vertex count and efficient cycle detection Stores edges in a dense adjacency matrix slice per vertex. Only the actually used portion of each row is tracked via list_sizes.
Constructor interface for digraph type.
Initializes a new instance of the digraph class
type(digraph) function digraph(integer vertices)
| [in] | vertices | Number of vertices (usually number of currently defined macros) |
Examples
Remarks
Private Attributes | |
| integer, private | vertices |
| Number of vertices. | |
| integer, dimension(:, :), allocatable, private | adjacency_list |
| Adjacency list containing the connection information between the vertices. | |
| integer, dimension(:), allocatable, private | list_sizes |
| Actually used portion of each row of adjacency_list. | |
| procedure, pass, public add_edge | ( | class(digraph), intent(inout) | this, |
| integer, intent(in) | source, | ||
| integer, intent(in) | destination, | ||
| logical, intent(out), optional | exists ) |
Add a directed edge from source → destination Silently ignores invalid indices. Optional exists flag indicates if edge was already present.
| [in,out] | this | digraph object |
| [in] | source | Source vertex (1-based) |
| [in] | destination | Target vertex (1-based) |
| [out] | exists | (optional) .true. if edge already existed |
Remarks
| procedure, pass, public is_circular | ( | class(digraph), intent(in) | this, |
| integer, intent(in) | start_vertex ) |
Check whether a cycle exists in the graph reachable from start_vertex Uses standard DFS with recursion stack (back-edge detection).
| [in] | this | digraph object |
| [in] | start_vertex | Vertex from which to begin cycle search |
Remarks