diff --git a/genetic_algorithm/genetic_algorithm.py b/genetic_algorithm/genetic_algorithm.py index bd2b30e..35d3fa2 100644 --- a/genetic_algorithm/genetic_algorithm.py +++ b/genetic_algorithm/genetic_algorithm.py @@ -91,7 +91,7 @@ def path_length_and_time(path, graph): return length, start_time, end_time -def generate_population(size, start, end, graph, max_attempts=1000): +def generate_population(size, start, end, graph, max_attempts=100): population = [] for i in range(size): attempts = 0 @@ -150,7 +150,7 @@ def update_best_paths(best_paths, path, graph, max_best_paths=3): del best_paths[worst_path] -def genetic_algorithm(start, end, graph, flights_data, type, population_size=100, generations=100): +def genetic_algorithm(start, end, graph, flights_data, type, population_size=1000, generations=100): population = generate_population(population_size, start, end, graph) best_paths = {} # Словарь для хранения уникальных лучших маршрутов и их длин for generation in range(generations): diff --git a/router_class.py b/router_class.py index c14abc2..e05c8d6 100644 --- a/router_class.py +++ b/router_class.py @@ -27,6 +27,16 @@ async def get_flight(request: TripRequest): if not request.returnDate: resultTo = genetic_algorithm(start=start_point, end=end_point, graph=graphTo, flights_data=flightsDataTo, type="to") + resultTo.append({ + "back": [ + { + "id": None, + "departurePoint": None, + "destinationPoint": None + } + ] + }) + if not resultTo: raise HTTPException(status_code=404, detail="No valid paths found") return resultTo