Skip to content

Commit be2b993

Browse files
Better solve statistics
1 parent 699aa71 commit be2b993

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

examples/cycles_demo.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def test_min_flow_decomp(filename: str):
1818
"pathwidth": 2,
1919
})
2020

21+
print(graph.graph["n"], graph.graph["m"], graph.graph["w"])
22+
2123
mfd_model = fp.MinFlowDecompCycles(
2224
G=graph,
2325
flow_attr="flow",
@@ -137,9 +139,11 @@ def process_solution(model):
137139
print("solve_time:", solve_statistics['solve_time']) # time taken by the ILP for a given k, or by MFD to iterate through k and do small internal things
138140
print("number_of_nontrivial_SCCs:", solve_statistics['number_of_nontrivial_SCCs']) # trivial = at least one edge
139141
print("size_of_largest_SCC:", solve_statistics['size_of_largest_SCC']) # size = number of edges
142+
print("avg_size_of_non_trivial_SCC:", solve_statistics['avg_size_of_non_trivial_SCC']) # size = number of edges
140143

141144
def main():
142-
test_min_flow_decomp(filename = "tests/cyclic_graphs/gt5.kmer27.(655000.660000).V18.E27.mincyc4.graph")
145+
test_min_flow_decomp(filename = "tests/cyclic_graphs/gt3.kmer15.(130000.132000).V23.E32.cyc100.graph")
146+
test_min_flow_decomp(filename = "tests/cyclic_graphs/gt5.kmer27.(655000.660000).V18.E27.mincyc4.e0.75.graph")
143147
test_least_abs_errors(filename = "tests/cyclic_graphs/gt5.kmer27.(655000.660000).V18.E27.mincyc4.e0.75.graph")
144148
test_min_path_error(filename = "tests/cyclic_graphs/gt5.kmer27.(655000.660000).V18.E27.mincyc4.e0.75.graph")
145149

flowpaths/abstractwalkmodeldigraph.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ def solve(self) -> bool:
455455
self.solve_statistics[f"solve_time"] = time.perf_counter() - start_time
456456
self.solve_statistics[f"model_status"] = self.solver.get_model_status()
457457
self.solve_statistics[f"number_of_nontrivial_SCCs"] = self.G.get_number_of_nontrivial_SCCs()
458+
self.solve_statistics[f"avg_size_of_non_trivial_SCC"] = self.G.get_avg_size_of_non_trivial_SCC()
458459
self.solve_statistics[f"size_of_largest_SCC"] = self.G.get_size_of_largest_SCC()
459460

460461
if self.solver.get_model_status() == "kOptimal" or self.solver.get_model_status() == 2:

flowpaths/minflowdecompcycles.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def solve(self) -> bool:
231231
solver_options=fd_solver_options,
232232
)
233233
fd_model.solve()
234+
self.solve_statistics = fd_model.solve_statistics
234235

235236
# If the previous run exceeded the time limit,
236237
# we still stop the search, even if we might have managed to solve it
@@ -251,8 +252,10 @@ def solve(self) -> bool:
251252
self.fd_model = fd_model
252253
return True
253254
elif fd_model.solver.get_model_status() == sw.SolverWrapper.infeasible_status:
255+
self.solve_statistics = fd_model.solve_statistics
254256
utils.logger.info(f"{__name__}: model is infeasible for k = {i}")
255257
else:
258+
self.solve_statistics = fd_model.solve_statistics
256259
# If the model is not solved and the status is not infeasible,
257260
# it means that the solver stopped because of an unexpected termination,
258261
# thus we cannot conclude that the model is infeasible.

flowpaths/stdigraph.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,13 @@ def get_size_of_largest_SCC(self) -> int:
309309
Returns the size of the largest SCC (in terms of number of edges).
310310
"""
311311
return max((len(self._condensation.graph['member_edges'][str(v)]) for v in self._condensation.nodes()), default=0)
312+
313+
def get_avg_size_of_non_trivial_SCC(self) -> int:
314+
"""
315+
Returns the average size (in terms of number of edges) of non-trivial SCCs (i.e. SCCs with at least one edge).
316+
"""
317+
sizes = [len(self._condensation.graph['member_edges'][str(v)]) for v in self._condensation.nodes() if len(self._condensation.graph['member_edges'][str(v)]) > 0]
318+
return sum(sizes) // len(sizes) if sizes else 0
312319

313320
def get_longest_incompatible_sequences(self, sequences: list) -> list:
314321

0 commit comments

Comments
 (0)