included fastapi
Some checks failed
Test code / Test code (push) Failing after 3s

This commit is contained in:
Kilian Scheidecker 2024-05-22 15:01:46 +02:00
parent 2b31ce5f6b
commit 101af0ebc6
10 changed files with 19 additions and 10 deletions

0
backend/app/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
import app.src

View File

@ -1,10 +1,15 @@
from optimizer import solve_optimization
from optimizer import landmark
from src.optimizer import solve_optimization
from src.optimizer import landmark
from fastapi import FastAPI
def main():
app = FastAPI()
@app.get("/optimize/{max_steps}/{print_to_console}")
def main(max_steps: int, print_to_console: bool):
# CONSTRAINT TO RESPECT MAX NUMBER OF STEPS
max_steps = 16
#max_steps = 16
# Initialize all landmarks (+ start and goal). Order matters here
@ -18,8 +23,11 @@ def main():
landmarks.append(landmark("arrivée", -1, (0, 0)))
visiting_order = solve_optimization(landmarks, max_steps, True)
visiting_order = solve_optimization(landmarks, max_steps, print_to_console)
#return visiting_order
return("max steps :", max_steps, "\n", visiting_order)
if __name__ == "__main__":

View File

Binary file not shown.

View File

@ -10,7 +10,6 @@ class landmark :
self.attractiveness = attractiveness
self.loc = loc
# Convert the solution of the optimization into the list of edges to follow. Order is taken into account
def untangle(resx: list) :
N = len(resx) # length of res
@ -43,6 +42,7 @@ def untangle(resx: list) :
def print_res(res, landmarks: list, P) :
X = abs(res.x)
order = untangle(X)
things = []
"""N = int(np.sqrt(len(X)))
for i in range(N):
@ -59,11 +59,12 @@ def print_res(res, landmarks: list, P) :
for idx in order :
print('- ' + landmarks[idx].name)
things.append(landmarks[idx].name)
steps = path_length(P, abs(res.x))
print("\nSteps walked : " + str(steps))
return order
return things
# Checks for cases of circular symmetry in the result
def has_circle(resx: list) :
@ -260,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) :
def solve_optimization (landmarks, max_steps, printing_console) :
# SET CONSTRAINTS FOR INEQUALITY
c, A_ub, b_ub = init_ub_dist(landmarks, max_steps) # Add the distances from each landmark to the other
@ -307,12 +308,11 @@ def solve_optimization (landmarks, max_steps, printing) :
raise ValueError("No solution could be found, even when increasing max_steps using the heuristic")
if printing is True :
if printing_console 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)