Skip to content

Commit

Permalink
update demo and others
Browse files Browse the repository at this point in the history
  • Loading branch information
toruseo committed Jan 7, 2025
1 parent 31f03b6 commit 5fceb7e
Show file tree
Hide file tree
Showing 7 changed files with 318 additions and 688 deletions.
2 changes: 1 addition & 1 deletion README.jp.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ UXsimは単純,軽量,柔軟であるため,研究・教育上の目的に
- シミュレーション結果の基本的な分析と`pandas.DataFrame`,CSVへのエクスポート
- `Matplotlib`を使用したシミュレーション結果の可視化.インタラクティブなGUIも利用可能
- 純Pythonであることを活かした高度なカスタマイズ性.`PyTorch`を用いた深層強化学習による交通制御など,他のPythonベースのフレームワークとも直接連携可能
- メインコードの`uxsim.py`は約1800行のコードのみ.ユーザーが簡単に理解しカスタマイズできます
- メインコードの`uxsim.py`は約2300行のコードのみ.ユーザーが簡単に理解しカスタマイズできます

## 計算例

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ If you are interested, please see:
- Basic analysis of simulation results and their export to `pandas.DataFrame` and CSV files
- Visualization of simulation results using `Matplotlib`; interactive GUI is also available
- Flexible and customizable thanks to pure Python implementation; can also be directly integrated with other Python-based frameworks, such as `PyTorch` for deep reinforcement learning traffic control
- The main code `uxsim.py` is only about 1800 lines of code. Users may easily understand and customize it
- The main code `uxsim.py` is only about 2300 lines of code. Users may easily understand and customize it

## Simulation Examples

Expand Down
947 changes: 268 additions & 679 deletions demos_and_examples/demo_notebook_09en_dynamic_traffic_assignment.ipynb

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion tests/test_other_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,4 +1143,43 @@ def test_route_enforce_route():

df = W.analyzer.link_to_pandas()
for l in r2:
assert df[df["link"]==l.name]["traffic_volume"].values[0] == 2130
assert df[df["link"]==l.name]["traffic_volume"].values[0] == 2130

def test_construct_time_space_network():
W = World(
name="",
deltan=20,
tmax=6000,
print_mode=1, save_mode=1, show_mode=1,
vehicle_logging_timestep_interval=1,
hard_deterministic_mode=False,
random_seed=42 #fix seed to reproduce random demand
)

W.addNode("1", 0, 1)
W.addNode("2", 1, 1)
W.addNode("3", 5, 1)
W.addNode("4", 0, 0)
W.addNode("5", 1, 0)
W.addNode("6", 5, 0)
W.addNode("7", 6, 0.5)

W.addLink("highway12", "1", "2", length=1000, number_of_lanes=1, merge_priority=1)
W.addLink("highway23", "2", "3", length=3000, number_of_lanes=1, merge_priority=1, capacity_out=0.6)
W.addLink("highway37", "3", "7", length=1000, number_of_lanes=1, merge_priority=1)
W.addLink("onramp", "5", "2", length=1000, number_of_lanes=1, merge_priority=0.5)
W.addLink("arterial45", "4", "5", length=1000, free_flow_speed=10, number_of_lanes=2, merge_priority=0.5)
W.addLink("arterial56", "5", "6", length=3000, free_flow_speed=10, number_of_lanes=2, merge_priority=0.5)
W.addLink("arterial67", "6", "7", length=1000, free_flow_speed=10, number_of_lanes=2, merge_priority=0.5)

W.adddemand("1", "7", 0, 3000, 0.3)
W.adddemand("4", "7", 0, 3000, 0.4*3)

W.exec_simulation()

W.analyzer.print_simple_stats()

construct_time_space_network(W)

assert W.TSN_paths["4", 0]["7", "end"][-2] == ('7', 320)
assert equal_tolerance(W.TSN_costs["4", 0]["7", "end"], W.TSN_paths["4", 0]["7", "end"][-2][1])
6 changes: 3 additions & 3 deletions tests/test_verification_dta_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def create_World():
solver_DSO.plot_link_stats()
solver_DSO.plot_vehicle_stats(orig="4", dest="7")

solver_DSO.plot_convergence()
solver_DSO.plot_link_stats()
solver_DSO.plot_vehicle_stats(orig="4", dest="7")
solver_DSO_GA.plot_convergence()
solver_DSO_GA.plot_link_stats()
solver_DSO_GA.plot_vehicle_stats(orig="4", dest="7")

assert W_DUO.analyzer.total_travel_time > W_DUE.analyzer.total_travel_time
assert W_DUE.analyzer.total_travel_time > W_DSO.analyzer.total_travel_time
Expand Down
8 changes: 5 additions & 3 deletions uxsim/Utilities/Utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def enumerate_k_shortest_routes_on_t(W, source, target, t, k=1, cost_function=la

def enumerate_k_random_routes(W, k):
"""
Enumerate k random routes between all node pairs in a network. The shortest path with free flow travel time is always included. This is much faster than `enumerate_k_shortest_routes` and useful for some purposes.
Enumerate k random routes between all node pairs in a network. The shortest path with free flow travel time is always included. This is much faster than `enumerate_k_shortest_routes` and could be useful for a plausible choice set generation for route choice problems.
Parameters
----------
Expand Down Expand Up @@ -328,19 +328,21 @@ def get_shortest_path_instantaneous_travel_time_between_all_nodes_on_t(W, t, ret

def construct_time_space_network(W, dt=None, from_origin_only=True):
"""
Construct a time-space network (TSN).
Construct a time-space network (TSN) that includes the time-dependent shortest path infomation.
Parameters
----------
W : World
The World object.
dt : int, optional
The time interval to construct the TSN. Default is None.
The time interval to construct the TSN. Default is None, which sets to the simulation timestep.
from_origin_only : bool, optional
Whether to compute the shortest path from the origin only. Default is True
Notes
-----
In the default setting, `W.TSN_paths` contains time-dependent shortest paths from the origin nodes to all nodes, for all departure time. The time-dependent link cost is based on the actual travel time. For example, `W.TSN_paths["orig_node_name", 0]` contains the shortest path from the node "orig_node_name" with departure time 0. `W.TSN_paths["orig_node_name", 0]["dest_node_name", "end"]` contains the shortest path from the node "orig_node_name" to "dest_node_name" with departure time 0. The travel time between these nodes on this time can be obtained by `W.TSN_costs["orig_node_name", 0]["dest_node_name", "end"]`.
Not efficient for large networks.
"""
if dt == None:
Expand Down

0 comments on commit 5fceb7e

Please sign in to comment.