Skip to content

Commit

Permalink
Olusanya (#358)
Browse files Browse the repository at this point in the history
* Car assignment last in end assigment (#352)

* Fix minor bug where buses in background traffic was sometimes for wrong
time period in iteration 1

* Do bike assignment before car assignment in last iteration
Need to explicitly set car vdfs after bike assignment

* Fix pandas indexing (#353)

* Enable workforce accessibility calculation and printing (#355)

* Merge README (#356)

* Fix `WindowsError` (#343)

* Fix `WindowsError`

`subprocess.CalledProcessError` only works if git client is installed

* Update version number

* Update README.md (#354)

* Update README.md

* Print line optimization (#359)

* Speed up line prints when printing many lines

* Re-add printing of the first line
  • Loading branch information
Jens West committed Aug 27, 2021
1 parent 9cf580a commit 78259e1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 28 deletions.
44 changes: 26 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,54 @@ This repository contains python files for Helmet 4.1 Model System. Source codes

## Usage

In this chapter, we will guide you how to install HELMET 4.1 to work with INRO Emme software. The user is not expected to install any new software apart from [helmet-model-system](https://github.com/HSLdevcom/helmet-model-system) and [helmet-ui](https://github.com/HSLdevcom/helmet-ui).
You can run HELMET 4.1 from the command line or by using [helmet-ui](https://github.com/HSLdevcom/helmet-ui).
In this chapter, we will guide you how to install HELMET 4.1 to work with Inro EMME software from the command line.
The user is not expected to install any new software apart from [helmet-model-system](https://github.com/HSLdevcom/helmet-model-system) and EMME.

If you do not have an Emme license or you wish to develop HELMET 4.1 further, please scroll down to [Development](#development) chapter.

### Setup

In production, we are using Python 3.7 which is supported by and installed together with INRO Emme 4.5 software.
From this repository, copy the contents of the [Scripts](Scripts) folder to your computer.

We are using those Python dependencies that come with INRO Emme installation. To get access to these dependencies, you need to add them to your local PATH variable:
In production, we are using Python 3.7 which is supported by and installed together with INRO Emme software.
We are using those Python dependencies that come with Inro EMME installation.
To get access to these dependencies, you need to add them to your local PATH variable:

1. Open Control Panel.
2. Go to User Accounts, then click again User Accounts, then select from the left hand menu "Change my environment variables".
3. From the top box ("User variables for USERNAME"), find and select "Path" variable, and click "Edit...".
4. Click "New" and write `%EMMEPATH%\Programs`.
5. Click OK in the "Edit environment variable" window, and then click OK again in the "Environment Variables" window.
5. Click "New" and write `%EMMEPATH%\Python37`.
6. Click "New" and write `%EMMEPATH%\Python37\Scripts`.
7. Click OK in the "Edit environment variable" window, and then click OK again in the "Environment Variables" window.

Next, you need to initialize an Emme project:
Emme assignment can be tested without further configuration.
Open command line to your local Scripts folder and write:

```
python test_assignment.py
```

This will create a small EMME test network and run test assignments on it.

You can also initialize a proper Emme project (if you do not want to use the test network):

1. Open Emme desktop application.
2. Create new project called `helmet-model-system` in which the path should match your project name and path.
- The wizard should create you a (large binary) file called `helmet-model-system.emp` inside your project folder
3. Follow external instructions to configure the details of the Emme project. Now, your working folder is filled with Emme project specific folders and files.
4. From this repository, copy the contents of the [Scripts](Scripts) folder to the "Scripts" folder in the Emme project.
2. Create new project in which the path should match your project name and path.
3. Follow [external instructions](https://hsldevcom.github.io/helmet-ui/sijopankki.html) to configure the details of the Emme project.
Now, your working folder is filled with Emme project specific folders and files.

### Running

You can run HELMET 4.1 from the command line or by using [helmet-ui](https://github.com/HSLdevcom/helmet-ui). Before running from the command line, set the configurations in [dev-config.json](Scripts/dev-config.json). Then, open command line to your Emme project and type:
Before running from the command line, set the configurations in [dev-config.json](Scripts/dev-config.json).
Instructions on the configuration settings are found [here](Scripts#running-the-model-system).
Then, open command line to your local Scripts folder:

```
cd Scripts
python helmet.py
```

Emme assignment can be tested without further configuration:

```
cd Scripts
python test_assignment.py
```

## Development

If you do not have INRO Emme license or you wish to develop HELMET 4.1 source code, you need to set up a development environment. Although not covered here, installing [Git](https://git-scm.com/downloads) is highly recommended!
Expand Down
8 changes: 4 additions & 4 deletions Scripts/assignment/assignment_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def assign(self, matrices, iteration):
elif iteration==1:
if not self._save_matrices:
self._set_car_and_transit_vdfs()
self._calc_background_traffic()
self._assign_cars(param.stopping_criteria_coarse)
self._calc_extra_wait_time()
self._assign_transit()
Expand All @@ -120,15 +121,14 @@ def assign(self, matrices, iteration):
self._calc_extra_wait_time()
self._assign_transit()
elif iteration=="last":
if not self._save_matrices:
self._set_car_and_transit_vdfs()
self._set_bike_vdfs()
self._assign_bikes(self.result_mtx["dist"]["bike"]["id"], "all")
self._set_car_and_transit_vdfs()
self._calc_background_traffic()
self._assign_cars(param.stopping_criteria_fine)
self._calc_boarding_penalties(is_last_iteration=True)
self._calc_extra_wait_time()
self._assign_congested_transit()
self._set_bike_vdfs()
self._assign_bikes(self.result_mtx["dist"]["bike"]["id"], "all")
else:
raise ValueError("Iteration number not valid")

Expand Down
4 changes: 2 additions & 2 deletions Scripts/cba.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ def run_cost_benefit_analysis(scenario_0, scenario_1, year, workbook):
transit_mile_diff = (read(TRANSIT_KMS_FILE, scenario_1)
- read(TRANSIT_KMS_FILE, scenario_0))
for mode in TRANSIT_AGGREGATIONS:
transit_mile_diff[mode] = 0
transit_mile_diff.loc[mode] = 0
for submode in TRANSIT_AGGREGATIONS[mode]:
transit_mile_diff[mode] += transit_mile_diff[submode]
transit_mile_diff.loc[mode] += transit_mile_diff.loc[submode]
ws = workbook["Tuottajahyodyt"]
cols = CELL_INDICES["transit_miles"]["cols"]
rows = CELL_INDICES["transit_miles"]["rows"][year]
Expand Down
9 changes: 6 additions & 3 deletions Scripts/datahandling/resultdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ def print_line(self, line, filename):
filename : str
Name of file where text is pushed (can contain other text)
"""
if filename not in self._line_buffer:
self._line_buffer[filename] = open(
try:
buffer = self._line_buffer[filename]
except KeyError:
buffer = open(
os.path.join(self.path, "{}.txt".format(filename)), 'w')
self._line_buffer[filename].write(line + "\n")
self._line_buffer[filename] = buffer
buffer.write(line + "\n")

def print_matrix(self, data, filename, sheetname):
"""Save 2-d matrix data to buffer (printed to file when flushing).
Expand Down
2 changes: 1 addition & 1 deletion Scripts/modelsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _add_internal_demand(self, previous_iter_impedance, is_last_iteration):
purpose_impedance = self.imptrans.transform(
purpose, previous_iter_impedance)
purpose.calc_prob(purpose_impedance)
if is_last_iteration and purpose.dest != "source":
if is_last_iteration and purpose.name not in ("sop", "so"):
purpose.accessibility_model.calc_accessibility(
purpose_impedance)

Expand Down

0 comments on commit 78259e1

Please sign in to comment.