-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmiscellaneous.py
64 lines (54 loc) · 1.84 KB
/
miscellaneous.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
60
61
62
63
64
import numpy as np
class Call:
def __init__(self, s, e, sp, ep, start_time, wait_end_time, price, duration):
"""
:param s: Start road index.
:param e: End road index.
:param sp: Start road position.
:param ep: End road position.
:param start_time: Call start time.
:param wait_end_time: Wait end time.
:param price: Price of the call.
:param duration: Duration of the call.
"""
self.s = s
self.sp = sp
self.e = e
self.ep = ep
self.start_time = start_time
self.served_time = None
self.wait_end_time = wait_end_time
self.price = price
self.duration = duration
class Road:
def __init__(self, uuid=0, **kwargs):
self.uuid = uuid
self.length = kwargs['length'] # meter
self.drivers = []
self.calls = []
# u, v is an id of start, end node.
self.u = kwargs['u'].item()
self.v = kwargs['v'].item()
self.reachable_roads = []
self.popularity = abs(np.random.normal(0, 1)) ** 3 / 20
self.speed = 24 # km/h
self.speed_coefficient = 1
self.actionable_driver_number = 0
temp = kwargs.get('speed_info_closest_road_index', None)
if temp is None:
temp_v = 0
else:
temp_v = temp.item()
self.speed_info_closest_road_index = temp_v
class Driver:
def __init__(self, uuid, road_index, road_position):
self.uuid = uuid
self.last_road_index = road_index
self.road_index = road_index
self.road_position = road_position
self.current_serving_call = None
self.movable_time = 0
def is_online(self):
return self.current_serving_call is not None
def assign_call(self, call: Call):
self.current_serving_call = call