mable.extensions package

Submodules

mable.extensions.cargo_distributions module

Extension to generate and transport cargoes based on cargo frequency and amount distributions and associated changes to shipping.

class mable.extensions.cargo_distributions.DistributionClassFactory

Bases: LatLongFactory

Class factory to change the generation of classes to use the cargo distribution classes.

static generate_event_arrival(*args, **kwargs)

Generates an arrival event. Default: py:class:maritime_simulator.event_management.ArrivalEvent.

Parameters:
  • args – Positional args.

  • kwargs – Keyword args.

Returns:

The event.

static generate_shipping(*args, **kwargs)

Generates a shipping (cargo generation) unit. Default: py:class:maritime_simulator.shipping_market.StaticShipping. :param _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionClassFactory.generate_shipping.args:

Positional args.

Parameters:

kwargs – Keyword args.

Returns:

The shipping.

static generate_trade(*args, **kwargs)

Generates a trade (cargo). Default: py:class:maritime_simulator.shipping_market.Trade. :param _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionClassFactory.generate_trade.args:

Positional args.

Parameters:

kwargs – Keyword args.

Returns:

The trade.

class mable.extensions.cargo_distributions.DistributionShipping(*args, **kwargs)

Bases: Shipping

Generate cargoes based on cargo distributions.

__init__(*args, **kwargs)

Constructor. Calls initialise_trades() with all args and kwargs. :param _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionShipping.args:

Positional args.

Parameters:

kwargs – Keyword args.

static filter_out_outliers(df, stds_around_mean=5)
initialise_trades(*args, **kwargs)

Generate all trades that occur over the run of the simulation. :param _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionShipping.initialise_trades.args:

Ignored.

Parameters:

kwargs

The paths to the cargo generation distributions.

The paths to the csv files for the cargo generation as specified in load_distributions():
  • port_transition_duration_distributions_path

  • port_cargo_weight_distribution_path

  • port_trade_frequency_distribution_path

load_distributions(port_transition_duration_distributions_path, port_cargo_weight_distribution_path, port_trade_frequency_distribution_path)

Load the distributions for the cargo generation.

Parameters:
  • port_transition_duration_distributions_path – The path to the csv with information on the transit durations.

  • port_cargo_weight_distribution_path – The path to the csv with information on the average weight of cargo at the ports.

  • port_trade_frequency_distribution_path – The path to the csv with information on the average visit frequency at the ports.

static sample_cargo_weight(world, cargo_weight_dict, cargo_weight_distribution, mean_cargo_weight_std, port, supply_demand)

Samples a cargo weight based on normal port distributions

Parameters

world:

TODO

cargo_weight_dict: dict

Stores cargo weight distributions that have already been searched for

cargo_weight_distributionpandas.DataFrame

Distributions of the cargo weight picked up/delivered at individual ports Columns:

Port: str

The name of the port

SupplyDemand: str (“Supply” or “Demand”, TODO: can be converted to binary)

Specifies if each row represents a supply or demand distribution

Mean: float

The mean of the cargo weight normal distribution at the given port (picked up or delivered)

Std. Dev: float or “inf”, TODO: currently when only one data point, “inf” is passed by Lewis,

TODO may be more appropriate to be empty

The standard deviation of the cargo weight normal distribution at the given port (picked up or delivered)

mean_cargo_weight_std: float

The average standard deviation across all records in the cargo_weight_distribution. Used when std is missing.

port: str

The name of the port to sample at

supply_demand: str

String indicating if we look for ‘Supply’ or ‘Demand’ distribution

return:

quantityfloat

The cargo quantity sampled (in MT)

sample_cargoes_from_port_distributions(world, class_factory, number_of_cargoes, cargo_weight_distribution, frequency_distribution, time_transit_distribution, pickup_period, time, regional_changes=None, precomputed_routes=None)

Samples a given number of trades based on distributions.

Parameters

number_of_cargoesint

The number of trades to be sampled

