52 lines
1.8 KiB
C
52 lines
1.8 KiB
C
#ifndef INCLUDED_C_FORDFULKERSON_H
|
|
#define INCLUDED_C_FORDFULKERSON_H
|
|
|
|
#ifndef INCLUDED_C_FLOWNETWORK_H
|
|
#include <c_FlowNetwork.h>
|
|
#endif /*INCLUDED_C_FLOWNETWORK_H*/
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
typedef struct {
|
|
c_size_t* edge_to; /* edge_to[v] = global edge_id on augmenting path to vertex v */
|
|
c_bool_t* marked; /* marked[v] = C_TRUE if an augmenting path can reach vertex v */
|
|
double max_flow; /* Cumulative total maximum value computed */
|
|
c_size_t V; /* Vertex limit count cached locally */
|
|
c_Allocator_t allocator; /* Deep copy of the user-provided allocator */
|
|
} c_FordFulkerson_t;
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
/**
|
|
* @brief Computes the maximum flow and minimum cut from source 's' to sink 't'.
|
|
* @param allocator Explicit allocator context used to configure temporary path discovery buffers
|
|
*/
|
|
c_err_t c_FordFulkerson_Init(c_FordFulkerson_t* self, c_FlowNetwork_t* graph, c_size_t s, c_size_t t, c_Allocator_t* allocator);
|
|
|
|
/**
|
|
* @brief Releases internal tracking buffers safely.
|
|
*/
|
|
void c_FordFulkerson_Destroy(c_FordFulkerson_t* self);
|
|
|
|
/**
|
|
* @brief Returns the total maximum flow value computed.
|
|
*/
|
|
C_STATIC_FORCE_INLINE
|
|
double c_FordFulkerson_GetValue(const c_FordFulkerson_t* self) {
|
|
return self ? self->max_flow : 0.0;
|
|
}
|
|
|
|
/**
|
|
* @brief Determines if vertex 'v' is on the source side of the minimum cut.
|
|
*/
|
|
C_STATIC_FORCE_INLINE
|
|
c_bool_t c_FordFulkerson_InCut(const c_FordFulkerson_t* self, c_size_t v) {
|
|
if (!self || v >= self->V || !self->marked) return C_FALSE;
|
|
return self->marked[v];
|
|
}
|
|
|
|
#endif /*INCLUDED_C_FORDFULKERSON_H*/
|