ai-lab-one/main.py

36 lines
1.3 KiB
Python
Raw Normal View History

2023-02-12 16:48:56 +00:00
#!.venv/bin/python
# I am but a silly little NixOS user who cannot use normal shebangs
2023-02-11 22:08:26 +00:00
from emis_funky_funktions import *
from sys import argv
from operator import eq
2023-02-12 21:36:23 +00:00
from time import perf_counter_ns
2023-02-11 22:08:26 +00:00
2023-02-12 04:58:01 +00:00
from a_star import pathfind_multi
2023-02-12 16:10:07 +00:00
from read_in import load_points, load_world_from_paths
2023-02-11 22:08:26 +00:00
from world import Point, World
2023-02-12 04:58:01 +00:00
from write_out import save_map
2023-02-11 22:08:26 +00:00
2023-02-12 16:10:07 +00:00
def main(terrain_path: str, elevation_path: str, checkpoints_path: str, image_output: str):
2023-02-12 21:36:23 +00:00
start_time = perf_counter_ns()
2023-02-12 04:58:01 +00:00
world = unwrap_r(load_world_from_paths(terrain_path, elevation_path))
2023-02-12 16:10:07 +00:00
checkpoints = unwrap_r(load_points(checkpoints_path))
2023-02-12 21:36:23 +00:00
print('All files loaded, begining search...', end = ' ')
loaded_time = perf_counter_ns()
2023-02-12 04:58:01 +00:00
maybe_path = pathfind_multi(
world.neighbors,
world.heuristic,
2023-02-12 16:10:07 +00:00
checkpoints
2023-02-11 22:08:26 +00:00
)
2023-02-12 21:36:23 +00:00
finish_time = perf_counter_ns()
2023-02-12 04:58:01 +00:00
path, cost = unwrap_opt(maybe_path)
2023-02-12 21:36:23 +00:00
print(f'Path found!\n')
print(f'Loading resources completed in {(loaded_time - start_time) // 1_000_000}ms')
print(f'Search completed in {(finish_time - loaded_time) // 1_000_000}ms\n')
print(f'Estimated travel time: {cost//60_000_000} minutes')
2023-02-12 21:19:13 +00:00
path_length = unwrap_r(world.calculate_path_length(path))
2023-02-12 21:36:23 +00:00
print(f'Total path length: {path_length/1_000_000:.1f} kilometers')
2023-02-12 16:10:07 +00:00
save_map(image_output, world, path)
2023-02-11 22:08:26 +00:00
if __name__ == '__main__':
main(*argv[1:])