cargo_weight_distributionpandas.DataFrame

Distributions of the cargo weight picked up/delivered at individual ports Columns:

Port: str

The name of the port

SupplyDemand: str (“Supply” or “Demand”, TODO: can be converted to binary)

Specifies if each row represents a supply or demand distribution

Mean: float

The mean of the cargo weight normal distribution at the given port (picked up or delivered)

Std. Dev: float or “inf”, TODO: currently when only one data point, “inf” is passed by Lewis,

TODO may be more appropriate to be empty

The standard deviation of the cargo weight normal distribution at the given port (picked up or delivered)

frequency_distributionpandas.DataFrame

Distributions of the number of trades with cargo picked up/delivered at individual ports Columns:

Name: str

The name of the port

SupplyDemand: str (“Supply” or “Demand”, TODO: can be converted to binary)

Specifies if each row represents a supply or demand distribution

Num Samples: int

The number of trades at the given port (picked up or delivered as specified in the SupplyDemand column)

time_transit_distributionpandas.DataFrame

Distributions of the sailing time between ports Columns:

From: str

The name of start port

To: str

The name of end port

Mean: float

The mean of the normal distribution of the sailing time (in minutes) between the start and end port

Std. Dev: float or “inf”, TODO: currently when only one data point, “inf” is passed by Lewis,

TODO may be more appropriate to be empty

The standard deviation of the normal distribution of the sailing time between the start and end port

pickup_period(start_T, end_T) tuple

The timestep interval in which trades needs to be picked up

regional_changesdict, optional

TODO: implement regional changes A dictionary encoding the regional changes as passed from the web app (default is None)

return:

list List of Cargo objects of length specified

static sample_time_windows(world, time_transition_dict, time_transit_distribution, mean_transition_std, start_port, end_port, cargo_weight, pickup_period, time_windows_allowance=5)

Sample time interval based on normal time transition distributions between start and end ports

Parameters

param _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionShipping.sample_time_windows.world:

TODO

param _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionShipping.sample_time_windows.time_transition_dict:

Dictionary which stores the time transition times between port pairs

type _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionShipping.sample_time_windows.time_transition_dict:

dict

:param _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionShipping.sample_time_windows.time_transit_distribution :

Distributions of the sailing time between ports Columns:

From: str

The name of start port

To: str

The name of end port

Mean: float

The mean of the normal distribution of the sailing time (in minutes) between the start and end port

Std. Dev: float or “inf”, TODO: currently when only one data point, “inf” is passed by Lewis,

TODO may be more appropriate to be empty

The standard deviation of the normal distribution of the sailing time between the start and end port

type _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionShipping.sample_time_windows.time_transit_distribution:

pd.DataFrame

param _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionShipping.sample_time_windows.mean_transition_std:

float The average standard deviation across all records in the time_transit_distribution. Used when std is missing.

:param _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionShipping.sample_time_windows.start_portstr

The name of the start port

:param _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionShipping.sample_time_windows.end_portstr

The name of the end port

:param _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionShipping.sample_time_windows.cargo_weightfloat

The cargo weight to be transported. It is used to calculate loading and unloading times

:param _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionShipping.sample_time_windows.pickup_period :

The timestep interval in which trades needs to be picked up in days.

type _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionShipping.sample_time_windows.pickup_period:

Tuple[float, float]

:param _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionShipping.sample_time_windows.time_windows_allowance :

The number of days (per directions) to extend each time window (default is 5)

type _sphinx_paramlinks_mable.extensions.cargo_distributions.DistributionShipping.sample_time_windows.time_windows_allowance:

int

return:

pickup_time_windowtuple

Pickup time window consisting representing the time interval the pickup should be started and finished

delivery_time_windowtuple

Pickup time window consisting representing the time interval the delivery should be started and finished

property trade_occurrence_frequency
class mable.extensions.cargo_distributions.DistributionSimulationBuilder(class_factory, specifications)

Bases: SimulationBuilder

