added dataclass
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
				
			|||||||
from src.optimizer import solve_optimization
 | 
					from src.optimizer import solve_optimization
 | 
				
			||||||
from src.optimizer import landmark
 | 
					from src.optimizer import Landmark
 | 
				
			||||||
from fastapi import FastAPI
 | 
					from fastapi import FastAPI
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app = FastAPI()
 | 
					app = FastAPI()
 | 
				
			||||||
@@ -12,18 +12,18 @@ def main(max_steps: int, print_details: bool):
 | 
				
			|||||||
    #max_steps = 16
 | 
					    #max_steps = 16
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Initialize all landmarks (+ start and goal). Order matters here
 | 
					    # Initialize all Landmarks (+ start and goal). Order matters here
 | 
				
			||||||
    landmarks = []
 | 
					    Landmarks = []
 | 
				
			||||||
    landmarks.append(landmark("départ", -1, (0, 0)))
 | 
					    Landmarks.append(Landmark("départ", -1, (0, 0)))
 | 
				
			||||||
    landmarks.append(landmark("tour eiffel", 99, (0,2)))                           # PUT IN JSON
 | 
					    Landmarks.append(Landmark("tour eiffel", 99, (0,2)))                           # PUT IN JSON
 | 
				
			||||||
    landmarks.append(landmark("arc de triomphe", 99, (0,4)))
 | 
					    Landmarks.append(Landmark("arc de triomphe", 99, (0,4)))
 | 
				
			||||||
    landmarks.append(landmark("louvre", 99, (0,6)))
 | 
					    Landmarks.append(Landmark("louvre", 99, (0,6)))
 | 
				
			||||||
    landmarks.append(landmark("montmartre", 99, (0,10)))
 | 
					    Landmarks.append(Landmark("montmartre", 99, (0,10)))
 | 
				
			||||||
    landmarks.append(landmark("concorde", 99, (0,8)))
 | 
					    Landmarks.append(Landmark("concorde", 99, (0,8)))
 | 
				
			||||||
    landmarks.append(landmark("arrivée", -1, (0, 0)))
 | 
					    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
 | 
					    #return visiting_order
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,14 +1,15 @@
 | 
				
			|||||||
from scipy.optimize import linprog
 | 
					from scipy.optimize import linprog
 | 
				
			||||||
import numpy as np
 | 
					import numpy as np
 | 
				
			||||||
from scipy.linalg import block_diag
 | 
					from scipy.linalg import block_diag
 | 
				
			||||||
 | 
					from dataclasses import dataclass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Defines the landmark class (aka some place there is to visit)
 | 
					# Defines the landmark class (aka some place there is to visit)
 | 
				
			||||||
class landmark :
 | 
					@dataclass
 | 
				
			||||||
    def __init__(self, name: str, attractiveness: int, loc: tuple):
 | 
					class Landmark :
 | 
				
			||||||
        self.name = name
 | 
					    name : str
 | 
				
			||||||
        self.attractiveness = attractiveness
 | 
					    attractiveness : int
 | 
				
			||||||
        self.loc = loc
 | 
					    loc : tuple
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Convert the solution of the optimization into the list of edges to follow. Order is taken into account
 | 
					# Convert the solution of the optimization into the list of edges to follow. Order is taken into account
 | 
				
			||||||
def untangle(resx: list) :
 | 
					def untangle(resx: list) :
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user