Skip to main content

A collection of pre-simulation optimization algorithms for eFLIPS.

Project description

eflips-opt


Part of the eFLIPS/simBA list of projects.


This repository contains code for optimizing (electric) bus networks. The following optimization problems are considered:

Installation

  1. Clone the repository

    git clone git@github.com:mpm-tu-berlin/eflips-opt.git
    
  2. Install the packages listed in poetry.lock and pyproject.toml into your Python environment. Notes:

    • The suggested Python version is 3.11.*, it may work with other versions, but this is not tested.
    • Using the poetry package manager is recommended. It can be installed according to the instructions listed here.
  3. In order to use the Depot-Rotation Matching, it is recommended to install the

  4. Gurobi solver. The solver can be installed by following the instructions listed here. The solver can be used with a license for academic purposes. If you do not have a license, you can request one here.

Usage

Depot-Rotation Matching

Example scripts for the Depot-Rotation Matching problem can be found in the examples/depot_rotation_matching directory. The general usage is as follows:

from eflips.opt.depot_rotation_matching import DepotRotationOptimizer

# Initialize the optimizer
optimizer = DepotRotationOptimizer(session, SCENARIO_ID)

# Create a depot input. Both existing and new depots can be added.
user_input_depot = [
   {
       "depot_station": 103281393,
       "capacity": 300,
       "vehicle_type": [84, 86, 87, 90],
   },  # Indira-Gandhi-Str
   {
       "name": "Suedost",
       "depot_station": (13.497371828836501, 52.46541010322369),
       "capacity": 260,
       "vehicle_type": [82, 84, 85, 86, 87, 90],
   },  # Südost
]
optimizer.get_depot_from_input(user_input_depot)
optimizer.data_preparation()
optimizer.optimize(time_report=True)
optimizer.write_optimization_results(delete_original_data=True)

Simplified Electric Vehicle Scheduling Problem


This section is not current, it will be updated soon.


Example scripts for the Simplified Electric Vehicle Scheduling Problem can be found in the examples/simplified_electric_vehicle_scheduling_problem directory. It creates a graph of all possible trips and their possible connections. The minimum number of rotations is now a minimum path cover of the graph. This is what the minimum_path_cover_rotation_plan() function does. Its result however tries to make rotations as long as possible, ignoring the fact that the bus might need to be recharged (this is useful for identifying terminus stations to electrify though.

In order to find a rotation plan that considers the battery state of the bus, the soc_aware_rotation_plan() function can be used. It iterates over the solution of the minimum_path_cover_rotation_plan() function and heuristically finds a good rotation plan that considers the battery state of the bus.

Known issues

  • The result is not optimal in terms of minimum waiting time at each terminus. This could be improved by fine-tuning the candidate selection process in the create_graph_of_possible_connections() function.
  • The result is not stable, changing with each new python process. This is due to there being multiple minimum path c covers of the graph. This could possibly be fixed by iterating over all minimum path covers and selecting the one that minimizes the dwell durations or the energy consumption of each bus. See here for a possible implementation (but be careful of the combination explosion)

Usage

# You probably want to create one schedule for each vehicle type, e.g. not connect 12m buses' trips with 18m buses' trips
trips_by_vt = passenger_trips_by_vehicle_type(scenario, session)
for vehicle_type, trips in trips_by_vt.items():
   # The connection graph is what the schedule will be based on
   graph = create_graph_of_possible_connections(trips)
   
   # The minimum path cover rotation plan just makes rotations as long as possible
   rotation_graph = minimum_path_cover_rotation_plan(graph)
   
   # The soc aware rotation plan tries to make rotations that consider the battery state of the bus
   soc_aware_graph = soc_aware_rotation_plan(graph, soc_reserve=SOC_RESERVE)
   
   # The rotation plan can be visualized
   visualize_with_dash_cytoscape(soc_aware_graph)

Development

We utilize the GitHub Flow branching structure. This means that the main branch is always deployable and that all development happens in feature branches. The feature branches are merged into main via pull requests.

We use black for code formatting. You can use pre-commit to ensure the code is formatted correctly before committing. You are also free to use other methods to format the code, but please ensure that the code is formatted correctly before committing.

Please make sure that your poetry.lock and pyproject.toml files are consistent before committing. You can use poetry check to check this. This is also checked by pre-commit.

License

This project is licensed under the AGPLv3 license - see the LICENSE file for details.

Funding Notice

This code was developed as part of the project eBus2030+ funded by the Federal German Ministry for Digital and Transport (BMDV) under grant number 03EMF0402.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eflips_opt-1.0.2.tar.gz (41.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eflips_opt-1.0.2-py3-none-any.whl (42.3 kB view details)

Uploaded Python 3

File details

Details for the file eflips_opt-1.0.2.tar.gz.

File metadata

  • Download URL: eflips_opt-1.0.2.tar.gz
  • Upload date:
  • Size: 41.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for eflips_opt-1.0.2.tar.gz
Algorithm Hash digest
SHA256 6fc4cad0ee1b5034e20b59b32c1f8a58223624eb3a4f9a3ec72bd5c0160b8d2e
MD5 d5cd3573f4e054c63e86a494404b5e04
BLAKE2b-256 0aaff13e878547e5cab764abbfc3aece398fef085e1218b79d9ff479cbf3edb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for eflips_opt-1.0.2.tar.gz:

Publisher: release.yml on mpm-tu-berlin/eflips-opt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file eflips_opt-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: eflips_opt-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 42.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for eflips_opt-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b4c9d0e045152b89e5e8574a7c2ba19c14ce36ec7aa98383e0b06a83c4a8f128
MD5 da3baf0850f190a525a00d3cd4401342
BLAKE2b-256 abb38ec2f14c515e91fd8eac98d336ab5cd311db2b6c8f881ca682a42ac457a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for eflips_opt-1.0.2-py3-none-any.whl:

Publisher: release.yml on mpm-tu-berlin/eflips-opt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page