diff --git a/backend/app/__pycache__/main.cpython-310.pyc b/backend/app/__pycache__/main.cpython-310.pyc index 21f3cee..cd67059 100644 Binary files a/backend/app/__pycache__/main.cpython-310.pyc and b/backend/app/__pycache__/main.cpython-310.pyc differ diff --git a/backend/app/main.py b/backend/app/main.py index 84b3141..d7e153c 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -5,8 +5,8 @@ from fastapi import FastAPI app = FastAPI() -@app.get("/optimize/{max_steps}/{print_to_console}") -def main(max_steps: int, print_to_console: bool): +@app.get("/optimize/{max_steps}/{print_details}") +def main(max_steps: int, print_details: bool): # CONSTRAINT TO RESPECT MAX NUMBER OF STEPS #max_steps = 16 @@ -23,7 +23,7 @@ def main(max_steps: int, print_to_console: bool): landmarks.append(landmark("arrivée", -1, (0, 0))) - visiting_order = solve_optimization(landmarks, max_steps, print_to_console) + visiting_order = solve_optimization(landmarks, max_steps, print_details) #return visiting_order diff --git a/backend/app/src/__pycache__/optimizer.cpython-310.pyc b/backend/app/src/__pycache__/optimizer.cpython-310.pyc index 55a6337..e60b82c 100644 Binary files a/backend/app/src/__pycache__/optimizer.cpython-310.pyc and b/backend/app/src/__pycache__/optimizer.cpython-310.pyc differ diff --git a/backend/app/src/optimizer.py b/backend/app/src/optimizer.py index 4c1b631..2681469 100644 --- a/backend/app/src/optimizer.py +++ b/backend/app/src/optimizer.py @@ -261,7 +261,7 @@ def path_length(P: list, resx: list) : return np.dot(P, resx) # Main optimization pipeline -def solve_optimization (landmarks, max_steps, printing_console) : +def solve_optimization (landmarks, max_steps, printing_details) : # SET CONSTRAINTS FOR INEQUALITY c, A_ub, b_ub = init_ub_dist(landmarks, max_steps) # Add the distances from each landmark to the other @@ -283,15 +283,7 @@ def solve_optimization (landmarks, max_steps, printing_console) : # Solve linear programming problem res = linprog(c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq = b_eq, bounds=x_bounds, method='highs', integrality=3) - circle = has_circle(res.x) - i = 0 - - # Break the circular symmetry if needed - while len(circle) != 0 : - A_ub, b_ub = break_circle(landmarks, A_ub, b_ub, circle) - res = linprog(c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq = b_eq, bounds=x_bounds, method='highs', integrality=3) - circle = has_circle(res.x) - i += 1 + # Raise error if no solution is found @@ -305,16 +297,29 @@ def solve_optimization (landmarks, max_steps, printing_console) : res = linprog(c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq = b_eq, bounds=x_bounds, method='highs', integrality=3) if not res.success : - raise ValueError("No solution could be found, even when increasing max_steps using the heuristic") + s = "No solution could be found, even when increasing max_steps using the heuristic" + return s + #raise ValueError("No solution could be found, even when increasing max_steps using the heuristic") + # If there is a solution, we're good to go, just check for + else : + circle = has_circle(res.x) + i = 0 - if printing_console is True : - if i != 0 : - print(f"Neded to recompute paths {i} times because of unconnected loops...") + # Break the circular symmetry if needed + while len(circle) != 0 : + A_ub, b_ub = break_circle(landmarks, A_ub, b_ub, circle) + res = linprog(c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq = b_eq, bounds=x_bounds, method='highs', integrality=3) + circle = has_circle(res.x) + i += 1 + + if printing_details is True : + if i != 0 : + print(f"Neded to recompute paths {i} times because of unconnected loops...") X = print_res(res, landmarks, P) return X - else : - return untangle(res.x) + else : + return untangle(res.x)