forked from toruseo/UXsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_20en_taxi_or_shared_mobility.py
60 lines (52 loc) · 1.89 KB
/
example_20en_taxi_or_shared_mobility.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
from uxsim import *
from uxsim.TaxiHandler import *
# World definition
tmax = 7200
deltan = 5
W = World(
name="",
deltan=deltan,
tmax=tmax,
print_mode=1, save_mode=1, show_mode=1,
random_seed=0,
)
# Scenario definition: grid network
#deploy nodes as an imax x jmax grid
imax = 6
jmax = 6
nodes = {}
for i in range(imax):
for j in range(jmax):
nodes[i,j] = W.addNode(f"n{(i,j)}", i, j, flow_capacity=1.6)
#create links between neighborhood nodes
links = {}
for i in range(imax):
for j in range(jmax):
if i != imax-1:
links[i,j,i+1,j] = W.addLink(f"l{(i,j,i+1,j)}", nodes[i,j], nodes[i+1,j], length=1000, free_flow_speed=20, number_of_lanes=1)
if i != 0:
links[i,j,i-1,j] = W.addLink(f"l{(i,j,i-1,j)}", nodes[i,j], nodes[i-1,j], length=1000, free_flow_speed=20, number_of_lanes=1)
if j != jmax-1:
links[i,j,i,j+1] = W.addLink(f"l{(i,j,i,j+1)}", nodes[i,j], nodes[i,j+1], length=1000, free_flow_speed=20, number_of_lanes=1)
if j != 0:
links[i,j,i,j-1] = W.addLink(f"l{(i,j,i,j-1)}", nodes[i,j], nodes[i,j-1], length=1000, free_flow_speed=20, number_of_lanes=1)
# taxis and passengers
n_passengers = 20000
n_taxis = 3000
for i in range(int(n_taxis/deltan)):
node = random.choice(list(nodes.values()))
W.addVehicle(node, None, 0, mode="taxi")
Handler = TaxiHandler_nearest(W)
for i in range(int(n_passengers/deltan)):
node1 = random.choice(list(nodes.values()))
node2 = random.choice(list(nodes.values()))
while node1 == node2:
node2 = random.choice(list(nodes.values()))
Handler.add_trip_request(node1, node2, i/n_passengers*deltan*tmax/2)
# Run the simulation
while W.check_simulation_ongoing():
W.exec_simulation(duration_t = 60)
Handler.assign_trip_request_to_taxi() # for every 60 seconds, the taxi is assgined
# Results
W.analyzer.print_simple_stats()
Handler.print_stats()