This commit is contained in:
parent
2b31ce5f6b
commit
101af0ebc6
0
backend/app/__init__.py
Normal file
0
backend/app/__init__.py
Normal file
BIN
backend/app/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
backend/app/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/app/__pycache__/main.cpython-310.pyc
Normal file
BIN
backend/app/__pycache__/main.cpython-310.pyc
Normal file
Binary file not shown.
1
backend/app/dependencies.py
Normal file
1
backend/app/dependencies.py
Normal file
@ -0,0 +1 @@
|
||||
import app.src
|
@ -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__":
|
0
backend/app/src/__init__.py
Normal file
0
backend/app/src/__init__.py
Normal file
BIN
backend/app/src/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
backend/app/src/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user