Adjustments to simulation generation.

generate_shipping(*args, **kwargs)

Keyword based generation. Otherwise, see py:func:maritime_simulator.instructions.SimulationBuilder.generate_shipping.

class mable.extensions.cargo_distributions.TimeWindowArrivalEvent(time, vessel, trade, is_pickup)

Bases: ArrivalEvent

An event where a vessel arrives for loading or unloading.

mable.extensions.fuel_emissions module

Add fuel and emission capabilities.

class mable.extensions.fuel_emissions.ConsumptionRate(*, base: float, speed_power: float, factor: float)

Bases: JsonAble

A polynomial consumption rate.

The consumption for a specific speed over a specified time is: base * pow(speed, speed_power) * factor * time.

class Data(current_class: Type[DataProtocol], base: float, speed_power: float, factor: float)

Bases: DataClass

class Schema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)

Bases: DataSchema

opts: SchemaOpts = <marshmallow.schema.SchemaOpts object>
__init__(current_class: Type[DataProtocol], base: float, speed_power: float, factor: float) None

Method generated by attrs for class ConsumptionRate.Data.

base: float
factor: float
speed_power: float
__init__(*, base: float, speed_power: float, factor: float) None

Method generated by attrs for class ConsumptionRate.

base: float
factor: float
speed_power: float
to_json()
Returns:

Any A json encodable object.

class mable.extensions.fuel_emissions.Fuel(*, name: str, price: float, energy_coefficient: float, co2_coefficient: float)

Bases: JsonAble

A fuel with name, price per tonne, energy coefficient and co_2 coefficient.

Parameters:
  • name (str) – The name

  • price – float Price in $ per tonne

  • energy_coefficient

  • co2_coefficient – float Coefficient of produced CO_2 per amount of fuel

__init__(*, name: str, price: float, energy_coefficient: float, co2_coefficient: float) None

Method generated by attrs for class Fuel.

co2_coefficient: float
energy_coefficient: float
get_co2_emissions(amount)
get_cost(amount)
Parameters:

amount – float Amount of fuel in tonnes

Returns:

float The cost of the amount of fuel.

name: str
price: float
to_json()
Returns:

Any A json encodable object.

class mable.extensions.fuel_emissions.FuelClassFactory

Bases: DistributionClassFactory

Extends the class factory for the generation of vessels with engines that use different fuels.

static generate_consumption_rate(*args, **kwargs)
static generate_fuel(*args, **kwargs)
static generate_vessel(*args, **kwargs)

Generates a vessel. Default: py:class:maritime_simulator.transport_operation.SimpleVessel. :param _sphinx_paramlinks_mable.extensions.fuel_emissions.FuelClassFactory.generate_vessel.args:

Positional args.

Parameters:

kwargs – Keyword args.

Returns:

The vessel.

static generate_vessel_engine(*args, **kwargs)
class mable.extensions.fuel_emissions.FuelSimulationFactory(class_factory, specifications)

Bases: DistributionSimulationBuilder

Extends the Simulation builder such that vessels have engines that use fuel for transportation.

__init__(class_factory, specifications)

Constructor. :param _sphinx_paramlinks_mable.extensions.fuel_emissions.FuelSimulationFactory.class_factory: ClassFactory

The class factory.

Parameters:

specifications – Specifications for a simulation.

generate_consumption_rate(*args, **kwargs)
generate_engine(*args, **kwargs)

Generates an engine from the specifications by generating all units in turn. Order: random, network, world, shipping_companies, shipping(cargo generation), market (shipping allocation). :return:

The simulation engine.

generate_fuels(*args, **kwargs)
generate_vessel(*args, **kwargs)

Generates one vessel using based on class factory’s ClassFactory.generate_vessel(). :param _sphinx_paramlinks_mable.extensions.fuel_emissions.FuelSimulationFactory.generate_vessel.args:

Positional args.

Parameters:

kwargs – Keyword args. Should include ‘location’ and ‘capacities_and_loading_rates’.

Returns:

