Skip to content

Commit

Permalink
revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
toruseo committed Mar 26, 2024
1 parent e84f430 commit 778661b
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/verify-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
test-script: [tests/test_verification_straight_road.py, tests/test_verification_route_choice.py tests/test_verification_node.py, tests/test_verification_exceptional.py, tests/test_verification_sioux_falls.py]
test-script: [tests/test_verification_straight_road.py tests/test_verification_route_choice.py tests/test_verification_node.py tests/test_verification_exceptional.py tests/test_verification_sioux_falls.py]
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from uxsim import *
from uxsim.OSMImporter.OSMImporter import OSMImporter
from uxsim.OSMImporter import OSMImporter

W = World(
name="",
Expand Down
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) 2023 Toru Seo
# License: MIT License

from setuptools import setup
from setuptools import setup, find_packages
#import uxsim

DESCRIPTION = "UXsim: traffic flow simulator"
Expand All @@ -12,7 +12,7 @@
URL = 'https://github.com/toruseo/UXsim'
LICENSE = 'MIT License'
DOWNLOAD_URL = 'https://github.com/toruseo/UXsim'
VERSION = "1.0.8"
VERSION = "1.0.9"
PYTHON_REQUIRES = ">=3.9"

INSTALL_REQUIRES = [
Expand All @@ -22,14 +22,13 @@
'tqdm>=4.64.1',
'scipy>=1.9.1',
'pandas>=1.4.4',
'PyQt5>=5.15.7'
]

EXTRAS_REQUIRE = {
}

PACKAGES = [
'uxsim'
]
PACKAGES = find_packages()

