-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapproximateCost.py
45 lines (36 loc) · 1.19 KB
/
approximateCost.py
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
import numpy as np
def approx_distances(maze, target_x, target_y):
penalty = 0
slope=0
adj = {}
for i in range(len(target_x)):
adj[i] = []
for i in range(len(target_x)):
x1 = target_x[i]
y1 = target_y[i]
for j in range(len(target_x)):
x1 = target_x[i]
y1 = target_y[i]
x2 = target_x[j]
y2 = target_y[j]
dist = ((x2 - x1)**2 + (y2 - y1)**2)**(1/2)
sample_points = []
if x2 - x1 != 0 and (y2-y1 > 60 or x2-x1 > 60):
rise, run = (y2-y1)//15, (x2-x1)//15
x1 += run
y1 += rise
for k in range(15):
if(maze[y1][x1] != np.inf):
sample_points.append(maze[y1][x1])
x1 += run
y1 += rise
if len(sample_points) >= 1:
average = sum(sample_points)/len(sample_points)
adj[i].append((j, dist))
else:
adj[i].append((j, dist))
else:
adj[i].append((j, dist))
for key in adj.keys():
print(key, adj[key])
return adj