fast-traffic-simulator 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,126 @@
1
+ Metadata-Version: 2.4
2
+ Name: fast-traffic-simulator
3
+ Version: 0.1.0
4
+ Summary: A NumPy/SciPy-based microscopic traffic simulator
5
+ Project-URL: Homepage, https://github.com/fbk-most/FastTrafficSimulator
6
+ Project-URL: Repository, https://github.com/fbk-most/FastTrafficSimulator
7
+ Author: Marco Pistore
8
+ License: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: numpy,scipy,simulation,traffic,transport
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Scientific/Engineering
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: >=3.12
20
+ Requires-Dist: numpy>=1.24
21
+ Requires-Dist: pandas>=2.0
22
+ Requires-Dist: pyarrow>=14.0
23
+ Requires-Dist: scipy>=1.10
24
+ Description-Content-Type: text/markdown
25
+
26
+ # Fast Traffic Simulator
27
+
28
+ A NumPy/SciPy-based microscopic traffic simulator for directed road networks.
29
+
30
+ We develop this package at [@fbk-most](https://github.com/fbk-most), a research unit
31
+ at [Fondazione Bruno Kessler](https://www.fbk.eu/en/).
32
+
33
+ The simulator models individual vehicles travelling from an origin node to a
34
+ destination node across a directed graph of road edges. Shortest-path routing
35
+ is computed via Dijkstra's algorithm and can be refreshed periodically to
36
+ reflect current congestion. Vehicle behaviour on links follows Newell's
37
+ simplified car-following model: each vehicle moves as fast as possible while
38
+ respecting the road speed limit and keeping a safe distance from the vehicle
39
+ ahead. This reproduces queue formation and congestion without explicit capacity
40
+ constraints. Nodes are treated as dimensionless transfer points — travel time
41
+ accrues only on links — and each edge supports multiple independent lanes.
42
+
43
+ *Note: this package is currently in an early development stage. APIs may change
44
+ without notice between releases.*
45
+
46
+ ## Installation
47
+
48
+ ```bash
49
+ pip install fast-traffic-simulator
50
+ ```
51
+
52
+ Or, for development (requires [uv](https://docs.astral.sh/uv/)):
53
+
54
+ ```bash
55
+ git clone https://github.com/fbk-most/FastTrafficSimulator
56
+ cd FastTrafficSimulator
57
+ uv sync
58
+ ```
59
+
60
+ ## Quick start
61
+
62
+ ```python
63
+ import pandas as pd
64
+ from fts import Simulator
65
+
66
+ # Build a minimal two-edge graph: 0 → 1 → 2
67
+ edges = pd.DataFrame({
68
+ 'from': [0, 1],
69
+ 'to': [1, 2],
70
+ 'length': [100.0, 150.0],
71
+ 'speed': [10.0, 15.0],
72
+ 'lanes': [1, 1],
73
+ })
74
+
75
+ # One vehicle travelling from node 0 to node 2, departing at step 0
76
+ vehicles = pd.DataFrame({
77
+ 'origin': [0],
78
+ 'destination': [2],
79
+ 'start': [0],
80
+ })
81
+
82
+ simulator, _ = Simulator.build(edges=edges, vehicles=vehicles)
83
+
84
+ while True:
85
+ simulator.step()
86
+ arrived = (simulator.vehicles.status == Simulator.VehicleStatus.ARRIVED.value).sum()
87
+ if arrived == len(vehicles):
88
+ break
89
+
90
+ print(f"Vehicle arrived at step {simulator.vehicles.arrival_time[0]}")
91
+ ```
92
+
93
+ ## Main contributors
94
+
95
+ [Marco Pistore](https://it.linkedin.com/in/marco-pistore): design and implementation.
96
+
97
+ ## Acknowledgements
98
+
99
+ This software has been developed in the scope of the Bologna Digital Twin project,
100
+ and partially supported by the following projects:
101
+
102
+ - NRR ICSC National Research Centre for High Performance Computing, Big Data and Quantum Computing (CN00000013), under
103
+ the NRRP MUR program funded by the NextGenerationEU.
104
+ - European Structural and Investment Funds, as part of the National Program for Metropolitan Cities and Medium-Sized
105
+ Cities South 2021-2027, Priority 1 Digital Agenda and Urban Innovation,Action 1.1.2.1 Metropolitan Digital Agenda,
106
+ Project BO1.1.2.1.a "DIGITAL TWIN: GOVERNANCE AND ENHANCEMENT OF DATA ASSETS"
107
+
108
+ ## License
109
+
110
+ Copyright 2025-2026 Fondazione Bruno Kessler
111
+
112
+ Licensed under the Apache License, Version 2.0 (the "License");
113
+ you may not use this file except in compliance with the License.
114
+ You may obtain a copy of the License at
115
+
116
+ http://www.apache.org/licenses/LICENSE-2.0
117
+
118
+ Unless required by applicable law or agreed to in writing, software
119
+ distributed under the License is distributed on an "AS IS" BASIS,
120
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
121
+ See the License for the specific language governing permissions and
122
+ limitations under the License.
123
+
124
+ ```
125
+ SPDX-License-Identifier: Apache-2.0
126
+ ```
@@ -0,0 +1,101 @@
1
+ # Fast Traffic Simulator
2
+
3
+ A NumPy/SciPy-based microscopic traffic simulator for directed road networks.
4
+
5
+ We develop this package at [@fbk-most](https://github.com/fbk-most), a research unit
6
+ at [Fondazione Bruno Kessler](https://www.fbk.eu/en/).
7
+
8
+ The simulator models individual vehicles travelling from an origin node to a
9
+ destination node across a directed graph of road edges. Shortest-path routing
10
+ is computed via Dijkstra's algorithm and can be refreshed periodically to
11
+ reflect current congestion. Vehicle behaviour on links follows Newell's
12
+ simplified car-following model: each vehicle moves as fast as possible while
13
+ respecting the road speed limit and keeping a safe distance from the vehicle
14
+ ahead. This reproduces queue formation and congestion without explicit capacity
15
+ constraints. Nodes are treated as dimensionless transfer points — travel time
16
+ accrues only on links — and each edge supports multiple independent lanes.
17
+
18
+ *Note: this package is currently in an early development stage. APIs may change
19
+ without notice between releases.*
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ pip install fast-traffic-simulator
25
+ ```
26
+
27
+ Or, for development (requires [uv](https://docs.astral.sh/uv/)):
28
+
29
+ ```bash
30
+ git clone https://github.com/fbk-most/FastTrafficSimulator
31
+ cd FastTrafficSimulator
32
+ uv sync
33
+ ```
34
+
35
+ ## Quick start
36
+
37
+ ```python
38
+ import pandas as pd
39
+ from fts import Simulator
40
+
41
+ # Build a minimal two-edge graph: 0 → 1 → 2
42
+ edges = pd.DataFrame({
43
+ 'from': [0, 1],
44
+ 'to': [1, 2],
45
+ 'length': [100.0, 150.0],
46
+ 'speed': [10.0, 15.0],
47
+ 'lanes': [1, 1],
48
+ })
49
+
50
+ # One vehicle travelling from node 0 to node 2, departing at step 0
51
+ vehicles = pd.DataFrame({
52
+ 'origin': [0],
53
+ 'destination': [2],
54
+ 'start': [0],
55
+ })
56
+
57
+ simulator, _ = Simulator.build(edges=edges, vehicles=vehicles)
58
+
59
+ while True:
60
+ simulator.step()
61
+ arrived = (simulator.vehicles.status == Simulator.VehicleStatus.ARRIVED.value).sum()
62
+ if arrived == len(vehicles):
63
+ break
64
+
65
+ print(f"Vehicle arrived at step {simulator.vehicles.arrival_time[0]}")
66
+ ```
67
+
68
+ ## Main contributors
69
+
70
+ [Marco Pistore](https://it.linkedin.com/in/marco-pistore): design and implementation.
71
+
72
+ ## Acknowledgements
73
+
74
+ This software has been developed in the scope of the Bologna Digital Twin project,
75
+ and partially supported by the following projects:
76
+
77
+ - NRR ICSC National Research Centre for High Performance Computing, Big Data and Quantum Computing (CN00000013), under
78
+ the NRRP MUR program funded by the NextGenerationEU.
79
+ - European Structural and Investment Funds, as part of the National Program for Metropolitan Cities and Medium-Sized
80
+ Cities South 2021-2027, Priority 1 Digital Agenda and Urban Innovation,Action 1.1.2.1 Metropolitan Digital Agenda,
81
+ Project BO1.1.2.1.a "DIGITAL TWIN: GOVERNANCE AND ENHANCEMENT OF DATA ASSETS"
82
+
83
+ ## License
84
+
85
+ Copyright 2025-2026 Fondazione Bruno Kessler
86
+
87
+ Licensed under the Apache License, Version 2.0 (the "License");
88
+ you may not use this file except in compliance with the License.
89
+ You may obtain a copy of the License at
90
+
91
+ http://www.apache.org/licenses/LICENSE-2.0
92
+
93
+ Unless required by applicable law or agreed to in writing, software
94
+ distributed under the License is distributed on an "AS IS" BASIS,
95
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
96
+ See the License for the specific language governing permissions and
97
+ limitations under the License.
98
+
99
+ ```
100
+ SPDX-License-Identifier: Apache-2.0
101
+ ```
@@ -0,0 +1,12 @@
1
+ ## Ideas and todos
2
+
3
+ We need to manage:
4
+
5
+ - multi-edge graphs, either directly or with some tricks (e.g., adding fictitious nodes and edges). At the moment, only
6
+ one among multiple edges is kept.
7
+ - vehicles starting and ending at the same node
8
+
9
+ Improvements:
10
+
11
+ - no need to manage the whole vehicle array in all iterations: we can consider windows of active vehicles (e.g., from
12
+ first active to last active)
@@ -0,0 +1,102 @@
1
+ """Demo script: run the simulator on a small graph and trace vehicle/edge histories.
2
+
3
+ Usage::
4
+
5
+ uv run python examples/demo.py
6
+
7
+ Input files are located in ``examples/demo_data/``.
8
+ """
9
+
10
+ import numpy as np
11
+ import pandas as pd
12
+ from fts import Simulator
13
+
14
+
15
+ def run() -> np.ndarray:
16
+ """Run the demo simulation and return per-step position logs.
17
+
18
+ Returns:
19
+ A float array of shape ``(steps, nr_vehicles, 2)`` where the last axis
20
+ holds ``[edge_index, edge_distance]`` for each vehicle at each step.
21
+ Edge index is ``-1`` (distance set to 0) when the vehicle is not in an
22
+ edge.
23
+ """
24
+ edges_file = 'examples/demo_data/demo_graph.csv'
25
+ vehicles_file = 'examples/demo_data/demo_demand.csv'
26
+ edges = pd.read_csv(edges_file, names=['id', 'from', 'to', 'length', 'speed', 'lanes'],
27
+ skiprows=1, index_col='id')
28
+ vehicles = pd.read_csv(vehicles_file, names=['origin', 'destination', 'start'],
29
+ skiprows=1)
30
+ vehicles['start'] = vehicles['start'].astype(int)
31
+ vehicles.index.name = 'id'
32
+
33
+ simulator, _ = Simulator.build(edges=edges, vehicles=vehicles)
34
+ logs = []
35
+
36
+ def snapshot() -> np.ndarray:
37
+ log = np.vstack([simulator.vehicles.edge, simulator.vehicles.edge_distance])
38
+ log[1, simulator.vehicles.edge == -1] = 0
39
+ return log.swapaxes(0, 1)
40
+
41
+ logs.append(snapshot())
42
+
43
+ while True:
44
+ simulator.step(False)
45
+ nr_waiting = (simulator.vehicles.status == Simulator.VehicleStatus.WAITING.value).sum()
46
+ nr_at_node = (simulator.vehicles.status == Simulator.VehicleStatus.AT_NODE.value).sum()
47
+ nr_in_edge = (simulator.vehicles.status == Simulator.VehicleStatus.IN_EDGE.value).sum()
48
+ logs.append(snapshot())
49
+
50
+ if nr_waiting + nr_at_node + nr_in_edge == 0:
51
+ break
52
+
53
+ return np.array(logs)
54
+
55
+
56
+ def vehicle_history(logs: np.ndarray, v: int) -> None:
57
+ """Print a human-readable movement history for a single vehicle.
58
+
59
+ Args:
60
+ logs: Position log array as returned by :func:`run`.
61
+ v: Vehicle index.
62
+ """
63
+ print(f"History of vehicle {v}")
64
+ edge = -1
65
+ for t in range(logs.shape[0]):
66
+ old_edge = edge
67
+ edge = int(logs[t, v, 0])
68
+ dist = logs[t, v, 1]
69
+ if edge != old_edge:
70
+ if edge == -1:
71
+ print(f"- Time {t}: vehicle {v} arrives")
72
+ else:
73
+ print(f"- Time {t}: vehicle {v} enters edge {edge}")
74
+ if edge != -1:
75
+ print(f"- Time {t}: vehicle {v} is at distance {dist} in edge {edge}")
76
+
77
+
78
+ def edge_history(logs: np.ndarray, edge: int) -> None:
79
+ """Print a human-readable occupancy history for a single edge.
80
+
81
+ Args:
82
+ logs: Position log array as returned by :func:`run`.
83
+ edge: Edge index.
84
+ """
85
+ print(f"History of edge {edge}")
86
+ vehicles: set[int] = set()
87
+ for t in range(logs.shape[0]):
88
+ old_vehicles = vehicles
89
+ vehicles = {v for v in range(logs.shape[1]) if logs[t, v, 0] == edge}
90
+ for v in vehicles:
91
+ dist = logs[t, v, 1]
92
+ if v not in old_vehicles:
93
+ print(f"- Time {t}: vehicle {v} enters edge {edge}")
94
+ print(f"- Time {t}: vehicle {v} is at distance {dist} in edge {edge}")
95
+ for v in old_vehicles - vehicles:
96
+ print(f"- Time {t}: vehicle {v} leaves edge {edge}")
97
+
98
+
99
+ if __name__ == "__main__":
100
+ logs = run()
101
+ vehicle_history(logs, 3)
102
+ edge_history(logs, 7)
@@ -0,0 +1,21 @@
1
+ origin,destination,depart_time
2
+ 2,6,281.38
3
+ 2,6,446.91
4
+ 2,6,250.78
5
+ 2,6,43.48
6
+ 2,6,18.27
7
+ 2,6,130.09
8
+ 2,6,44.05
9
+ 2,6,385.41
10
+ 2,6,317.27
11
+ 2,6,264.15
12
+ 8,5,319.13
13
+ 8,5,392.50
14
+ 8,5,352.10
15
+ 8,5,72.89
16
+ 8,5,421.57
17
+ 8,5,408.01
18
+ 8,5,396.64
19
+ 8,5,464.23
20
+ 8,5,216.43
21
+ 8,5,101.30
@@ -0,0 +1,25 @@
1
+ id,from,to,length,ffspeed,lanes
2
+ 0link_0_1, 0, 1, 298, 30, 1
3
+ 0link_0_2, 0, 2, 200, 30, 1
4
+ 0link_0_4, 0, 4, 386, 100, 1
5
+ 0link_1_0, 1, 0, 298, 30, 1
6
+ 0link_1_2, 1, 2, 294, 30, 1
7
+ 0link_2_0, 2, 0, 200, 30, 1
8
+ 0link_2_1, 2, 1, 294, 30, 1
9
+ 0link_2_4, 2, 4, 377, 100, 1
10
+ 0link_3_4, 3, 4, 463, 30, 1
11
+ 0link_3_5, 3, 5, 287, 30, 1
12
+ 0link_3_7, 3, 7, 478, 100, 1
13
+ 0link_4_0, 4, 0, 386, 100, 1
14
+ 0link_4_2, 4, 2, 377, 100, 1
15
+ 0link_4_3, 4, 3, 463, 30, 1
16
+ 0link_4_5, 4, 5, 304, 30, 1
17
+ 0link_5_3, 5, 3, 287, 30, 1
18
+ 0link_5_4, 5, 4, 304, 30, 1
19
+ 0link_8_6, 8, 6, 223, 30, 1
20
+ 0link_8_7, 8, 7, 335, 30, 1
21
+ 0link_6_8, 6, 8, 223, 30, 1
22
+ 0link_6_7, 6, 7, 337, 30, 1
23
+ 0link_7_3, 7, 3, 478, 100, 1
24
+ 0link_7_8, 7, 8, 335, 30, 1
25
+ 0link_7_6, 7, 6, 337, 30, 1
@@ -0,0 +1,37 @@
1
+ """Minimal quickstart example: simulate one vehicle on a synthetic two-edge graph.
2
+
3
+ No input files are required — the network and demand are built in memory.
4
+
5
+ Usage::
6
+
7
+ uv run python examples/quickstart.py
8
+ """
9
+
10
+ import pandas as pd
11
+ from fts import Simulator
12
+
13
+ # Build a minimal two-edge graph: 0 → 1 → 2
14
+ edges = pd.DataFrame({
15
+ 'from': [0, 1],
16
+ 'to': [1, 2],
17
+ 'length': [100.0, 150.0],
18
+ 'speed': [10.0, 15.0],
19
+ 'lanes': [1, 1],
20
+ })
21
+
22
+ # One vehicle travelling from node 0 to node 2, departing at step 0
23
+ vehicles = pd.DataFrame({
24
+ 'origin': [0],
25
+ 'destination': [2],
26
+ 'start': [0],
27
+ })
28
+
29
+ simulator, _ = Simulator.build(edges=edges, vehicles=vehicles)
30
+
31
+ while True:
32
+ simulator.step()
33
+ arrived = (simulator.vehicles.status == Simulator.VehicleStatus.ARRIVED.value).sum()
34
+ if arrived == len(vehicles):
35
+ break
36
+
37
+ print(f"Vehicle arrived at step {simulator.vehicles.arrival_time[0]}")