67 lines
2.5 KiB
C
67 lines
2.5 KiB
C
#ifndef INCLUDED_C_ACYCLICLP_H
|
|
#define INCLUDED_C_ACYCLICLP_H
|
|
|
|
#ifndef INCLUDED_C_EDGEWEIGHTEDDIGRAPH_H
|
|
#include <c_EdgeWeightedDigraph.h>
|
|
#endif /*INCLUDED_C_EDGEWEIGHTEDDIGRAPH_H*/
|
|
|
|
|
|
#ifndef INCLUDED_C_VERTEXIDLIST_H
|
|
#include <c_VertexIdList.h>
|
|
#endif /*INCLUDED_C_VERTEXIDLIST_H*/
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
typedef struct {
|
|
c_size_t* edge_to; /* edge_to[w] = entering directed edge_id on longest path to w */
|
|
c_size_t* from_vertex; /* from_vertex[w] = source vertex parent link on path to w */
|
|
double* dist_to; /* dist_to[w] = cumulative longest path distance from source s to w */
|
|
c_size_t s; /* The source vertex index */
|
|
c_size_t V; /* Total number of vertices in the digraph */
|
|
c_Allocator_t allocator; /* Deep copy of the user-provided allocator */
|
|
} c_AcyclicLP_t;
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
/**
|
|
* @brief Computes a longest-paths tree from the source vertex 's' in a directed acyclic graph (DAG).
|
|
* @param allocator Explicit allocator context used to configure internal tracking state memory
|
|
*/
|
|
c_err_t c_AcyclicLP_Init(c_AcyclicLP_t* self, c_EdgeWeightedDigraph_t* graph, c_size_t s, c_Allocator_t* allocator);
|
|
|
|
/**
|
|
* @brief Releases internal tracking buffers safely.
|
|
*/
|
|
void c_AcyclicLP_Destroy(c_AcyclicLP_t* self);
|
|
|
|
/**
|
|
* @brief Is there a directed path from the source vertex 's' to vertex 'v'?
|
|
*/
|
|
C_STATIC_FORCE_INLINE
|
|
c_bool_t c_AcyclicLP_HasPathTo(c_AcyclicLP_t* self, c_size_t v) {
|
|
if (!self || v >= self->V || !self->dist_to) return C_FALSE;
|
|
return self->dist_to[v] > -DBL_MAX;
|
|
}
|
|
|
|
/**
|
|
* @brief Returns the distance of the longest path from the source vertex 's' to vertex 'v'.
|
|
* @return Distance value, or -DBL_MAX if unreachable / parameter error
|
|
*/
|
|
C_STATIC_FORCE_INLINE
|
|
double c_AcyclicLP_DistTo(c_AcyclicLP_t* self, c_size_t v) {
|
|
if (!self || v >= self->V || !self->dist_to) return -DBL_MAX;
|
|
return self->dist_to[v];
|
|
}
|
|
|
|
/**
|
|
* @brief Reconstructs the exact longest path from the source vertex 's' to vertex 'v' and appends it to out_path.
|
|
* @param out_path An initialized c_VertexIdList_t container to collect the sequence of global directed edge_ids.
|
|
*/
|
|
c_err_t c_AcyclicLP_PathTo(c_AcyclicLP_t* self, c_size_t v, c_VertexIdList_t* out_path);
|
|
|
|
|
|
#endif /*INCLUDED_C_ACYCLICLP_H*/
|