(start: TPos, goal: TPos, n_heuristic: int)
| 234 | |
| 235 | |
| 236 | def multi_a_star(start: TPos, goal: TPos, n_heuristic: int): |
| 237 | g_function = {start: 0, goal: float("inf")} |
| 238 | back_pointer = {start: -1, goal: -1} |
| 239 | open_list = [] |
| 240 | visited = set() |
| 241 | |
| 242 | for i in range(n_heuristic): |
| 243 | open_list.append(PriorityQueue()) |
| 244 | open_list[i].put(start, key(start, i, goal, g_function)) |
| 245 | |
| 246 | close_list_anchor: list[int] = [] |
| 247 | close_list_inad: list[int] = [] |
| 248 | while open_list[0].minkey() < float("inf"): |
| 249 | for i in range(1, n_heuristic): |
| 250 | # print(open_list[0].minkey(), open_list[i].minkey()) |
| 251 | if open_list[i].minkey() <= W2 * open_list[0].minkey(): |
| 252 | global t |
| 253 | t += 1 |
| 254 | if g_function[goal] <= open_list[i].minkey(): |
| 255 | if g_function[goal] < float("inf"): |
| 256 | do_something(back_pointer, goal, start) |
| 257 | else: |
| 258 | _, get_s = open_list[i].top_show() |
| 259 | visited.add(get_s) |
| 260 | expand_state( |
| 261 | get_s, |
| 262 | i, |
| 263 | visited, |
| 264 | g_function, |
| 265 | close_list_anchor, |
| 266 | close_list_inad, |
| 267 | open_list, |
| 268 | back_pointer, |
| 269 | ) |
| 270 | close_list_inad.append(get_s) |
| 271 | elif g_function[goal] <= open_list[0].minkey(): |
| 272 | if g_function[goal] < float("inf"): |
| 273 | do_something(back_pointer, goal, start) |
| 274 | else: |
| 275 | get_s = open_list[0].top_show() |
| 276 | visited.add(get_s) |
| 277 | expand_state( |
| 278 | get_s, |
| 279 | 0, |
| 280 | visited, |
| 281 | g_function, |
| 282 | close_list_anchor, |
| 283 | close_list_inad, |
| 284 | open_list, |
| 285 | back_pointer, |
| 286 | ) |
| 287 | close_list_anchor.append(get_s) |
| 288 | print("No path found to goal") |
| 289 | print() |
| 290 | for i in range(n - 1, -1, -1): |
| 291 | for j in range(n): |
| 292 | if (j, i) in blocks: |
| 293 | print("#", end=" ") |
no test coverage detected