A vessel.

generate_vessel_engine(*args, **kwargs)
class mable.extensions.fuel_emissions.FuelSpecsBuilder

Bases: Builder

Extends the specification builder to encode fuels.

add_fuel(*args, **kwargs)
class mable.extensions.fuel_emissions.GlobalSetup

Bases: object

classmethod get_item(key)
classmethod get_keys()
classmethod set_item(key, value)
class mable.extensions.fuel_emissions.VesselEngine(fuel, idle_consumption, laden_consumption_rate, ballast_consumption_rate, loading_consumption, unloading_consumption)

Bases: object

An engine for a vessel that consumes fuel.

class Data(current_class: Type[DataProtocol], fuel: str, idle_consumption: float, laden_consumption_rate: Data, ballast_consumption_rate: Data, loading_consumption: float, unloading_consumption: float)

Bases: DataClass

class Schema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)

Bases: DataSchema

opts: SchemaOpts = <marshmallow.schema.SchemaOpts object>
__init__(current_class: Type[DataProtocol], fuel: str, idle_consumption: float, laden_consumption_rate: Data, ballast_consumption_rate: Data, loading_consumption: float, unloading_consumption: float) None

Method generated by attrs for class VesselEngine.Data.

ballast_consumption_rate: Data
fuel: str
idle_consumption: float
laden_consumption_rate: Data
loading_consumption: float
unloading_consumption: float
__init__(fuel, idle_consumption, laden_consumption_rate, ballast_consumption_rate, loading_consumption, unloading_consumption)
Parameters:
  • fuel (Fuel) – The fuel the engine uses.

  • idle_consumption (float) – The consumption of fuel while the vessel is idling. This should be a flat per time value.

  • laden_consumption_rate (ConsumptionRate) – The consumption of fuel while the vessel is moving while laden. This is a speed dependent consumption curve.

  • ballast_consumption_rate (ConsumptionRate) – The consumption of fuel while the vessel is moving while under ballast (unladen). This is a speed dependent consumption curve.

  • loading_consumption (float) – The consumption of fuel while the vessel is loading. This should be a flat per time value.

  • unloading_consumption (float) – The consumption of fuel while the vessel is unloading. This should be a flat per time value.

property fuel
get_ballast_consumption(time, speed)
get_idle_consumption(time)
get_laden_consumption(time, speed)
get_loading_consumption(time)
get_unloading_consumption(time)
to_json()
class mable.extensions.fuel_emissions.VesselWithEngine(capacities_and_loading_rates, location, speed, propelling_engine, keep_journey_log=True, name=None, company=None)

Bases: WorldVessel

A vessel with a fuel consuming engine.

class Data(current_class: Type[DataProtocol], capacities_and_loading_rates: List[Data], location: str | None, keep_journey_log: bool, name: str, speed: float, propelling_engine: Data)

Bases: Data

class Schema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)

Bases: Schema

opts: SchemaOpts = <marshmallow.schema.SchemaOpts object>
__init__(current_class: Type[DataProtocol], capacities_and_loading_rates: List[Data], location: str | None, keep_journey_log: bool, name: str, speed: float, propelling_engine: Data) None

Method generated by attrs for class VesselWithEngine.Data.

propelling_engine: Data
__init__(capacities_and_loading_rates, location, speed, propelling_engine, keep_journey_log=True, name=None, company=None)
Parameters:
  • capacities_and_loading_rates (List[CargoCapacity]) – A list of the types, capacities and loading rates of the cargo containers.

  • location – The location of the vessel at creation.

  • speed (float) – The vessels speed in knots (kn), i.e. nautical miles per hour (nmi/h).

  • propelling_engine (VesselEngine) – The propelling engine.

  • keep_journey_log (bool) – If true the vessel keeps a log of event occurrences that affected the vessel.

  • name (str) – The name of the vessel.

  • company (ShippingCompany[V]) – The company that owns the vessel.

get_ballast_consumption(time, speed)