CLASSIFIERS = [
'Intended Audience :: Science/Research',
Expand Down
49 changes: 49 additions & 0 deletions tests/test_result_gui_viewer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
This script tests ResultGUIViewer.
This is for local test only. I don't know how to test it in Github Actions properly.
"""

import pytest

def test_result_gui_viewer():
import uxsim as UX
from uxsim.ResultGUIViewer import ResultGUIViewer

#simple network
W = UX.World(
name="", # Scenario name
deltan=5, # Simulation aggregation unit delta n
tmax=1200, # Total simulation time (s)
print_mode=0, save_mode=0, show_mode=0, # Various options
random_seed=None # Set the random seed
)

# Define the scenario
W.addNode("orig1", 0, 0) # Create a node
W.addNode("orig2", 0, 2)
W.addNode("merge", 0.5, 1)
W.addNode("dest", 1, 1)
W.addLink("link1", "orig1", "merge", length=1000, free_flow_speed=20, jam_density=0.2, merge_priority=0.5) # Create a link
W.addLink("link2", "orig2", "merge", length=1000, free_flow_speed=20, jam_density=0.2, merge_priority=2)
W.addLink("link3", "merge", "dest", length=1000, free_flow_speed=20, jam_density=0.2)
W.adddemand("orig1", "dest", 0, 1000, 0.4) # Create OD traffic demand
W.adddemand("orig2", "dest", 500, 1000, 0.6)


# Run the simulation to the end
W.exec_simulation()

# Print summary of simulation result
W.analyzer.print_simple_stats()

app, window = ResultGUIViewer.launch_World_viewer(W, return_app_window=True)

# Shut down 5 sec later
from PyQt5.QtCore import QTimer
import sys
timer = QTimer()
timer.timeout.connect(window.close)
timer.start(1000*5)
assert True
with pytest.raises(SystemExit):
sys.exit(app.exec_())
1 change: 1 addition & 0 deletions uxsim/OSMImporter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .OSMImporter import *
54 changes: 41 additions & 13 deletions uxsim/ResultGUIViewer/ResultGUIViewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def paint(self, painter, option, widget):

c = colormaps["viridis"](speed/self.Link.u)
#color = QColor(int(density/self.Link.jam_density * 255), int(density/self.Link.jam_density * 255), 0, 255)
color = QColor(c[0]*255, c[1]*255, c[2]*255, 255)
color = QColor(int(c[0]*255), int(c[1]*255), int(c[2]*255), 255)
pen = QPen(color, lw)
painter.setPen(pen)

Expand Down Expand Up @@ -244,9 +244,10 @@ def set_show_vehicles(self, show_vehicles):
self.viewport().update()

class MainWindow(QMainWindow):
def __init__(self, nodes, edges, vehicle_list, tmax):
def __init__(self, W, nodes, edges, vehicle_list, tmax):
super().__init__()
self.setWindowTitle("UXsim result viewer")
self.W = W
self.tmax = tmax
self.playing = False
self.curve_direction = 1
Expand Down Expand Up @@ -290,26 +291,47 @@ def __init__(self, nodes, edges, vehicle_list, tmax):
self.timer.timeout.connect(self.update_t)

menu_bar = self.menuBar()
settings_menu = menu_bar.addMenu("Settings")

curve_direction_menu = settings_menu.addMenu("Link Curve Direction")
curve_right_action = curve_direction_menu.addAction("Right-handed")

# menu_file = menu_bar.addMenu("File")
# acrion_save_world = menu_file.addAction("Save World")
# acrion_save_world.triggered.connect(lambda: self.save_world())

menu_settings = menu_bar.addMenu("Settings")
option_curve_direction = menu_settings.addMenu("Link Curve Direction")
curve_right_action = option_curve_direction.addAction("Right-handed")
curve_right_action.triggered.connect(lambda: self.set_curve_direction(1))
curve_left_action = curve_direction_menu.addAction("Left-handed")
curve_left_action = option_curve_direction.addAction("Left-handed")
curve_left_action.triggered.connect(lambda: self.set_curve_direction(-1))

display_menu = settings_menu.addMenu("Display")
show_names_action = display_menu.addAction("Show Names")
option_display = menu_settings.addMenu("Display")
show_names_action = option_display.addAction("Show Names")
show_names_action.setCheckable(True)
show_names_action.setChecked(True)
show_names_action.triggered.connect(self.toggle_show_names)

self.update_graph()
# show_vehicles_action = display_menu.addAction("Show Vehicles")
menu_Animation = menu_bar.addMenu("Export Results")
action_csv = menu_Animation.addAction("Export Results to CSV files")
action_csv.triggered.connect(lambda: self.W.analyzer.output_data())
action_network_anim_detailed0 = menu_Animation.addAction("Export Network Animation (link-level)")
action_network_anim_detailed0.triggered.connect(lambda: self.W.analyzer.network_anim(detailed=0))
action_network_anim_detailed1 = menu_Animation.addAction("Export Network Animation (link segment-level)")
action_network_anim_detailed1.triggered.connect(lambda: self.W.analyzer.network_anim(detailed=1))
action_network_anim_fancy = menu_Animation.addAction("Export Network Animation (vehicle-level)")
action_network_anim_fancy.triggered.connect(lambda: self.W.analyzer.network_fancy())

# menu_Vehicle = menu_bar.addMenu("Vehicle Analysis")
# show_vehicles_action = menu_Vehicle.addAction("Show Vehicles")
# show_vehicles_action.setCheckable(True)
# show_vehicles_action.setChecked(True)
# show_vehicles_action.triggered.connect(self.toggle_show_vehicles)

self.update_graph()

def save_world(self):
import pickle
with open("World.pkl", mode="wb") as f:
pickle.dump(self.W, f)

def update_graph(self):
t = self.t_slider.value()
edie_dt = self.graph_widget.edges[0].Link.edie_dt
Expand Down Expand Up @@ -347,16 +369,20 @@ def toggle_show_vehicles(self):
self.show_vehicles = not self.show_vehicles
self.graph_widget.set_show_vehicles(self.show_vehicles)

def launch_World_viewer(W):
def launch_World_viewer(W, return_app_window=False):
"""
Launch the interactive viewer for the simulation result of the given World object.
Parameters
----------
W : World
The World object to visualize.
return_app_window : bool, optional
If True, this function returns the QApplication and MainWindow objects. Default is False.
"""

print("Launching the interactive viewer for the simulation result (Do NOT close this terminal!)...")

W.show_mode = 1
W.analyzer.compute_edie_state()
tmax = W.LINKS[0].q_mat.shape[0]
Expand Down Expand Up @@ -391,8 +417,10 @@ def launch_World_viewer(W):
vehicle_list = None

app = QApplication(sys.argv)
window = MainWindow(nodes, edges, vehicle_list, tmax)
window = MainWindow(W, nodes, edges, vehicle_list, tmax)
window.show()
if return_app_window:
return app, window
sys.exit(app.exec_())


Expand Down
1 change: 1 addition & 0 deletions uxsim/ResultGUIViewer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .ResultGUIViewer import *
2 changes: 1 addition & 1 deletion uxsim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .uxsim import *
from .utils import *

__version__ = "1.0.8"
__version__ = "1.0.9"
__author__ = "Toru Seo"
__copyright__ = "Copyright (c) 2023 Toru Seo"
__license__ = "MIT License"

0 comments on commit 778661b

Please sign in to comment.