-
Notifications
You must be signed in to change notification settings - Fork 0
/
intersection.py
executable file
·42 lines (32 loc) · 1007 Bytes
/
intersection.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
"""
Represents an intersection and handles requests to get out of the intersection.
Holds the out links from the intersection.
Visible links are set of links that are visible for short-term stigmergy from that intersection.
"""
class Intersection:
def __init__(self, env, name, links, visible_links, pos):
self.env = env
self.id = name
self.out = links
self.visible_links = visible_links
self.pos = pos
def get_pos(self):
return self.pos
def get_links(self):
return self.out
def get_links_in_area(self):
return self.visible_links
def get_random_link(self):
return np.random.choice(self.out)
def get_id(self):
return self.id
def is_deadend(self):
return len(self.out) == 0
def __str__(self):
return "Intersection {} {}".format(self.id, self.pos)
def __repr__(self):
return self.__str__()
# Note: This is only defined to satisfy the `heapq` library in `network.py`
def __lt__(self, other):
return True