# 1. define node class |
class Node: |
def __init__(self, position, parent=None): |
# 2. Define heuristic functions |
def heuristic(node, goal): |
# 3. Get a neighbor node |
def get_neighbors(node, grid, goal, mode): |
# 4. Define a two-way A* search |
def a_star_bidirectional(start, goal, grid, connectivity = 8): |
# 5. Check if the paths meet and merge the paths |
def meet_in_the_middle(): |
# 6. Read map data from an Excel file |
def read_data_from_excel(file_path): |
# 7. Optimize the path |
def optimize_path(path, grid, goal): |
# 8. Draw maps and routes |
def plot_grid(grid, search_start, search_goal, path1, path2, start, goal): |
# Main process |
file_path = ‘map_model.xlsx’ |
grid, start, goal = read_data_from_excel(file_path) |
path1, path2, search_path_start, search_path_goal = a_star_bidirectional(start, goal, grid) |
optimized_path = optimize_path(path1 + path2, grid, goal) |
plot_grid(grid, search_path_start, search_path_goal, optimized_path, [], start, goal) |