model.network

Classes

Line

The Line represents a bus line, which is a collection of Route that belong together. This may not

Route

A route is a fixed geometry that a bus takes. It is a part of a Line. A trip takes place on a route.

VoltageLevel

The voltage level of a charging infrastructure. Used in analysis and simulation to determine grid load.

ChargeType

The type of charging infrastructure. Only vehicle types with opportunity charging can charge at opportunity

Station

A Station is a point on the map that a bus can stop at. It is visited on a Trip.

AssocRouteStation

An association table between Route and Station. It is used to represent the stops on a route.

Functions

check_route_before_insert_or_update(_, __, target)

Check the route before flushing it to the database.

Module Contents

class model.network.Line

Bases: eflips.model.Base

The Line represents a bus line, which is a collection of Route that belong together. This may not include all routes that a bus on this line takes over its service day, since depot and deadhead routes are not included (they can be shared between multiple lines).

__tablename__ = 'Line'
id: sqlalchemy.orm.Mapped[int]

The unique identifier of the battery type. Auto-incremented.

scenario_id: sqlalchemy.orm.Mapped[int]

The unique identifier of the scenario. Foreign key to Scenario.id.

scenario: sqlalchemy.orm.Mapped[eflips.model.Scenario]

The scenario.

name: sqlalchemy.orm.Mapped[str]

The name of the line. Usually a number or letter, e.g. “1” or “A” followed by the terminal stations. Example: “1 - Hauptbahnhof <-> Hauptfriedhof”

name_short: sqlalchemy.orm.Mapped[str]

The short name of the line. Usually a number or letter, e.g. “1” or “A”.

routes: sqlalchemy.orm.Mapped[list[Route]]
__repr__()
Return type:

str

class model.network.Route

Bases: eflips.model.Base

A route is a fixed geometry that a bus takes. It is a part of a Line. A trip takes place on a route.

__tablename__ = 'Route'
id: sqlalchemy.orm.Mapped[int]

The unique identifier of the battery type. Auto-incremented.

scenario_id: sqlalchemy.orm.Mapped[int]

The unique identifier of the scenario. Foreign key to Scenario.id.

scenario: sqlalchemy.orm.Mapped[eflips.model.Scenario]

The scenario.

departure_station_id: sqlalchemy.orm.Mapped[int]

The unique identifier of the departure station. Foreign key to Station.id.

departure_station: sqlalchemy.orm.Mapped[Station]

The departure station.

arrival_station_id: sqlalchemy.orm.Mapped[int]

The unique identifier of the arrival station. Foreign key to Station.id.

arrival_station: sqlalchemy.orm.Mapped[Station]

The arrival station.

line_id: sqlalchemy.orm.Mapped[int]

The unique identifier of the line. Foreign key to Line.id. May be None.

line: sqlalchemy.orm.Mapped[Line]

The line.

name: sqlalchemy.orm.Mapped[str]

The name of the route. Usually a number followed by the terminal station. Example: “1 Hauptbahnhof -> Hauptfriedhof

name_short: sqlalchemy.orm.Mapped[str]

The short name of the route (if available).

headsign: sqlalchemy.orm.Mapped[str]

The headsign of the route (if available). This is whatever is displayed on the bus.

distance: sqlalchemy.orm.Mapped[float]

The length of the route in meters.

geom: sqlalchemy.orm.Mapped[geoalchemy2.Geometry]

The shape of the route as a 3D polyline (X = lon, Y = lat, Z = elevation in meters). If set, the 2D ground length of this shape must be within 50 meters of Route.distance — Z is ignored by the length check, by PostGIS’ ST_Length(..., true) and SpatiaLite’s GeodesicLength. Use WGS84 coordinates (EPSG:4326). Z = 0 is acceptable when elevation is unknown; populate it via the eflips-ingest elevation backfill.

trips: sqlalchemy.orm.Mapped[List[eflips.model.Trip]]

The trips.

assoc_route_stations: sqlalchemy.orm.Mapped[List[AssocRouteStation]]

The associated route stations. This contains metadata about the stops on the route, such as the partial distance.

stations: sqlalchemy.orm.Mapped[List[Station]]

This is a list of all stations on the route.

__table_args__
__repr__()
Return type:

str

static calculate_length(session, linestring)

Portable function to calculate the length of a linestring in meters. It adapts to whether the database uses PostGIS or SpatiaLite.

Parameters:
  • session (sqlalchemy.orm.session.Session) – An open SQLAlchemy session.

  • linestring (str) – A string representation of a linestring in WKT format.

Returns:

The length of the linestring in meters.

Return type:

float

model.network.check_route_before_insert_or_update(_, __, target)

Check the route before flushing it to the database. - Ensure that the distance of the first stop time is 0 - Ensure that the distance of the last stop time is the distance of the route - Ensure that the first and last associated route stations correspond to the departure and arrival stations

  • If we have stop times, we must ensure that the temporal order of stop times matches the spatial order of the stations.

Parameters:
  • target (Route)

  • _ (Any)

  • __ (Any)

Returns:

Nothing. Raises an exception if the route is invalid.

Return type:

None

class model.network.VoltageLevel(*args, **kwds)

Bases: enum.Enum

The voltage level of a charging infrastructure. Used in analysis and simulation to determine grid load.

HV

High Voltage, e.g. 110kV transmission grid

HV_MV

Both high and medium voltage

MV

Medium Voltage, e.g. 10kV distribution grid

MV_LV

Both medium and low voltage

LV

