Какой же я дурак, надо было просто увеличить количество популяции и все заработало....
This commit is contained in:
parent
2d83c5c9ed
commit
f6685b2d82
@ -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):
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user