From f6685b2d82850ef6a68cdd4606131dd140493e9e Mon Sep 17 00:00:00 2001 From: maksim Date: Wed, 5 Jun 2024 20:30:30 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=B0=D0=BA=D0=BE=D0=B9=20=D0=B6=D0=B5?= =?UTF-8?q?=20=D1=8F=20=D0=B4=D1=83=D1=80=D0=B0=D0=BA,=20=D0=BD=D0=B0?= =?UTF-8?q?=D0=B4=D0=BE=20=D0=B1=D1=8B=D0=BB=D0=BE=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=BE=20=D1=83=D0=B2=D0=B5=D0=BB=D0=B8=D1=87=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BA=D0=BE=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=BE=20=D0=BF=D0=BE=D0=BF=D1=83=D0=BB=D1=8F=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=B8=20=D0=B2=D1=81=D0=B5=20=D0=B7=D0=B0=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=BB=D0=BE....?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- genetic_algorithm/genetic_algorithm.py | 4 ++-- router_class.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) 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