#include <digraphx/neg_cycle_q.hpp>
template<typename DiGraph, typename Domain>
NegCycleFinderQ class
Negative Cycle Finder with constraints using Howard's method.
| Template parameters | |
|---|---|
| DiGraph | Type of the directed graph representation |
| Domain | Numeric type for distance calculations |
This class extends the basic negative cycle detection to support constrained optimization problems. It implements both predecessor and successor versions of Howard's algorithm, providing flexibility in how cycles are detected and how distance updates are constrained.
Algorithm variants:
- Predecessor-based (howard_pred):
- Follows traditional Bellman-Ford relaxation
- Updates dist[v] based on dist[u] + weight(u,v)
- Useful when constraints apply to forward updates
Predecessor relaxation: dist[v] > dist[u] + w(u,v) a -----> b becomes: pred[b] = a
- Successor-based (howard_succ):
- Uses reverse relaxation logic
- Updates dist[u] based on dist[v] - weight(u,v)
- Useful when constraints apply to backward updates
Successor relaxation: dist[u] < dist[v] - w(u,v) a -----> b becomes: succ[a] = b
Constraint handling:
- The UpdateOk callback controls when distance updates are allowed
- This enables domain-specific constraints and optimization strategies
- Can implement bounds, step size limits, or custom validation
Template requirements:
- DiGraph: Same as basic NegCycleFinder
- Domain: Numeric type for distance calculations
Constructors, destructors, conversion operators
- NegCycleFinderQ(const DiGraph& digraph) explicit
- Initialize the negative cycle finder with a directed graph.
Public functions
-
template<typename Mapping, typename GetWeight, typename UpdateOk>auto howard_pred(Mapping& dist, GetWeight&& get_weight, UpdateOk&& update_ok) -> cppcoro::generator< Cycle > -> auto
- Find negative cycles using predecessor-based Howard's algorithm.
-
template<typename Mapping, typename GetWeight, typename UpdateOk>auto howard_succ(Mapping& dist, GetWeight&& get_weight, UpdateOk&& update_ok) -> cppcoro::generator< Cycle > -> auto
- Find negative cycles using successor-based Howard's algorithm.
Function documentation
template<typename DiGraph, typename Domain>
NegCycleFinderQ<DiGraph, Domain>:: NegCycleFinderQ(const DiGraph& digraph) explicit
Initialize the negative cycle finder with a directed graph.
| Parameters | |
|---|---|
| digraph | A directed graph represented as a nested mapping |
template<typename DiGraph, typename Domain>
template<typename Mapping, typename GetWeight, typename UpdateOk>
auto NegCycleFinderQ<DiGraph, Domain>:: howard_pred(Mapping& dist,
GetWeight&& get_weight,
UpdateOk&& update_ok) -> cppcoro::generator< Cycle >
Find negative cycles using predecessor-based Howard's algorithm.
| Template parameters | |
|---|---|
| Mapping | Distance mapping type |
| GetWeight | Callable type for getting edge weights |
| UpdateOk | Callable type for update constraint |
| Parameters | |
| dist | Initial distance estimates (often zero-initialized) |
| get_weight | Function to get weight of an edge |
| update_ok | Function to determine if distance updates are allowed |
| Returns | cppcoro::generator<Cycle> Each negative cycle found as a list of edges |
template<typename DiGraph, typename Domain>
template<typename Mapping, typename GetWeight, typename UpdateOk>
auto NegCycleFinderQ<DiGraph, Domain>:: howard_succ(Mapping& dist,
GetWeight&& get_weight,
UpdateOk&& update_ok) -> cppcoro::generator< Cycle >
Find negative cycles using successor-based Howard's algorithm.
| Template parameters | |
|---|---|
| Mapping | Distance mapping type |
| GetWeight | Callable type for getting edge weights |
| UpdateOk | Callable type for update constraint |
| Parameters | |
| dist | Initial distance estimates (often zero-initialized) |
| get_weight | Function to get weight of an edge |
| update_ok | Function to determine if distance updates are allowed |
| Returns | cppcoro::generator<Cycle> Each negative cycle found as a list of edges |