Skip to content

Commit

Permalink
replace second max_flow call with rust
Browse files Browse the repository at this point in the history
  • Loading branch information
ohjuny committed Oct 18, 2024
1 parent 5a7d108 commit 3e07341
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions lowtime/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ def reformat_rust_flow_to_dict(flow_vec: list[tuple[tuple[int, int], float]], da
"PROFILING PhillipsDessouky::find_min_cut maximum_flow_1 time: %.10fs",
profiling_max_flow,
)
# TODO(ohjun): replace to handle Rust-side pyo3 exception
except nx.NetworkXUnbounded as e:
raise LowtimeFlowError("ERROR: Infinite flow for unbounded DAG.") from e

Expand Down Expand Up @@ -559,19 +560,41 @@ def reformat_rust_flow_to_dict(flow_vec: list[tuple[tuple[int, int], float]], da

# Run max flow on the new residual graph.
try:
# profiling_max_flow = time.time()
# _, flow_dict = nx.maximum_flow(
# residual_graph,
# source_node,
# sink_node,
# capacity="capacity",
# flow_func=edmonds_karp,
# )
# profiling_max_flow = time.time() - profiling_max_flow
# logger.info(
# "PROFILING PhillipsDessouky::find_min_cut maximum_flow_2 time: %.10fs",
# profiling_max_flow,
# )
profiling_max_flow = time.time()
_, flow_dict = nx.maximum_flow(
residual_graph,
source_node,
sink_node,
capacity="capacity",
flow_func=edmonds_karp,
nodes, edges = format_rust_inputs(residual_graph)

profiling_data_transfer = time.time()
rust_dag = lowtime_rust.PhillipsDessouky(
nodes, source_node, sink_node, edges
)
profiling_data_transfer = time.time() - profiling_data_transfer
logger.info(
"PROFILING PhillipsDessouky::find_min_cut data transfer 2 time: %.10fs",
profiling_data_transfer,
)

rust_flow_vec = rust_dag.max_flow()
flow_dict = reformat_rust_flow_to_dict(rust_flow_vec, unbound_dag)

profiling_max_flow = time.time() - profiling_max_flow
logger.info(
"PROFILING PhillipsDessouky::find_min_cut maximum_flow_2 time: %.10fs",
profiling_max_flow,
)
# TODO(ohjun): replace to handle Rust-side pyo3 exception
except nx.NetworkXUnbounded as e:
raise LowtimeFlowError(
"ERROR: Infinite flow on capacity residual graph."
Expand Down

0 comments on commit 3e07341

Please sign in to comment.