Skip to content

Commit 4f0c0c9

Browse files
committed
cleanup
1 parent 060fd8b commit 4f0c0c9

File tree

14 files changed

+118
-376
lines changed

14 files changed

+118
-376
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ add_executable(netgraph_core_tests
2222
tests/cpp/flow_graph_tests.cpp
2323
tests/cpp/max_flow_tests.cpp
2424
tests/cpp/k_shortest_paths_tests.cpp
25-
tests/cpp/negative_safety_tests.cpp
2625
tests/cpp/masking_tests.cpp
2726
)
2827
target_link_libraries(netgraph_core_tests PRIVATE netgraph_core GTest::gtest_main)

dev/compare_flow_policy_with_netgraph.py

Lines changed: 0 additions & 246 deletions
This file was deleted.

include/netgraph/core/backend.hpp

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
44
The default CPU backend delegates to in-process algorithm implementations.
55
All execution flows through this interface via an Algorithms façade.
6-
7-
For Python developers:
8-
- std::shared_ptr<T>: reference-counted pointer (like Python object references)
9-
- virtual: method can be overridden in subclasses (like Python's inheritance)
10-
- = 0: pure virtual (must be implemented by subclass, like @abstractmethod)
116
*/
127
#pragma once
138

@@ -25,7 +20,7 @@
2520
namespace netgraph::core {
2621

2722
// GraphHandle: opaque handle to a backend-owned graph.
28-
// Uses shared_ptr for automatic lifetime management (like Python's reference counting).
23+
// Uses shared_ptr for automatic lifetime management.
2924
struct GraphHandle {
3025
std::shared_ptr<const StrictMultiDiGraph> graph {};
3126
};
@@ -34,30 +29,100 @@ class Backend {
3429
public:
3530
virtual ~Backend() noexcept = default;
3631

37-
// Prepare a backend-specific graph handle from an existing graph reference.
38-
// CPU backend creates a non-owning shared_ptr with a no-op deleter.
32+
// Prepares a backend-specific graph handle from an existing graph reference.
33+
//
34+
// The CPU backend creates a non-owning shared_ptr with a no-op deleter.
35+
//
36+
// Arguments:
37+
// g: The source graph to wrap.
38+
//
39+
// Returns:
40+
// A GraphHandle containing the backend-specific graph representation.
3941
[[nodiscard]] virtual GraphHandle build_graph(const StrictMultiDiGraph& g) = 0;
4042

41-
// Prepare a backend-specific graph handle that takes shared ownership of the
43+
// Prepares a backend-specific graph handle that takes shared ownership of the
4244
// provided graph instance.
45+
//
46+
// Arguments:
47+
// g: The source graph as a shared_ptr.
48+
//
49+
// Returns:
50+
// A GraphHandle that shares ownership of the graph.
4351
[[nodiscard]] virtual GraphHandle build_graph(std::shared_ptr<const StrictMultiDiGraph> g) = 0;
4452

53+
// Computes shortest paths from a source node.
54+
//
55+
// Arguments:
56+
// gh: The graph handle.
57+
// src: The source node ID.
58+
// opts: Configuration options for SPF (e.g., multipath, edge selection).
59+
//
60+
// Returns:
61+
// A pair containing:
62+
// - A vector of costs (distances) from src to all nodes.
63+
// - A predecessor DAG encoding the shortest paths.
4564
[[nodiscard]] virtual std::pair<std::vector<Cost>, PredDAG> spf(
4665
const GraphHandle& gh, NodeId src, const SpfOptions& opts) = 0;
4766

67+
// Computes maximum flow between a source and destination node.
68+
//
69+
// Arguments:
70+
// gh: The graph handle.
71+
// src: The source node ID.
72+
// dst: The destination node ID.
73+
// opts: Configuration options for max flow (e.g., algorithm, capacity constraints).
74+
//
75+
// Returns:
76+
// A pair containing:
77+
// - The total flow amount.
78+
// - A FlowSummary struct with detailed results.
4879
[[nodiscard]] virtual std::pair<Flow, FlowSummary> max_flow(
4980
const GraphHandle& gh, NodeId src, NodeId dst, const MaxFlowOptions& opts) = 0;
5081

82+
// Computes K-shortest paths between a source and destination node.
83+
//
84+
// Arguments:
85+
// gh: The graph handle.
86+
// src: The source node ID.
87+
// dst: The destination node ID.
88+
// opts: Configuration options for KSP (e.g., K, cost constraints).
89+
//
90+
// Returns:
91+
// A vector of pairs, each representing a path:
92+
// - A vector of costs along the path.
93+
// - A predecessor DAG representing the path.
5194
[[nodiscard]] virtual std::vector<std::pair<std::vector<Cost>, PredDAG>> ksp(
5295
const GraphHandle& gh, NodeId src, NodeId dst, const KspOptions& opts) = 0;
5396

97+
// Computes maximum flow for a batch of source-destination pairs.
98+
//
99+
// Arguments:
100+
// gh: The graph handle.
101+
// pairs: A vector of (source, destination) pairs.
102+
// opts: Common configuration options for all pairs.
103+
// node_masks: Optional vector of node masks, one per pair.
104+
// edge_masks: Optional vector of edge masks, one per pair.
105+
//
106+
// Returns:
107+
// A vector of FlowSummary structs, one for each pair.
54108
[[nodiscard]] virtual std::vector<FlowSummary> batch_max_flow(
55109
const GraphHandle& gh,
56110
const std::vector<std::pair<NodeId,NodeId>>& pairs,
57111
const MaxFlowOptions& opts,
58112
const std::vector<std::span<const bool>>& node_masks = {},
59113
const std::vector<std::span<const bool>>& edge_masks = {}) = 0;
60114

115+
// Performs sensitivity analysis to identify edges that constrain flow.
116+
//
117+
// Arguments:
118+
// gh: The graph handle.
119+
// src: The source node ID.
120+
// dst: The destination node ID.
121+
// opts: Configuration options.
122+
//
123+
// Returns:
124+
// A vector of pairs (EdgeId, Flow gain), indicating how much flow would
125+
// increase if the edge's capacity were relaxed.
61126
[[nodiscard]] virtual std::vector<std::pair<EdgeId, Flow>> sensitivity_analysis(
62127
const GraphHandle& gh, NodeId src, NodeId dst, const MaxFlowOptions& opts) = 0;
63128
};

0 commit comments

Comments
 (0)