-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.py
41 lines (35 loc) · 1.02 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
class Node:
"""
A node connects to other nodes via Edges to form a graph
Each node has a unique identifier (ID) so they can be mathematically distinct. Optionally, a node also has an x and
y coordinate.
"""
n_nodes = 0
def __init__(self, x=0, y=0):
"""
Create a node with its own unique identifier.
:param x: x coordinate
:param y: y coordinate
:return: an initialized Node object
"""
Node.n_nodes += 1
self.ID = Node.n_nodes
self.x = x # x position
self.y = y # y position
def __eq__(self, other):
return (self.ID, self.x, self.y) == (other.ID, other.x, other.y)
def __hash__(self):
return hash(self.ID)
def copy(self):
node = Node()
node.ID = self.ID
node.x = self.x
node.y = self.y
return node
def generate_dict(self):
dictionary = {
'ID': self.ID,
'x': self.x,
'y': self.y
}
return dictionary