From 70cebc0aa19f900cac6bf0bca8cee79fd2e9934a Mon Sep 17 00:00:00 2001 From: Kilian Scheidecker Date: Wed, 22 May 2024 15:12:54 +0200 Subject: [PATCH] fixed return order --- backend/app/__pycache__/main.cpython-310.pyc | Bin 986 -> 980 bytes backend/app/main.py | 6 +-- .../src/__pycache__/optimizer.cpython-310.pyc | Bin 6114 -> 6107 bytes backend/app/src/optimizer.py | 37 ++++++++++-------- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/backend/app/__pycache__/main.cpython-310.pyc b/backend/app/__pycache__/main.cpython-310.pyc index 21f3cee4583cade7331b40935c4fb79e719f22cd..cd67059540ba463b9a64189908a944b49246cc02 100644 GIT binary patch delta 66 zcmcb`eubSkpO=@50SIK@`lcyPjgtKMLwkLi8h$aPh;`n;*bWK#XtdpTT2xD#rNPUzW?DI1lpg@nR07Hy4*Ft+=!aSbM zk98$aG3_(W`pibuiwnqW+Rvr+u~vZg$HIKG64}h7R(Q0>%PV&BAKSSJN*%1Re~q#; zi(=&L9Im`yRJRem9Ig^Et9{XMDAI`NARH$XpOnuK9_zqncU znlGbyue@yTfGVfW2TzAVcCxp(pJnE;n^<>Pc6j3O&|%e~L+I2^*X6GWL-omwj_v69 z{X4yHcSna=`MUL}zDCkiobDb@Av0T4l-I50-Zmvlc%VQDDHcHSRJ1+6qJ#o|-WERh bfZ}%)c;NIlL=b|!5B-p4Bxw;Z!=>pTJ|}Fx delta 411 zcmYk1F-yZh6vyx7k~B?|^t4UQDmd7oRuHWeQ4|Xf3Ti$vAOCyrt@++`0^2r;eAk~lL$Chq99DpdVdZ`%GO%=7 zOd+v+EwLjVtrUE1M0p&UNKi!$EfH0xJAWS9zTP7L-EdEKl)}fzLM??&a$+4TiJds; zAdD1#gGJe5uaI*TSoOAkW!o>La0RINMojpttj)iDi5$O(_5<COaMto!OCqBey|K8hH8xgdVpIhNj9PRO onBq`RH9>_ud0>J8)|YND%0RjFsIC}bP(%8bbkuKC6EKzi0M12SO8@`> 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)