-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnode.py
59 lines (47 loc) · 1.36 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Node:
"""
Node class based on the book "Inteligencia Artificial. Fundamentos,
práctica y aplicaciones", 2nd. Edition, by Alberto García Serrano.
"""
def __init__(self, data, children=None):
self.data = data
self.children = None
self.father = None
self.cost = None
self.set_children(children)
def set_children(self, children):
self.children = children
if self.children is not None:
for child in self.children:
child.father = self
return
def get_children(self):
return self.children
def set_father(self, father):
self.father = father
return
def get_father(self):
return self.father
def set_data(self, data):
self.data = data
return
def get_data(self):
return self.data
def set_cost(self, cost):
self.cost = cost
return
def get_cost(self):
return self.cost
def equal(self, node):
if self.get_data() == node.get_data():
return True
return False
def in_list(self, node_list):
is_contained = False
for node in node_list:
if self.equal(node):
is_contained = True
break
return is_contained
def __str__(self):
return str(self.get_data())