-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolutions.py
More file actions
71 lines (54 loc) · 1.72 KB
/
Solutions.py
File metadata and controls
71 lines (54 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import math
import heapq
import typing as tp
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from time import time
from PIL import Image, ImageDraw
from heapq import heappop, heappush
from astar import Node
def make_path(goal):
'''
Creates a path by tracing parent pointers from the goal node to the start node
It also returns path's length.
'''
length = goal.f
current = goal
path = []
while current.parent:
path.append(current)
current = current.parent
path.append(current)
return path[::-1], length
class Solutions:
def __init__(self):
self.solutions = []
def add_solution(self, find, end, steps, abandoned: tp.List[Node] = []):
self.solutions.append(Solution(find, end, steps, abandoned))
def upgrade_solution(self, index, find, end, steps, abandoned: tp.List[Node] = []):
self.solutions[index] = Solution(find, end, steps, abandoned)
def get_solution_of_robot(self, index):
return self.solutions[index]
def __repr__(self) -> str:
for solution in self.solutions:
print(solution.get_path())
class Solution:
def __init__(self, find, end, steps, abandoned: tp.List[Node] = []):
self._find = find
self._end = end
self._steps = steps
self._abandoned = abandoned
self._sneakyMdd = None # there IS none
def find(self):
return self._find
def get_path(self):
path, _ = make_path(self._end)
return path
def steps(self):
return self._steps
def get_cost(self):
return self._end.time
def remember_the_past(self):
return self._abandoned