The amount of consumed fuel over a specified time in which the vessel is moving at speed while under ballast (unladen).

Parameters:
  • time (float) – The time.

  • speed (float) – The speed of the vessel.

Returns:

The amount of fuel consumed.

Return type:

float

get_co2_emissions(amount)

The amount of emitted co_2 for an amount of consumed fuel.

Parameters:

amount (float) – The amount of consumed fuel.

Returns:

The amount of co_2.

Return type:

float

get_cost(amount)

The cost of burning the specified amount of fuel.

Parameters:

amount (float) – The amount of consumed fuel.

Returns:

The cost of the amount of fuel.

Return type:

float

get_idle_consumption(time)

The amount of consumed fuel over a specified time idling.

Parameters:

time (float) – The time.

Returns:

The amount of fuel consumed.

Return type:

float

get_laden_consumption(time, speed)

The amount of consumed fuel over a specified time in which the vessel is moving at speed while laden.

Parameters:
  • time (float) – The time.

  • speed (float) – The speed of the vessel.

Returns:

The amount of fuel consumed.

Return type:

float

get_loading_consumption(time)

The amount of consumed fuel over a specified time loading.

Parameters:

time (float) – The time.

Returns:

The amount of fuel consumed.

Return type:

float

get_unloading_consumption(time)

The amount of consumed fuel over a specified time unloading.

Parameters:

time (float) – The time.

Returns:

The amount of fuel consumed.

Return type:

float

property propelling_engine
to_json()

mable.extensions.world_ports module

Ports and routing based on a world graph and real world port location.

class mable.extensions.world_ports.LatLongFactory

Bases: ClassFactory

Factory to generate the network, ports and vessels in a real-world graph.

static generate_location(*args, **kwargs)

Generates a location. Default: py:class:mable.simulation_space.universe.Location. :param _sphinx_paramlinks_mable.extensions.world_ports.LatLongFactory.generate_location.args:

Positional args.

Parameters:

kwargs – Keyword args.

Returns:

The network.

static generate_network(*args, **kwargs)

Generates a network (space). Default: py:class:mable.simulation_space.structure.UnitShippingNetwork.

Parameters:
  • args – Positional args.

  • kwargs – Keyword args.

Returns:

The network.

static generate_port(*args, **kwargs)

Generates a port. Default: py:class:mable.simulation_space.universe.Port. :param _sphinx_paramlinks_mable.extensions.world_ports.LatLongFactory.generate_port.args:

Positional args.

Parameters:

kwargs – Keyword args.

Returns:

The port.

static generate_vessel(*args, **kwargs)

Generates a vessel. Default: py:class:maritime_simulator.transport_operation.SimpleVessel. :param _sphinx_paramlinks_mable.extensions.world_ports.LatLongFactory.generate_vessel.args:

Positional args.

Parameters:

kwargs – Keyword args.

Returns:

The vessel.

class mable.extensions.world_ports.LatLongLocation(latitude, longitude, name)

Bases: Location

A location with latitude and longitude.

__init__(latitude, longitude, name)
Parameters:
  • x (float) – The x coordinate of the location.

  • y (float) – The y coordinate of the location.

  • name (str) – An optional name of the location.

property latitude
property longitude
class mable.extensions.world_ports.LatLongPort(name, latitude, longitude)

Bases: Port, JsonAble

A port with latitude and longitude.

__init__(name, latitude, longitude)
Parameters:
  • name (str) – The name of the port.

  • latitude (float) – The latitude of the port in decimal degrees.

  • longitude (float) – The longitude of the port in decimal degrees.

property latitude
Returns:

The latitude of the port in decimal degrees.

Return type:

float

property longitude
Returns:

The longitude of the port in decimal degrees.

Return type:

float

to_json()
Returns:

The port information as dictionary with keys ‘name’, ‘latitude’ and ‘longitude’.

Return type:

dict

class mable.extensions.world_ports.LatLongShippingNetwork(ports=None, precomputed_routes_file=None, graph_file=None)

