From 2d99352d096ce75bcbdbdb5a15d818f4e0eb99d3 Mon Sep 17 00:00:00 2001 From: Ruben1729 Date: Wed, 14 Feb 2024 17:26:20 -0500 Subject: [PATCH] Updated matsim example with docs --- README.md | 25 +++++++++++-------- __pycache__/matsim.cpython-39.pyc | Bin 9265 -> 9122 bytes __pycache__/matsim_visualizer.cpython-39.pyc | Bin 4842 -> 4970 bytes main.py | 4 +-- matsim_visualizer.py | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 12bf23a..2a906c7 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ ## Requirements - [x] [JDK 17](https://www.oracle.com/java/technologies/downloads/#java17) - [x] Python 3 +- [x] Input file holding the network of the city (For example: merged-network.osm.pbf) +- [x] Input GeoJSON file with all buildings (For example: summerschool_all_buildings.geojson) ## Goal Estimate city pollution coming from people driving in vehicles. @@ -12,18 +14,21 @@ Make sure to have JDK 17 installed and clone this repository. ## Usage The file `main.py` is essentially a replica from MEB workflow. It constructs a city and then allows the user to apply characteristics to that given city. -The difference is in the implementation of MatSimEngine. This engine should create the following files: -- facilities.xml -- network.xml -- population.xml -- config.xml +The additional steps from the MEB workflow are: +1. Generate Matsim required xml files. +2. Run Matsim analysis. +3. Visualize Matsim results. -Facilities and network are quite simple as the facilities file can be built from our city object and the network file can be built using a matsim utility along with OpenStreetMaps data. The population file must be generated via other ways and the config file can be generated once the first 3 files are created. +### 1- Generate Matsim Required XML Files -Additionally, it may be interesting to include public transport in the simulation. This is a potentially simple task. Montreal offers the GTFS files for its public transport for free and the project [PT2MATSim](https://github.com/matsim-org/pt2matsim) allows you to create the MatSim xml files from the initial GTFS files. +This step is done in `matsim.py`. The class was built to replicate the behavior of other HUB export factory classes. It takes in a city object, an output directory, and then generates all the xml files required by Matsim. -## Visualization +### 2- Run Matsim Analysis + +This step is done in `matsim_engine.py`. It simply runs the matsim.jar while providing the config.xml file generated in the previous step. + +### 3- Visualize Matsim Results + +This step is done in `matsim_visualizer.py`. It takes in a network and events xml file generated by the previous step and then displays it on a graph. It then shows in heatmap style the change in traffic over time. -Given we want to be able to visualize the results similar to the way the Munich scenario did it: https://www.matsim.org/gallery/munich. -The repository also has the code to visualize these results. It's a very basic implementation, but it basically uses matplotlib and nx to plot the network and how much traffic exists on a given link at a given time. diff --git a/__pycache__/matsim.cpython-39.pyc b/__pycache__/matsim.cpython-39.pyc index 625f92be38362ebc138cff73406bcfab29a41f0f..105f345b0040ec7977ddf5f03b4a1acb507bf3ad 100644 GIT binary patch delta 1514 zcmZuxO>7%Q6yBL#+iS;8;*>i6OX4_D6RVA7r$Mw;QIh7TO-USAaT{VGtWDN&E#jYy zHzYAO0fHh@RH|kU2x!%$M-GU}2&e=S95{dgap1H_MVz>BK%6Qn0q?DofPkHyZ{EzC z_ukC=nR^%Ro^Mnf4x0eqxzpdI)hBK?`pM4CA_^qju@_ahAmRr&r$A?EICMOaTV>7AI#AwLLt+p@t zPc{#^${*RTQsSyDH=H6cd)GeLWCwGO1G6fvJ+#Ncu1!6rHG|zAup2nE+gmd?tAuOL zfa5rbgq%!-ft}#*JAId;KElKxZ%uf(c;^KyQps$1hI~ zCnlz2#(C`w-OR4=NXyB-IV7J&m_mpl;F0Tq2WRLw4SI?3J1q>Z$2*RMn%uC0h75Q9 zN^7%69#B`srC!t;;9gJN7B|IxZ%*=US3imKPh2079M@W_WSRfgnjs~gbgz>Y{=NGa zS?9~1xOW}&g=o^cs${inJ`>l_xryLmpx}YN2f;;bMdjjLLtAH%>-uV zW)fplfgm$NXx|SZni=9J+xq=~2g`_#ZDcw&K5^cNjGJ$@{YVtP*q$@j!@(c4x0*i( z;nIivQTqpy=mPiO@7OY3knQpm9}Nt8t{X?J$Gg2w8(A~NZv}c4i*~}U)pk0& zh>R&3lG#Q6Y4CCLB#LGE!(f|f5XcSg?TT(7wIBf;e3(LqRrxJUDxxZ^K>DeqDpsgL zyH#4Hnoto`ag*K%SEY)yOH^r(5CN$QJ){UyvrxnmG)%y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8PkRrH>@{f7oP6Ol!BK>J z$Rb~C%$AO!a6_&(K7U;$-E+6!sWTYszix1ajHuW=dm!(d^3R6<;Tc+^yx}zhYA&A3 zNL<(a$Sby155U{Zdr&lr(#lFA6cO*0ilS-*@J8GnPey$Xup;jtm_M0^%=fB1Ndiys zHS|mAcqpvNDr$?hRFk!s{#RL(s(qS$Ezj7u7lLwN1ZH5}(U>B%UHh)Wlt8(r^eR`e ztYS;#V|$q$lvU@|6$jo#LO4(G9sxzk%yiOEqFAIbO=9Dk?_o7p@Kk#Ji2uW~<;)$w zL3%C1Bc3-;PrVI}KiaK$bHBDs8-zo+DSvPlSs?eE8D`5;^TNzw3iiL)L zj#Ih(B)(=bbB9Z1u&;Us=w2_ZB0uZXQ;yPc6IDEBDrFD0MQEGrjZSd%|D aSLgDQ{%utpIH0=>bc}vTUYt6@)V~3M-Y;kX diff --git a/main.py b/main.py index 8559450..a2a0fee 100644 --- a/main.py +++ b/main.py @@ -25,10 +25,10 @@ try: ConstructionFactory(construction_format, city).enrich() UsageFactory(usage_format, city).enrich() - Matsim(city, 'output_files')._export() + Matsim(city, 'output_files').export() MatSimEngine('output_files/Montreal_config.xml').run() - visualizer = MatsimVisualizer('output_files/Montreal/output_network.xml.gz', 'output_files/Montreal/output_events.xml.gz') + visualizer = MatsimVisualizer('output_files/Montreal/output_network.xml.gz', 'output_files/Montreal/output_events.xml.gz', 'output_files') visualizer.visualize() except Exception as ex: diff --git a/matsim_visualizer.py b/matsim_visualizer.py index 55fd178..1a11b8c 100644 --- a/matsim_visualizer.py +++ b/matsim_visualizer.py @@ -95,7 +95,7 @@ class MatsimVisualizer(): traffic_data = self._cumulative_traffic[tick] edge_colors = [self._cmap(self.norm(traffic_data.get(link['id'], 0))) for link in self._links] - edge_widths = [10 + self.norm(traffic_data.get(link['id'], 0)) * 10 for link in self._links] + edge_widths = [1 + self.norm(traffic_data.get(link['id'], 0)) * 10 for link in self._links] plt.cla() nx.draw(self._G, self._pos, node_size=0, node_color='blue', width=edge_widths, edge_color=edge_colors,