Skip to content

Commit

Permalink
Add timeout to solve functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cmalinmayor committed Aug 21, 2024
1 parent a30c621 commit 582e903
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def solve_basic_optimization(cand_graph):
cand_trackgraph = motile.TrackGraph(cand_graph, frame_attribute="t")
solver = motile.Solver(cand_trackgraph)
### YOUR CODE HERE ###
solver.solve()
solver.solve(timeout=120)
solution_graph = graph_to_nx(solver.get_selected_subgraph())

return solution_graph
Expand Down Expand Up @@ -505,7 +505,7 @@ def solve_basic_optimization(cand_graph):
solver.add_constraint(motile.constraints.MaxParents(1))
solver.add_constraint(motile.constraints.MaxChildren(2))

solver.solve()
solver.solve(timeout=120)
solution_graph = graph_to_nx(solver.get_selected_subgraph())
return solution_graph

Expand All @@ -526,6 +526,8 @@ def print_graph_stats(graph, name):
#
#
# Our integer linear program (ILP) tries to use the proprietary solver Gurobi. You probably don't have a license, in which case the ILP will fall back to the open source solver SCIP.
#
# SCIP is slower than Gurobi - to deal with this, we add a 120 second timeout to the solve call, which should approximate the truly optimal solution. For larger problems, or cases where getting the most optimal solution is crucial, one could increase the timeout or get a Gurobi license (recommended).
# </div>

# %%
Expand Down Expand Up @@ -727,7 +729,7 @@ def adapt_basic_optimization(cand_graph):
cand_trackgraph = motile.TrackGraph(cand_graph, frame_attribute="t")
solver = motile.Solver(cand_trackgraph)
### YOUR CODE HERE ###
solver.solve()
solver.solve(timeout=120)
solution_graph = graph_to_nx(solver.get_selected_subgraph())

return solution_graph
Expand Down Expand Up @@ -772,7 +774,7 @@ def adapt_basic_optimization(cand_graph):

solver.add_constraint(motile.constraints.MaxParents(1))
solver.add_constraint(motile.constraints.MaxChildren(2))
solver.solve()
solver.solve(timeout=120)
solution_graph = graph_to_nx(solver.get_selected_subgraph())

return solution_graph
Expand Down Expand Up @@ -866,7 +868,7 @@ def solve_drift_optimization(cand_graph):

### YOUR CODE HERE ###

solver.solve()
solver.solve(timeout=120)

solution_graph = graph_to_nx(solver.get_selected_subgraph())
return solution_graph
Expand Down Expand Up @@ -914,7 +916,7 @@ def solve_drift_optimization(cand_graph):
solver.add_constraint(motile.constraints.MaxParents(1))
solver.add_constraint(motile.constraints.MaxChildren(2))

solver.solve()
solver.solve(timeout=120)
solution_graph = graph_to_nx(solver.get_selected_subgraph())
return solution_graph

Expand Down Expand Up @@ -1054,7 +1056,7 @@ def get_ssvm_solver(cand_graph):
def get_ssvm_solution(cand_graph, solver_weights):
solver = get_ssvm_solver(cand_graph)
solver.weights = solver_weights
solver.solve()
solver.solve(timeout=120)
solution_graph = graph_to_nx(solver.get_selected_subgraph())
return solution_graph

Expand Down

0 comments on commit 582e903

Please sign in to comment.