diff --git a/README.jp.md b/README.jp.md index 28c1d8e..11c24a8 100644 --- a/README.jp.md +++ b/README.jp.md @@ -2,7 +2,7 @@ [![PyPi](https://img.shields.io/pypi/v/uxsim.svg)](https://pypi.python.org/pypi/uxsim) [![arXiv](https://img.shields.io/badge/arXiv-2309.17114-b31b1b.svg)](http://dx.doi.org/10.48550/arXiv.2309.17114) -[![Demo in Colab](https://colab.research.google.com/assets/colab-badge.svg)](http://colab.research.google.com/github/toruseo/UXsim/blob/main/demos_and_examples/demo_notebook_01en_for_colab.ipynb) +[![Demo in Colab](https://colab.research.google.com/assets/colab-badge.svg)](http://colab.research.google.com/github/toruseo/UXsim/blob/main/demos_and_examples/demo_notebook_05en_for_google_colab.ipynb) [![Static Badge](https://img.shields.io/badge/readme-English%20%F0%9F%87%BA%F0%9F%87%B8%20-%20darkblue)](https://github.com/toruseo/UXsim/blob/main/README.md) diff --git a/README.md b/README.md index 3a809f1..3fa79a9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![PyPi](https://img.shields.io/pypi/v/uxsim.svg)](https://pypi.python.org/pypi/uxsim) [![arXiv](https://img.shields.io/badge/arXiv-2309.17114-b31b1b.svg)](http://dx.doi.org/10.48550/arXiv.2309.17114) -[![Demo in Colab](https://colab.research.google.com/assets/colab-badge.svg)](http://colab.research.google.com/github/toruseo/UXsim/blob/main/demos_and_examples/demo_notebook_01en_for_colab.ipynb) +[![Demo in Colab](https://colab.research.google.com/assets/colab-badge.svg)](http://colab.research.google.com/github/toruseo/UXsim/blob/main/demos_and_examples/demo_notebook_05en_for_google_colab.ipynb) [![Static Badge](https://img.shields.io/badge/readme-%E6%97%A5%E6%9C%AC%E8%AA%9E%20%F0%9F%87%AF%F0%9F%87%B5%20-pink)](https://github.com/toruseo/UXsim/blob/main/README.jp.md) diff --git a/demos_and_examples/demo_notebook_01en_for_colab.ipynb b/demos_and_examples/demo_notebook_05en_for_google_colab.ipynb similarity index 93% rename from demos_and_examples/demo_notebook_01en_for_colab.ipynb rename to demos_and_examples/demo_notebook_05en_for_google_colab.ipynb index 85f2cb8..9c85a5e 100644 --- a/demos_and_examples/demo_notebook_01en_for_colab.ipynb +++ b/demos_and_examples/demo_notebook_05en_for_google_colab.ipynb @@ -6,7 +6,15 @@ "id": "WXW1G2euEY1S" }, "source": [ - "## Simple Scenario Example\n", + "# UXsim demo (for Google Colab)\n", + "\n", + "This notebook demonstrates basic functionaries of [UXsim](https://github.com/toruseo/UXsim). \n", + "For further details, please see the [GitHub repo](https://github.com/toruseo/UXsim) and the [technical documentation](https://toruseo.jp/UXsim/docs/index.html).\n", + "\n", + "We show two examples: simple one and large-scale one.\n", + "\n", + "## Simple Example\n", + "\n", "\n", "First, install UXsim using pip and import the required modules." ] @@ -99,7 +107,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The network shape is as follows." + "The network shape can be confirmed as follows." ] }, { @@ -375,6 +383,141 @@ "source": [ "W.analyzer.output_data()" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Large-scale Example\n", + "\n", + "Noe let's see large-scale scenario with a lot of vehicles in a large network.\n", + "\n", + "If you haven't, please install UXsim first." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "!pip install uxsim" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from uxsim import *\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "At this time, we automatically generate a grid-shaped network." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "W = World(\n", + " name=\"large\",\n", + " deltan=5,\n", + " tmax=7200,\n", + " print_mode=1, save_mode=1, show_mode=0,\n", + " random_seed=0,\n", + ")\n", + "\n", + "# create nodes on an imax x jmax grid.\n", + "imax = 11\n", + "jmax = 11\n", + "nodes = {}\n", + "for i in range(imax):\n", + " for j in range(jmax):\n", + " nodes[i,j] = W.addNode(f\"n{(i,j)}\", i, j)\n", + "\n", + "# create links between neighborhood nodes\n", + "links = {}\n", + "for i in range(imax):\n", + " for j in range(jmax):\n", + " if i != imax-1:\n", + " 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, jam_density=0.2)\n", + " if i != 0:\n", + " 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, jam_density=0.2)\n", + " if j != jmax-1:\n", + " 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, jam_density=0.2)\n", + " if j != 0:\n", + " 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, jam_density=0.2)\n", + "\n", + "# generate demand from each boundary node to the other boundary nodes\n", + "demand_flow = 0.035\n", + "demand_duration = 3600\n", + "for n1 in [(0,j) for j in range(jmax)]:\n", + " for n2 in [(imax-1,j) for j in range(jmax)]:\n", + " W.adddemand(nodes[n2], nodes[n1], 0, demand_duration, demand_flow)\n", + " W.adddemand(nodes[n1], nodes[n2], 0, demand_duration, demand_flow)\n", + "for n1 in [(i,0) for i in range(imax)]:\n", + " for n2 in [(i,jmax-1) for i in range(imax)]:\n", + " W.adddemand(nodes[n2], nodes[n1], 0, demand_duration, demand_flow)\n", + " W.adddemand(nodes[n1], nodes[n2], 0, demand_duration, demand_flow)\n", + "\n", + "W.show_network(network_font_size=0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Note that each link is 1 km long, so this is a 10 km x 10 km area. And the total number of vehicles is about 60000." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "W.exec_simulation()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's visualize the network traffic states. You can see complicated traffic pattern emerges in the network." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "W.analyzer.network_anim(animation_speed_inverse=15, timestep_skip=30, detailed=0, network_font_size=0, figsize=(6,6))\n", + "\n", + "from IPython.display import display, Image\n", + "with open(\"outlarge/anim_network0.gif\", \"rb\") as f:\n", + " display(Image(data=f.read(), format='png'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "W.analyzer.network_fancy(animation_speed_inverse=15, sample_ratio=0.3, interval=3, trace_length=5)\n", + "\n", + "with open(\"outlarge/anim_network_fancy.gif\", \"rb\") as f:\n", + " display(Image(data=f.read(), format='png'))" + ] } ], "metadata": { diff --git a/demos_and_examples/uxsim/uxsim.py b/demos_and_examples/uxsim/uxsim.py index 838daf3..0e5b4fc 100644 --- a/demos_and_examples/uxsim/uxsim.py +++ b/demos_and_examples/uxsim/uxsim.py @@ -2732,6 +2732,10 @@ def addNode(W, *args, **kwargs): A list representing the signal at the node. Default is [0], representing no signal. If a signal is present, the list contains the green times for each group. For example, `signal`=[60, 10, 50, 5] means that this signal has 4 phases, and green time for the 1st group is 60 s. + signal_offset : float, optional + The offset of the signal. Default is 0. + flow_capacity : float, optional + The maximum flow capacity of the node. Default is None, meaning infinite capacity. Returns ------- diff --git a/tests/test_verification_route_choice.py b/tests/test_verification_route_choice.py index 604935a..703beb8 100644 --- a/tests/test_verification_route_choice.py +++ b/tests/test_verification_route_choice.py @@ -1,5 +1,5 @@ """ -This script verifies whether UXsim outputs reasonable solutions for two route networks in various configurations. +This script verifies whether UXsim outputs reasonable solutions for multiple route networks in various configurations. Note that it uses random numbers for rouce choice behavior, so the results may vary slightly between runs. """