-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph_node.py
45 lines (35 loc) · 1.2 KB
/
graph_node.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
43
44
45
import numpy as np;
class node:
def __init__(self, neighbors, costs, position):
self.neighbors = neighbors;
self.costs = costs;
self.position = position;
self.parent = None;
self.g = float('Inf'); #cost of the path from the start node to this node
self.h = None; #estimated cost from this node to the end node
self.dimension = len(position);
def get_pos(self):
return self.position;
def get_costs(self):
return self.costs;
def get_neighbors(self):
return self.neighbors;
def get_parent(self):
return self.parent;
def set_parent(self, parent):
self.parent = parent;
return self.parent;
def set_g(self, g):
self.g = g;
return self.g;
def get_g(self):
return self.g;
def calculate_h(self, end_node_position):
if self.h == None:
result = 0;
for i in range(0,self.dimension):
result += (np.abs(self.position[i] - end_node_position[i])); #manhattan distance
self.h = result;
return self.h;
def calc_f(self, end_node_position):
return self.calculate_h(end_node_position) + self.g;