This commit is contained in:
parent
101af0ebc6
commit
70cebc0aa1
Binary file not shown.
@ -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
|
||||
|
||||
|
Binary file not shown.
@ -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)
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user