Bases: NetworkWithPortDict

A shipping network with latitude on longitude locations.

__init__(ports=None, precomputed_routes_file=None, graph_file=None)
add_canal_to_graph(canal_name)

Adds a shipping canal to the world graph.

Parameters

param _sphinx_paramlinks_mable.extensions.world_ports.LatLongShippingNetwork.add_canal_to_graph.canal_name:

string Name of the canal, also serves as key

property canals_nodes

Return locations which are canals :return:

The canals.

compute_all_routes_between_points(start_location, end_location, vessel_type=None)

Computes a list of all routes between the locations.

For the given start location and end location the direct route as well as the routes pass specified passage points (Suez (canal), Panama (canal)) are considered.

Parameters

start_location: object (provides instance variables: longitude, latitude and name)

The start location of the routes.

end_locationobject (provides instance variables: longitude, latitude and name)

The end location of the routes.

vessel_type: TODO

TODO

Returns

[Route]

List of all found routes.

static compute_route_length(route)

Compute the length of a route by summing the distances between all of it’s points.

Parameters

route: [Tuple]

List of (longitude, latitude) tuples that store the shortest route

Returns

float

The length of the route in nautical miles

create_canal_nodes()

Creates the canal nodes on the graph

Returns

nodes: {canal_name: (start_node, end_node)}

dictionary containing the canal nodes

create_world_canal_scenarios()

Creates a number of scenarios assuming different navigation canals are opened.

Each scenario is a tuple containing an array of strings, each representing the name of a canal being considered.

Returns:

List of canal names determining which canals are considered

Return type:

List[Tuple[String]]

find_closest_node(long_, lat_)

Finds the closest node in the world graph to a point of interest.

Parameters

long_: float

longitude of the point of interest

lat_: float

latitude of the point of interest

Returns

min_node: GraphX Node

the node closest to those coordinates in the router’s world_graph

generate_route_graph_from_file()

Generates the router graph file depending on the type of file the router has been initialised with Returns ——-

graph: networkx graph

the graph generated from the file

get_all_routes_between_points(start_location, end_location, vessel_type=None)

Returns a list of all routes between the locations.

For the given start location and end location the direct route as well as the routes pass specified passage points (Suez (canal), South Africa (Cape of Good Hope, Cape Agulhas), Panama (canal), Cape (North of Cape Horn), Singapore (Riau Islands south of Singapore Strait)) are considered.

Parameters

start_location: object (provides instance variables: longitude, latitude and name)

The start location of the routes.

end_locationobject (provides instance variables: longitude, latitude and name)

The end location of the routes.

vessel_type: TODO

TODO

Returns

[Route]

List of all found routes.

get_all_stored_routes_between_points(start_location, end_location)

Returns the shortest routes stored.

Parameters

start_location: object (provides instance variables: longitude, latitude and name)

The start location of the routes.

end_locationobject (provides instance variables: longitude, latitude and name)

The end location of the routes.

Returns

[Route] or None

List of all found routes or None if no routes between locations has been stored before.

get_distance(location_one, location_two)

Get the distance between two locations.

If there is no route between the two locations infinity (math.inf) if returned.

Parameters:
  • location_one (Port | str) – The first location.

  • location_two – The second location.

Returns:

The distance or math.inf if no route between the two locations exists.

Return type:

float

get_journey_location(journey, vessel, current_time)

Returns the current position of the vessel based on the journey information and the current time.

Parameters:
  • journey (OnJourney) – The journey object.

  • vessel (Vessel) – The vessel that is performing the journey.

  • current_time (float) – The current time.

Returns:

The current location the vessel is in.

Return type:

Location

static get_long_lat_dist(lat_a, lng_a, lat_b, lng_b)

Calculate the distance between points on earth using the haversine distance, assuming the earth is a perfect sphere.

get_shortest_grid_route_between_points(start_long, start_lat, end_long, end_lat)

Calculates the shortest route between start longitude/latitude and end longitude/latitude using the grid graph

