UI elements using the new structs #8
@@ -1,5 +1,5 @@
 | 
			
		||||
from src.optimizer import solve_optimization
 | 
			
		||||
from src.optimizer import Landmark
 | 
			
		||||
from src.landmarks_manager import Landmark
 | 
			
		||||
from fastapi import FastAPI
 | 
			
		||||
 | 
			
		||||
app = FastAPI()
 | 
			
		||||
@@ -12,18 +12,18 @@ def main(max_steps: int, print_details: bool):
 | 
			
		||||
    #max_steps = 16
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # Initialize all Landmarks (+ start and goal). Order matters here
 | 
			
		||||
    Landmarks = []
 | 
			
		||||
    Landmarks.append(Landmark("départ", -1, (0, 0)))
 | 
			
		||||
    Landmarks.append(Landmark("tour eiffel", 99, (0,2)))                           # PUT IN JSON
 | 
			
		||||
    Landmarks.append(Landmark("arc de triomphe", 99, (0,4)))
 | 
			
		||||
    Landmarks.append(Landmark("louvre", 99, (0,6)))
 | 
			
		||||
    Landmarks.append(Landmark("montmartre", 99, (0,10)))
 | 
			
		||||
    Landmarks.append(Landmark("concorde", 99, (0,8)))
 | 
			
		||||
    Landmarks.append(Landmark("arrivée", -1, (0, 0)))
 | 
			
		||||
    # Initialize all landmarks (+ start and goal). Order matters here
 | 
			
		||||
    landmarks = []
 | 
			
		||||
    landmarks.append(Landmark("départ", -1, (0, 0)))
 | 
			
		||||
    landmarks.append(Landmark("tour eiffel", 99, (0,2)))                           # PUT IN JSON
 | 
			
		||||
    landmarks.append(Landmark("arc de triomphe", 99, (0,4)))
 | 
			
		||||
    landmarks.append(Landmark("louvre", 99, (0,6)))
 | 
			
		||||
    landmarks.append(Landmark("montmartre", 99, (0,10)))
 | 
			
		||||
    landmarks.append(Landmark("concorde", 99, (0,8)))
 | 
			
		||||
    landmarks.append(Landmark("arrivée", -1, (0, 0)))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    visiting_order = solve_optimization(Landmarks, max_steps, print_details)
 | 
			
		||||
    visiting_order = solve_optimization(landmarks, max_steps, print_details)
 | 
			
		||||
 | 
			
		||||
    #return visiting_order
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										52
									
								
								backend/app/src/landmarks_manager.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								backend/app/src/landmarks_manager.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,52 @@
 | 
			
		||||
from OSMPythonTools.api import Api
 | 
			
		||||
from OSMPythonTools.overpass import Overpass
 | 
			
		||||
from dataclasses import dataclass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Defines the landmark class (aka some place there is to visit)
 | 
			
		||||
@dataclass
 | 
			
		||||
class Landmark :
 | 
			
		||||
    name : str
 | 
			
		||||
    attractiveness : int
 | 
			
		||||
    id : int
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Converts a OSM id to a landmark
 | 
			
		||||
def add_from_id(id: int, score: int) :
 | 
			
		||||
 | 
			
		||||
    try :
 | 
			
		||||
        s = 'way/' + str(id)           # prepare string for query
 | 
			
		||||
        obj =  api.query(s)                             # object to add
 | 
			
		||||
    except :
 | 
			
		||||
        s = 'relation/' + str(id)           # prepare string for query
 | 
			
		||||
        obj =  api.query(s)                             # object to add
 | 
			
		||||
 | 
			
		||||
    return Landmark(obj.tag('name:fr'), score, id)      # create Landmark out of it
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# take a lsit of tuples (id, score) to generate a list of landmarks
 | 
			
		||||
def generate_landmarks(ids_and_scores: list) :
 | 
			
		||||
 | 
			
		||||
    L = []
 | 
			
		||||
    for tup in ids_and_scores :
 | 
			
		||||
        L.append(add_from_id(tup[0], tup[1]))
 | 
			
		||||
 | 
			
		||||
    return L
 | 
			
		||||
 | 
			
		||||
api = Api()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
l = (7515426, 70)
 | 
			
		||||
t = (5013364, 100)
 | 
			
		||||
n = (201611261, 99)
 | 
			
		||||
a = (226413508, 50)
 | 
			
		||||
m = (23762981, 30)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
ids_and_scores = [t, l, n, a, m]
 | 
			
		||||
 | 
			
		||||
landmarks = generate_landmarks(ids_and_scores)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
for obj in landmarks :
 | 
			
		||||
    print(obj)
 | 
			
		||||
@@ -1,15 +1,9 @@
 | 
			
		||||
from scipy.optimize import linprog
 | 
			
		||||
import numpy as np
 | 
			
		||||
from scipy.linalg import block_diag
 | 
			
		||||
from dataclasses import dataclass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Defines the landmark class (aka some place there is to visit)
 | 
			
		||||
@dataclass
 | 
			
		||||
class Landmark :
 | 
			
		||||
    name : str
 | 
			
		||||
    attractiveness : int
 | 
			
		||||
    loc : tuple
 | 
			
		||||
# landmarks = [Landmark_1, Landmark_2, ...]
 | 
			
		||||
 | 
			
		||||
# Convert the solution of the optimization into the list of edges to follow. Order is taken into account
 | 
			
		||||
def untangle(resx: list) :
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user