Dispatching

class dispatching.BaseDispatcher[source]

Base class for dispatchers. Not useful to instantiate on its own.

All classes that inherit form BasePredictor should implement ‘dispatch()’ to choose from a list of Vehicle objects, which one to dispatch to a specified location.

dispatch(destination_coords, candidate_vehicles)[source]

Decide which vehicle to dispatch

load_time_matrix(path='data/responsetimes/time_matrix.csv')[source]

Load a pre-calculated matrix with travel durations.

move_station(destination_coords, candidate_vehicles)[source]

Move the location of a single station.

save_time_matrix(path='data/responsetimes/time_matrix.csv')[source]

Save the matrix with travel durations.

set_custom_stations(destination_coords, candidate_vehicles)[source]

Set custom station locations.

class dispatching.ShortestDurationDispatcher(demand_locs=None, station_locs=None, osrm_host='http://192.168.56.101:5000', load_matrix=True, save_matrix=False, data_dir='data', verbose=True)[source]
Dispatcher that dispatches the vehicle with the shortest travel time
estimated by the Open Source Routing Machine (OSRM).
Parameters:
  • demand_locs (dict) – The coordinates of demand locations, as a dictionary like: {‘demand location id’ -> (longitude, latitude)}. Ignored when load_matrix=True.
  • station_locs (dict) – The coordinates of the fire stations. Same form as demand_locs. Ignored when load_matrix=True.
  • osrm_host (str) – The URL to the OSRM API. Ignored when load_matrix=True.
  • load_matrix (boolean) – Whether to load the matrix of travel times from disk instead of computing it with OSRM. Defaults to True.
  • save_matrix (boolean) – Whether to save the computed time matrix to disk after computing it with OSRM. Optional, defaults to false.
  • data_dir (str) – The directory to store the time matrix and/or load it from.
  • verbose (boolean) – Whether to print progress to console.
add_station(station_name, location)[source]

Create a new fire station at a specified location.

Parameters:
  • station_name (str) – The name of the station to move.
  • new_location (str or tuple(float, float)) – The new location of the station. Either a string matching the ID of a demand location or a tuple of decimal longitude latitude.
dispatch(destination_loc, candidate_vehicles)[source]
Dispatches the vehicle with the shortest estimated response time
according to OSRM.
Parameters:
  • destination_loc (str) – The ID of the demand location to dispatch to.
  • candidate_vehicles (array-like of Vehicle objects) – Vehicle objects with their current state and locations.
Returns:

Return type:

ID of the vehicle to dispatch.

get_relocation_time(origin, destination)[source]

Get the travel time between two stations (useful for relocations).

Parameters:destination (origin,) – The names of the stations.
Returns:time – The travel time betweent the two stations in seconds.
Return type:float
move_station(station_name, new_location, new_name)[source]

Move the location of a single station.

Parameters:
  • station_name (str) – The name of the station to move.
  • new_location (str or tuple(float, float)) – The new location of the station. Either a string matching the ID of a demand location or a tuple of decimal longitude latitude.
  • new_name (str) – The new name of the station. To keep the old name, simply set this parameter equal to station_name.
reset_stations()[source]

Reset station locations and names to the original stations from the data.

set_custom_stations(station_locations, station_names)[source]

Set custom station locations.

The function recreates the time_matrix_stations, but leaves the original time_matrix intact. The new time_matrix_stations has len(station_locations) rows and the same columns as time_matrix (fictive column names are still ‘matrix_names’).

Parameters:
  • station_locations (array-like of strings) – The demand locations that should get a fire station.
  • station_names (array-like of strings) – The names of the custom stations.