From 29bc52a66034a05ef535018e271ff5ca19a2d7d2 Mon Sep 17 00:00:00 2001 From: Toru Seo <34780089+toruseo@users.noreply.github.com> Date: Mon, 6 Jan 2025 18:38:51 +0900 Subject: [PATCH 1/2] fix coverage and others --- .github/workflows/measure-coverage.yml | 2 +- ...book_09en_dynamic_traffic_assignment.ipynb | 128 ++++++++++++------ 2 files changed, 84 insertions(+), 46 deletions(-) diff --git a/.github/workflows/measure-coverage.yml b/.github/workflows/measure-coverage.yml index 9456765..09363ea 100644 --- a/.github/workflows/measure-coverage.yml +++ b/.github/workflows/measure-coverage.yml @@ -25,7 +25,7 @@ jobs: - name: Install pytest other dependencies run: pip install pytest pytest-rerunfailures pytest-xdist pytest-cov setuptools osmnx requests - name: Run verifications with pytest - run: pytest -n auto 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 tests/test_verification_multilane.py tests/test_verification_taxi.py tests/test_other_functions.py --durations=0 -v --cov=uxsim --cov-report=xml --cov-config=.github/.coveragerc + run: pytest -n auto 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 tests/test_verification_multilane.py tests/test_verification_taxi.py test_verification_dta_solvers.py tests/test_other_functions.py --durations=0 -v --cov=uxsim --cov-report=xml --cov-config=.github/.coveragerc - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v5.0.2 with: diff --git a/demos_and_examples/demo_notebook_09en_dynamic_traffic_assignment.ipynb b/demos_and_examples/demo_notebook_09en_dynamic_traffic_assignment.ipynb index 9afda9f..475dccd 100644 --- a/demos_and_examples/demo_notebook_09en_dynamic_traffic_assignment.ipynb +++ b/demos_and_examples/demo_notebook_09en_dynamic_traffic_assignment.ipynb @@ -1963,12 +1963,35 @@ "#DUE\n", "\n", "\n", - "solver = SolverDUE(create_World)\n", - "solver.solve(max_iter=300)\n", - "W_DUE = solver.W_sol\n", - "solver.plot_convergence()\n", - "solver.plot_link_stats()\n", - "solver.plot_vehicle_stats(orig=\"4\", dest=\"7\")\n", + "solver_DUE = SolverDUE(create_World)\n", + "solver_DUE.solve(max_iter=300)\n", + "W_DUE = solver_DUE.W_sol\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "solver_DUE.plot_convergence()\n", + "solver_DUE.plot_link_stats()\n", + "solver_DUE.plot_vehicle_stats(orig=\"4\", dest=\"7\")\n", + "\n", + "routes = enumerate_k_random_routes(W, k=5)\n", + "o, d = \"13\", \"10\"\n", + "print(f\"{o}-{d}: # of routes: {len(routes[o,d])}, min # of links: {min([len(r) for r in routes[o,d]])}\")\n", + "solver_DUE.plot_vehicle_stats(orig=o, dest=d)\n", + "o, d = \"10\", \"13\"\n", + "print(f\"{o}-{d}: # of routes: {len(routes[o,d])}, min # of links: {min([len(r) for r in routes[o,d]])}\")\n", + "solver_DUE.plot_vehicle_stats(orig=o, dest=d)\n", + "o, d = \"20\", \"10\"\n", + "print(f\"{o}-{d}: # of routes: {len(routes[o,d])}, min # of links: {min([len(r) for r in routes[o,d]])}\")\n", + "solver_DUE.plot_vehicle_stats(orig=o, dest=d)\n", + "o, d = \"10\", \"20\"\n", + "print(f\"{o}-{d}: # of routes: {len(routes[o,d])}, min # of links: {min([len(r) for r in routes[o,d]])}\")\n", + "solver_DUE.plot_vehicle_stats(orig=o, dest=d)\n", "\n", "W_DUE.analyzer.print_simple_stats(force_print=True)\n", "W_DUE.analyzer.macroscopic_fundamental_diagram()\n", @@ -1983,27 +2006,34 @@ "source": [ "#DSO\n", "\n", - "# scenario definition\n", - "def create_World():\n", - " W = uxsim.World(\n", - " name=\"\",\n", - " deltan=10,\n", - " tmax=9600,\n", - " print_mode=0, save_mode=0, show_mode=1,\n", - " random_seed=0\n", - " )\n", - "\n", - " W.load_scenario(\"dat/sfnetwork.uxsim_scenario\")\n", - " W.finalize_scenario()\n", - "\n", - " return W\n", + "solver_DSO = SolverDSO(create_World)\n", + "solver_DSO.solve(max_iter=300, initial_solution_World=W_DUE)\n", + "W_DSO = solver_DSO.W_sol" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "solver_DSO.plot_convergence()\n", + "solver_DSO.plot_link_stats()\n", + "solver_DSO.plot_vehicle_stats(orig=\"4\", dest=\"7\")\n", "\n", - "solver = SolverDSO(create_World)\n", - "solver.solve(max_iter=300, initial_solution_World=W_DUE)\n", - "W_DSO = solver.W_sol\n", - "solver.plot_convergence()\n", - "solver.plot_link_stats()\n", - "solver.plot_vehicle_stats(orig=\"4\", dest=\"7\")\n", + "routes = enumerate_k_random_routes(W, k=5)\n", + "o, d = \"13\", \"10\"\n", + "print(f\"{o}-{d}: # of routes: {len(routes[o,d])}, min # of links: {min([len(r) for r in routes[o,d]])}\")\n", + "solver_DSO.plot_vehicle_stats(orig=o, dest=d)\n", + "o, d = \"10\", \"13\"\n", + "print(f\"{o}-{d}: # of routes: {len(routes[o,d])}, min # of links: {min([len(r) for r in routes[o,d]])}\")\n", + "solver_DSO.plot_vehicle_stats(orig=o, dest=d)\n", + "o, d = \"20\", \"10\"\n", + "print(f\"{o}-{d}: # of routes: {len(routes[o,d])}, min # of links: {min([len(r) for r in routes[o,d]])}\")\n", + "solver_DSO.plot_vehicle_stats(orig=o, dest=d)\n", + "o, d = \"10\", \"20\"\n", + "print(f\"{o}-{d}: # of routes: {len(routes[o,d])}, min # of links: {min([len(r) for r in routes[o,d]])}\")\n", + "solver_DSO.plot_vehicle_stats(orig=o, dest=d)\n", "\n", "W_DSO.analyzer.print_simple_stats(force_print=True)\n", "W_DSO.analyzer.macroscopic_fundamental_diagram()\n", @@ -2018,27 +2048,35 @@ "source": [ "#DSO GA\n", "\n", - "# scenario definition\n", - "def create_World():\n", - " W = uxsim.World(\n", - " name=\"\",\n", - " deltan=10,\n", - " tmax=9600,\n", - " print_mode=0, save_mode=0, show_mode=1,\n", - " random_seed=0\n", - " )\n", - "\n", - " W.load_scenario(\"dat/sfnetwork.uxsim_scenario\")\n", - " W.finalize_scenario()\n", + "solver_DSO_GA = SolverDSO_GA(create_World)\n", + "solver_DSO_GA.solve(max_iter=300, initial_solution_World=W_DUE)\n", + "W_DSO = solver_DSO_GA.W_sol" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "\n", - " return W\n", + "solver_DSO_GA.plot_convergence()\n", + "solver_DSO_GA.plot_link_stats()\n", + "solver_DSO_GA.plot_vehicle_stats(orig=\"4\", dest=\"7\")\n", "\n", - "solver = SolverDSO_GA(create_World)\n", - "solver.solve(max_iter=300, initial_solution_World=W_DUE)\n", - "W_DSO = solver.W_sol\n", - "solver.plot_convergence()\n", - "solver.plot_link_stats()\n", - "solver.plot_vehicle_stats(orig=\"4\", dest=\"7\")\n", + "routes = enumerate_k_random_routes(W, k=5)\n", + "o, d = \"13\", \"10\"\n", + "print(f\"{o}-{d}: # of routes: {len(routes[o,d])}, min # of links: {min([len(r) for r in routes[o,d]])}\")\n", + "solver_DSO_GA.plot_vehicle_stats(orig=o, dest=d)\n", + "o, d = \"10\", \"13\"\n", + "print(f\"{o}-{d}: # of routes: {len(routes[o,d])}, min # of links: {min([len(r) for r in routes[o,d]])}\")\n", + "solver_DSO_GA.plot_vehicle_stats(orig=o, dest=d)\n", + "o, d = \"20\", \"10\"\n", + "print(f\"{o}-{d}: # of routes: {len(routes[o,d])}, min # of links: {min([len(r) for r in routes[o,d]])}\")\n", + "solver_DSO_GA.plot_vehicle_stats(orig=o, dest=d)\n", + "o, d = \"10\", \"20\"\n", + "print(f\"{o}-{d}: # of routes: {len(routes[o,d])}, min # of links: {min([len(r) for r in routes[o,d]])}\")\n", + "solver_DSO_GA.plot_vehicle_stats(orig=o, dest=d)\n", "\n", "W_DSO.analyzer.print_simple_stats(force_print=True)\n", "W_DSO.analyzer.macroscopic_fundamental_diagram()\n", From 7de857a4a50d061592267cfc4d5c1b0eff26f111 Mon Sep 17 00:00:00 2001 From: Toru Seo <34780089+toruseo@users.noreply.github.com> Date: Mon, 6 Jan 2025 18:42:26 +0900 Subject: [PATCH 2/2] Update measure-coverage.yml --- .github/workflows/measure-coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/measure-coverage.yml b/.github/workflows/measure-coverage.yml index 09363ea..0d7551e 100644 --- a/.github/workflows/measure-coverage.yml +++ b/.github/workflows/measure-coverage.yml @@ -25,7 +25,7 @@ jobs: - name: Install pytest other dependencies run: pip install pytest pytest-rerunfailures pytest-xdist pytest-cov setuptools osmnx requests - name: Run verifications with pytest - run: pytest -n auto 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 tests/test_verification_multilane.py tests/test_verification_taxi.py test_verification_dta_solvers.py tests/test_other_functions.py --durations=0 -v --cov=uxsim --cov-report=xml --cov-config=.github/.coveragerc + run: pytest -n auto 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 tests/test_verification_multilane.py tests/test_verification_taxi.py tests/test_verification_dta_solvers.py tests/test_other_functions.py --durations=0 -v --cov=uxsim --cov-report=xml --cov-config=.github/.coveragerc - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v5.0.2 with: