diff --git a/backend/app/__init__.py b/backend/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/app/__pycache__/__init__.cpython-310.pyc b/backend/app/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..678d7d0 Binary files /dev/null and b/backend/app/__pycache__/__init__.cpython-310.pyc differ diff --git a/backend/app/__pycache__/main.cpython-310.pyc b/backend/app/__pycache__/main.cpython-310.pyc new file mode 100644 index 0000000..21f3cee Binary files /dev/null and b/backend/app/__pycache__/main.cpython-310.pyc differ diff --git a/backend/app/dependencies.py b/backend/app/dependencies.py new file mode 100644 index 0000000..2cb6801 --- /dev/null +++ b/backend/app/dependencies.py @@ -0,0 +1 @@ +import app.src \ No newline at end of file diff --git a/backend/src/main.py b/backend/app/main.py similarity index 59% rename from backend/src/main.py rename to backend/app/main.py index 772daca..84b3141 100644 --- a/backend/src/main.py +++ b/backend/app/main.py @@ -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__": diff --git a/backend/app/src/__init__.py b/backend/app/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/app/src/__pycache__/__init__.cpython-310.pyc b/backend/app/src/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..3c06a08 Binary files /dev/null and b/backend/app/src/__pycache__/__init__.cpython-310.pyc differ diff --git a/backend/src/__pycache__/optimizer.cpython-310.pyc b/backend/app/src/__pycache__/optimizer.cpython-310.pyc similarity index 51% rename from backend/src/__pycache__/optimizer.cpython-310.pyc rename to backend/app/src/__pycache__/optimizer.cpython-310.pyc index 2446c04..55a6337 100644 Binary files a/backend/src/__pycache__/optimizer.cpython-310.pyc and b/backend/app/src/__pycache__/optimizer.cpython-310.pyc differ diff --git a/backend/src/main_example.py b/backend/app/src/main_example.py similarity index 100% rename from backend/src/main_example.py rename to backend/app/src/main_example.py diff --git a/backend/src/optimizer.py b/backend/app/src/optimizer.py similarity index 98% rename from backend/src/optimizer.py rename to backend/app/src/optimizer.py index 66efaeb..4c1b631 100644 --- a/backend/src/optimizer.py +++ b/backend/app/src/optimizer.py @@ -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)