Parameters

start_long: float

The longitude of the start location.

start_lat: float

The latitude of the start location.

end_longfloat

The longitude of the end location.

end_latfloat

The latitude of the end location.

Returns

[Tuple]

List of (longitude, latitude) tuples that store the shortest route

get_shortest_path_between_points(start_location, end_location, vessel_type=None)

Returns the shortest route between the locations.

Parameters

start_location: object (provides instance variables: longitude, latitude and name)

The start location of the route.

end_locationobject (provides instance variables: longitude, latitude and name)

The end location of the route.

vessel_type: TODO

TODO

Returns

Route

The shortest route found.

get_shortest_route_between_points(start_long, start_lat, end_long, end_lat, smooth_path=True)

Calculates the shortest route between start longitude/latitude and end longitude/latitude.

Parameters

start_long: float

The longitude of the start location.

start_lat: float

The latitude of the start location.

end_longfloat

The longitude of the end location.

end_latfloat

The latitude of the end location.

smooth_path: boolean

Flag to indicate whether or not to use smoothing algorithm on the path

Returns

[Tuple]

List of (longitude, latitude) tuples that store the shortest route

float

The length of the route in nautical miles

remove_canals_from_graph()

Removes all canal edges from the world graph.

property scenarios

Return canal scenarios. See LatLongShippingNetwork.create_world_canal_scenarios()

Returns:

The scenarios.

smooth_route(route, epsilon=1)

Smooths routes. If suez or panama entrances are found, simplify until them and from them.

Parameters

route: [Tuple]

List of (longitude, latitude) tuples that store the shortest route

epsilon: float

the epsilon value for the Ramer–Douglas–Peucker smoothing algorithm

Returns

[Tuple]

Compressed list of (longitude, latitude) tuples that store the shortest route removing unnecessary points

property world_graph
exception mable.extensions.world_ports.NoPathsException

Bases: Exception

class mable.extensions.world_ports.Route(name, route, length, canal_nodes=None)

Bases: object

Vessel route class.

__init__(name, route, length, canal_nodes=None)

Constructor.

Parameters

namestr

Name of the route.

route[[float, float]]

List of points of format [longitude, latitude].

lengthfloat

The length of the route.

canal_nodes: {canal_name: (start_node, end_node)}

Stores all canals in the world with their start and end nodes in the graph

as_tuple()
class mable.extensions.world_ports.WorldVessel(capacities_and_loading_rates, location, speed, keep_journey_log=True, name=None, company=None)

Bases: SimpleVessel

__init__(capacities_and_loading_rates, location, speed, keep_journey_log=True, name=None, company=None)
Parameters:
  • capacities_and_loading_rates (List[CargoCapacity]) – A list of the types, capacities and loading rates of the cargo containers.

  • location – The location of the vessel at creation.

  • speed (float) – The vessels speed in knots (kn), i.e. nautical miles per hour (nmi/h).

  • keep_journey_log (bool) – If true the vessel keeps a log of event occurrences that affected the vessel.

  • name (str) – The name of the vessel.

  • company (ShippingCompany[V]) – The company that owns the vessel.

get_travel_time(distance, *args, **kwargs)

The time it takes to travel the specified distance.

Parameters:

distance (float) – Distance in nautical miles (nmi).

Returns:

The travel time in hours (h).

Return type:

float

mable.extensions.world_ports.get_index_or_default(search_list, search_term, default=0)

Returns the first index of the elements who contain the search term or the default if no element matches. :param _sphinx_paramlinks_mable.extensions.world_ports.get_index_or_default.search_list:

The list to search in.

Parameters:
  • search_term – The search term.

  • default – The default to return if no element matches. Default value is 0.

Returns:

The index of the first match or the default.

mable.extensions.world_ports.get_ports(path)

Retrieve the ports from a csv file. :param _sphinx_paramlinks_mable.extensions.world_ports.get_ports.path:

The path of the port file.

Returns:

list A list of the ports

Module contents