Low voltage, e.g. 400V three- phase

class model.network.ChargeType(*args, **kwds)

Bases: enum.Enum

The type of charging infrastructure. Only vehicle types with opportunity charging can charge at opportunity charging stations.

depb

Only charge when vehicle is not on a rotation

oppb

Aka „terminus charging“. While on a rotation, charge in the breaks between trips

DEPOT

Legacy value for depb

OPPORTUNITY

Legacy value for oppb

class model.network.Station

Bases: eflips.model.Base

A Station is a point on the map that a bus can stop at. It is visited on a Trip. The station may not mark the exact location of the stop, but rather a point nearby, in case the station is part of a larger complex.

__tablename__ = 'Station'
id: sqlalchemy.orm.Mapped[int]

The unique identifier of the battery type. Auto-incremented.

scenario_id: sqlalchemy.orm.Mapped[int]

The unique identifier of the scenario. Foreign key to Scenario.id.

scenario: sqlalchemy.orm.Mapped[eflips.model.Scenario]

The scenario.

name: sqlalchemy.orm.Mapped[str]

The name of the station. Example: “Hauptbahnhof”

name_short: sqlalchemy.orm.Mapped[str]

The short name of the station (if available).

geom: sqlalchemy.orm.Mapped[geoalchemy2.Geometry]

The (optional) 3D location of the station (X = lon, Y = lat, Z = elevation in meters). Use WGS84 coordinates (EPSG:4326). Z = 0 is acceptable when elevation is unknown.

is_electrified

Whether the station has a charging infrastructure. If yes, then

  • amount_charging_places must be set

  • power_per_charger must be set

  • power_total must be set

  • charge_type must be set

  • voltage_level must be set

is_electrifiable

Whether the station can be electrified. This is used to determine whether a station can be electrified in the simulation. If the station is electrified, this must be set to true.

amount_charging_places

The amount of charging poles at the station. If is_electrified is true, this must be set.

power_per_charger

The power per charger in kW. If is_electrified is true, this must be set.

power_total

The total power of the charging infrastructure in kW. If is_electrified is true, this must be set.

charge_type

The type of charging infrastructure. If is_electrified is true, this must be set.

When running simBA and eflips, this is set to oppb for all stations. depb only makes sense in standalone simBA runs.

voltage_level

The voltage level of the charging infrastructure. If is_electrified is true, this must be set.

charging_point_type_id: sqlalchemy.orm.Mapped[int]

The unique identifier of the charging point type. Foreign key to ChargingPointType.id

charging_point_type: sqlalchemy.orm.Mapped[eflips.model.ChargingPointType]

The charging point type. This is used to represent the different types of charging points installed at stations or areas. It is mainly relevant for TCO calculations.

tco_parameters: sqlalchemy.orm.Mapped[Dict[str, Any]]

The TCO parameters of the charging point stored as a JSON object.

This field contains Total Cost of Ownership parameters used for financial analysis and planning of the charging station. The JSON object includes:

  • useful_life (int): Expected operational lifespan of the charging station in years (e.g., 20)

  • procurement_cost (float): Initial acquisition cost per station or depot.

  • cost_escalation (float): Annual cost escalation rate as a decimal between 0 and 1 (e.g., 0.02 represents 2% annual escalation)

depot: sqlalchemy.orm.Mapped[eflips.model.Depot]

The (optional) depot that is associated with this station. Only set if the station has a depot.

routes_departing: sqlalchemy.orm.Mapped[List[Route]]
routes_arriving: sqlalchemy.orm.Mapped[List[Route]]
stop_times: sqlalchemy.orm.Mapped[List[eflips.model.StopTime]]

The stop times.

trips: sqlalchemy.orm.Mapped[List[eflips.model.Trip]]

The trips stopping at this station.

assoc_route_stations: sqlalchemy.orm.Mapped[List[AssocRouteStation]]

The associated route stations. This contains metadata about the stops on the route, such as the partial distance.

routes: sqlalchemy.orm.Mapped[List[Route]]

This is a list of all routes that stop at this station.

events: sqlalchemy.orm.Mapped[List[eflips.model.Event]]

The events that take place at this station. Only expected to be filled for charging at electrified stations.

__table_args__
__repr__()
Return type:

str

class model.network.AssocRouteStation

Bases: eflips.model.Base

An association table between Route and Station. It is used to represent the stops on a route.

__tablename__ = 'AssocRouteStation'
id: sqlalchemy.orm.Mapped[int]

The unique identifier of the association. Auto-incremented.

scenario_id: sqlalchemy.orm.Mapped[int]

The unique identifier of the scenario. Foreign key to Scenario.id.

scenario: sqlalchemy.orm.Mapped[eflips.model.Scenario]

The scenario.

route_id: sqlalchemy.orm.Mapped[int]

The unique identifier of the route. Foreign key to Route.id.

route: sqlalchemy.orm.Mapped[Route]

The route.

station_id: sqlalchemy.orm.Mapped[int]

The unique identifier of the station. Foreign key to Station.id.

station: sqlalchemy.orm.Mapped[Station]

The station.

location: sqlalchemy.orm.Mapped[geoalchemy2.Geometry]

An optional precise 3D location of this route’s stop at the station (X = lon, Y = lat, Z = elevation in meters). Use WGS84 coordinates (EPSG:4326). Z = 0 is acceptable when elevation is unknown.

elapsed_distance: sqlalchemy.orm.Mapped[float]

The distance in m that the bus has traveled when it reached this stop.

__repr__()
Return type:

str