Defining a basic vessel#
In this notebook, we show how to setup a simple transport network.
We take the following steps:
1. Imports#
We start with importing required libraries
# package(s) used for geo-spatial operations
import pyproj
import shapely.geometry
# package(s) related to the simulation (creating the vessel, running the simulation)
import opentnsim
print('This notebook is executed with OpenTNSim version {}'.format(opentnsim.__version__))
This notebook is executed with OpenTNSim version 1.3.7
2. Create vessel#
We start with creating a vessel class. We call this class a Vessel, and add a number of OpenTNSim mix-ins to this class. Each mix-in requires certain input parameters.
The following mix-ins are sufficient to create a vessel for our problem:
Identifiable - allows to give the vessel a name and a random ID,
Movable - allows the vessel to move, with a fixed speed, while logging this activity,
Movable in turn relies on the mix-ins: Locatable, Routeable, and Log
# make your preferred Vessel class out of available mix-ins.
Vessel = type('Vessel',
(opentnsim.core.Identifiable,
opentnsim.core.Movable), {})
# create a dict with all important settings
data_vessel = {"env": None,
"name": "Vessel 1",
"geometry": shapely.geometry.Point(0, 0), # lon, lat
"route": None,
"v": None}
# create the TransportResource using the dict as keyword value pairs
vessel = Vessel(**data_vessel)
3. Inspect results#
We can now show that a vessel object is created with all indicated properties
vessel.__dict__
{'v': None,
'env': None,
'logbook': [],
'route': None,
'position_on_route': 0,
'complete_path': None,
'geometry': <POINT (0 0)>,
'node': None,
'wgs84': Geod(ellps='WGS84'),
'on_pass_edge_functions': [],
'on_pass_node_functions': [],
'name': 'Vessel 1',
'id': 'b2b39d30-d205-4901-9079-c7d6667b98e1'}
type(vessel.__dict__["id"])
str
type(vessel.__dict__["geometry"])
shapely.geometry.point.Point
More complex behaviours can be simulated by including more mix-ins.