Skip to content

Commit

Permalink
fix vehicle speed error at node
Browse files Browse the repository at this point in the history
  • Loading branch information
toruseo committed Feb 7, 2025
1 parent 3977256 commit 2e10594
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
53 changes: 48 additions & 5 deletions tests/test_verification_straight_road.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
import random
from uxsim import *

def equal_tolerance(val, check, rel_tol=0.1, abs_tol=0.0):
if check == 0 and abs_tol == 0:
abs_tol = 0.1
return abs(val - check) <= abs(check*rel_tol) + abs_tol

"""
default FD:
u = 20
Expand Down Expand Up @@ -1116,3 +1111,51 @@ def test_iterative_exec_rigorous_random_size_duration_t2():
assert W.VEHICLES["0"].x == (tmax//W.DELTAT-1)*W.DELTAT*link_u

print()

def test_vehicle_speed_at_node_transfer():
for i in range(10):
if i == 0:
deltan = 5
free_flow_speed = 10
length1 = 1000
length2 = random.randint(500,1000)
length3 = 1000
lanes1 = 1
lanes2 = 1
lanes3 = 1
else:
deltan = random.randint(1,10)
free_flow_speed = random.randint(5,25)
length1 = random.randint(500,1000)
length2 = random.randint(500,1000)
length3 = random.randint(500,1000)
lanes1 = random.randint(1,5)
lanes2 = random.randint(1,5)
lanes3 = random.randint(1,5)

W = World(
name="",
deltan=deltan,
tmax=3600,
print_mode=1, save_mode=0, show_mode=0,
random_seed=0
)

W.addNode("orig", 0, 0)
W.addNode("mid1", 1, 1)
W.addNode("mid2", 1, 1)
W.addNode("dest", 2, 1)
W.addLink(f"link1-{length1}", "orig", "mid1", length=length1, free_flow_speed=free_flow_speed, number_of_lanes=lanes1)
W.addLink(f"link2-{length2}", "mid1", "mid2", length=length2, free_flow_speed=free_flow_speed, number_of_lanes=lanes2)
W.addLink(f"link3-{length3}", "mid2", "dest", length=length3, free_flow_speed=free_flow_speed, number_of_lanes=lanes3)
W.adddemand("orig", "dest", 0, 1000, 0.1)
W.exec_simulation()

W.analyzer.print_simple_stats()
df = W.analyzer.vehicles_to_pandas()
df = df[(df["name"]=="0") & (df["x"]!=-1)]
print(df)
vs = df["v"]
for v in list(vs):
assert equal_tolerance(v, free_flow_speed, rel_tol=0, abs_tol=0.01)

11 changes: 10 additions & 1 deletion uxsim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,13 @@ def plot_multiple_y(x=None, ys=None, labels=None, **kwarg):
plt.plot((y-y_min)/(y_max-y_min), label=f"{labels[i]}: [{y_min:.5g}, {y_max:.5g}]", **kwarg)

plt.ylabel("normalized to [0, 1]")
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))


def equal_tolerance(val, check, rel_tol=0.1, abs_tol=0.0):
"""
function for tests
"""
if check == 0 and abs_tol == 0:
abs_tol = 0.1
return abs(val - check) <= abs(check*rel_tol) + abs_tol
4 changes: 3 additions & 1 deletion uxsim/uxsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ def transfer(s):
if x_next >= outlink.length:
x_next = outlink.length
veh.x = x_next
veh.v += veh.x/s.W.DELTAT
veh.move_remain = 0

#今移動した車両の後続車両がトリップ終了待ちの場合,トリップ終了させる
if len(inlink.vehicles) and inlink.vehicles[0].flag_waiting_for_trip_end:
Expand Down Expand Up @@ -919,7 +921,7 @@ def __init__(s, W, orig, dest, departure_time, name=None, route_pref=None, route
s.flag_waiting_for_trip_end = 0

#リンク端部の走り残し処理
s.move_remain = 0
s.move_remain = 0 #リンク移動後に走り続ける余力

#経路選択
if route_choice_principle == None:
Expand Down

0 comments on commit 2e10594

Please sign in to comment.