Previews

Previews are typically invoked before running the often time-consuming generation process triggered by ContainerFlowGenerationManager.generate(). A preview provides a first impression on what kind of data will be generated based on the input distributions and schedules. At this stage, some simplifications are made to actually save some time. Among others, no container instances are generated and operational constraints are neglected. The steps are explained according to the database created by the demo script for CTA , but you can still use any other ConFlowGen database.

[1]:
import datetime

import matplotlib
import matplotlib.pyplot as plt
from IPython.display import Markdown

import conflowgen

database_chooser = conflowgen.DatabaseChooser(
    sqlite_databases_directory="./data/prepared_dbs"  # subdirectory relative to Jupyter Notebook
)
database_chooser.load_existing_sqlite_database("demo_deham_cta.sqlite")

Instantiating a Preview

Each preview is a standardized approach of how the data existent in the database is digested. The resulting objects are part of the API but it requires some programming to further work with them.

[2]:
inbound_and_outbound_vehicle_capacity_preview = (
    conflowgen.InboundAndOutboundVehicleCapacityPreview(
        start_date=datetime.date(2021, 7, 1),
        end_date=datetime.date(2021, 7, 31),
        transportation_buffer=0.2,
    )
)
display(
    inbound_and_outbound_vehicle_capacity_preview.get_inbound_capacity_of_vehicles()
)
outbound_capacities = (
    inbound_and_outbound_vehicle_capacity_preview.get_outbound_capacity_of_vehicles()
)
display(outbound_capacities.used)
display(outbound_capacities.maximum)
ContainerVolumeByVehicleType(teu={<ModeOfTransport.truck: 'truck'>: 33234.91667936, <ModeOfTransport.train: 'train'>: 26784, <ModeOfTransport.feeder: 'feeder'>: 36459, <ModeOfTransport.deep_sea_vessel: 'deep_sea_vessel'>: 76777, <ModeOfTransport.barge: 'barge'>: 3712}, containers={<ModeOfTransport.truck: 'truck'>: 19901.147712191614, <ModeOfTransport.train: 'train'>: 16038.32335329341, <ModeOfTransport.feeder: 'feeder'>: 21831.736526946093, <ModeOfTransport.deep_sea_vessel: 'deep_sea_vessel'>: 45974.25149700598, <ModeOfTransport.barge: 'barge'>: 2222.754491017964})
ContainerVolumeByVehicleType(teu={<ModeOfTransport.truck: 'truck'>: 33234.91667936, <ModeOfTransport.train: 'train'>: 26784, <ModeOfTransport.feeder: 'feeder'>: 36459, <ModeOfTransport.deep_sea_vessel: 'deep_sea_vessel'>: 76777, <ModeOfTransport.barge: 'barge'>: 3712}, containers={<ModeOfTransport.truck: 'truck'>: 19901.147712191614, <ModeOfTransport.train: 'train'>: 16038.32335329341, <ModeOfTransport.feeder: 'feeder'>: 21831.736526946093, <ModeOfTransport.deep_sea_vessel: 'deep_sea_vessel'>: 45974.25149700598, <ModeOfTransport.barge: 'barge'>: 2222.754491017964})
ContainerVolumeByVehicleType(teu={<ModeOfTransport.truck: 'truck'>: nan, <ModeOfTransport.train: 'train'>: 26784, <ModeOfTransport.feeder: 'feeder'>: 43750.80000000001, <ModeOfTransport.deep_sea_vessel: 'deep_sea_vessel'>: 92132.4, <ModeOfTransport.barge: 'barge'>: 4454.400000000001}, containers={<ModeOfTransport.truck: 'truck'>: nan, <ModeOfTransport.train: 'train'>: 16038.32335329341, <ModeOfTransport.feeder: 'feeder'>: 26198.083832335327, <ModeOfTransport.deep_sea_vessel: 'deep_sea_vessel'>: 55169.10179640718, <ModeOfTransport.barge: 'barge'>: 2667.305389221557})

Instantiating a Preview Report

The data structures returned by a preview are further digestible by code. If you, however, prefer to have the data in a format better to read, you might rather look for the report. For every preview, a corresponding report exists. It auto-fills the parameters for the preview with the data already stored in the database. Thus, we do not need to provide a start_date, end_date, or a transportation_buffer.

[3]:
preview_report = conflowgen.InboundAndOutboundVehicleCapacityPreviewReport()
print(preview_report.get_report_as_text())

vehicle type      inbound volume (in TEU)   outbound avg volume (in TEU) outbound max capacity (in TEU)
deep sea vessel                   76777.0                        76777.0                        92132.4
feeder                            36459.0                        36459.0                        43750.8
barge                              3712.0                         3712.0                         4454.4
train                             26784.0                        26784.0                        26784.0
truck                             33234.9                        33234.9                           -1.0
(rounding errors might exist)

Instead of reading tables, one might prefer to see the data visualized. Occasionally, the visualization and text of some reports will be slightly different, but here they complement each other well.

[4]:
preview_report.show_report_as_graph()
../_images/notebooks_previews_7_0.svg

Furthermore, there is also the option to obtain the graph as an object without it being plotted. This allows you to further manipulate the visuals according to your needs. Each report might return a different kind of object, so please check the documentation of the respective report.

[5]:
plt_ax = preview_report.get_report_as_graph()

rectangles = list(
    filter(lambda x: isinstance(x, matplotlib.patches.Rectangle), plt_ax.get_children())
)

first_bar = rectangles[0]

first_bar.set_color("black")

plt.show()
../_images/notebooks_previews_9_0.svg

For more information on this preview report, please check InboundAndOutboundVehicleCapacityPreviewReport. A list of all previews including their corresponding reports shipped with ConFlowGen is available at Generating previews.

Showing all Previews as Text

Following the approach sketched out above, you could generate every preview report you are interested in. If you are interested in all of then, a convenience function exists. It can simply print all information to the standard output.

[6]:
conflowgen.run_all_previews(
    as_text=True,
    display_text_func=print,
)
Run all previews for the input distributions in combination with the schedules.

Inbound And Outbound Vehicle Capacity Preview Report

This report previews the container flow in terms of transshipment share and
modal split for the hinterland.

vehicle type      inbound volume (in TEU)   outbound avg volume (in TEU) outbound max capacity (in TEU)
deep sea vessel                   76777.0                        76777.0                        92132.4
feeder                            36459.0                        36459.0                        43750.8
barge                              3712.0                         3712.0                         4454.4
train                             26784.0                        26784.0                        26784.0
truck                             33234.9                        33234.9                           -1.0
(rounding errors might exist)


Vehicle Capacity Utilization On Outbound Journey Preview Report

This report previews the inbound and outbound traffic with a focus on up to
which extend the vehicle capacities will be exceeded. This is only an estimate,
additional restrictions (such as the dwell time restrictions) might further
reduce the number of containers one vehicle can in fact pick up for its outbound
journey.

vehicle type     maximum capacity (in TEU) required capacity (in TEU) exceeded difference (in TEU)
deep sea vessel                    92132.4                   71135.8        no                 0.0
feeder                             43750.8                   41294.5        no                 0.0
barge                               4454.4                     185.4        no                 0.0
train                              26784.0                   31116.4       yes              4332.4
truck                                 -1.0                   33234.9        no                 0.0
(rounding errors might exist)


Container Flow By Vehicle Type Preview Report

This report previews the container flow between vehicle types as defined by
schedules and input distributions.

vehicle type (from) vehicle type (to) required capacity (in TEU)
deep sea vessel     deep sea vessel                          0.0
deep sea vessel     feeder                               22850.0
deep sea vessel     barge                                  154.9
deep sea vessel     train                                26000.9
deep sea vessel     truck                                27771.2
feeder              deep sea vessel                      25849.3
feeder              feeder                                   0.0
feeder              barge                                   30.5
feeder              train                                 5115.4
feeder              truck                                 5463.7
barge               deep sea vessel                       3162.1
barge               feeder                                 549.9
barge               barge                                    0.0
barge               train                                    0.0
barge               truck                                    0.0
train               deep sea vessel                      18798.4
train               feeder                                7985.6
train               barge                                    0.0
train               train                                    0.0
train               truck                                    0.0
truck               deep sea vessel                      23326.0
truck               feeder                                9908.9
truck               barge                                    0.0
truck               train                                    0.0
truck               truck                                    0.0
(rounding errors might exist)


Modal Split Preview Report

This report previews the container flow in terms of transshipment share and
modal split for the hinterland. The reported statistics of the hinterland are
separated into three groups: The containers that have been delivered to the
container terminal on the inbound journey of a vehicle, the containers that have
been picked up from the container terminal on the outbound journey of a vehicle,
and the combination of both of them.

Role in network
transshipment traffic (in TEU):    48699.35 (27.52%)
inland gateway traffic (in TEU):  128267.56 (72.48%)

Modal split in hinterland traffic (only inbound traffic)
trucks (in TEU):    33234.9 (52.15%)
barges (in TEU):     3712.0 (5.82%)
trains (in TEU):    26784.0 (42.03%)

Modal split in hinterland traffic (only outbound traffic)
trucks (in TEU):    33234.9 (51.50%)
barges (in TEU):      185.4 (0.29%)
trains (in TEU):    31116.4 (48.22%)

Modal split in hinterland traffic (both inbound and outbound traffic)
trucks (in TEU):    66469.8 (51.82%)
barges (in TEU):     3897.4 (3.04%)
trains (in TEU):    57900.4 (45.14%)
(rounding errors might exist)


Quay Side Throughput Preview Report

This report previews the inbound and outbound traffic at the quay side. This is
only an estimate, additional restrictions (such as the dwell time restrictions)
might further reduce the number of containers one vehicle can in fact pick up
for its outbound journey.

discharged (in containers) loaded (in containers)
                     67806                  67323
(rounding errors might exist)


Truck Gate Throughput Preview Report

This report previews the average truck gate throughput throughout the week as
defined by     schedules and input distributions.
Hourly view:
                 Minimum (trucks/h)  Maximum (trucks/h)  Average (trucks/h)  Sum (trucks/24h)
Day of the week
Monday                            0                 146                  75              1794
Tuesday                          10                 146                  76              1828
Wednesday                        10                 146                  76              1828
Thursday                         10                 146                  76              1828
Friday                           10                 146                  76              1828
Saturday                          0                  14                   6               156
Sunday                            0                   0                   0                 0
Total                             0                 146                  55              9262
Fewest trucks in a day: 0 on Sunday
Most trucks in a day: 1828 on Tuesday
Average trucks per day: 1323
All previews have been presented.

Displaying Previews as Graphs

The same is possible for the graph reports. For emphasis, in the following the text version and graph version of the report are presented side-by-side. In addition, we also use the Markdown capabilities of the convenience function. This makes the presented previews blend into the remaining content.

[7]:
conflowgen.run_all_previews(
    as_text=True,
    as_graph=True,
    display_text_func=lambda text: display(Markdown(text)),
    display_in_markup_language="markdown",
    display_as_ipython_svg=True,
)

Run all previews for the input distributions in combination with the schedules.

Inbound And Outbound Vehicle Capacity Preview Report

This report previews the container flow in terms of transshipment share and modal split for the hinterland.

vehicle type      inbound volume (in TEU)   outbound avg volume (in TEU) outbound max capacity (in TEU)
deep sea vessel                   76777.0                        76777.0                        92132.4
feeder                            36459.0                        36459.0                        43750.8
barge                              3712.0                         3712.0                         4454.4
train                             26784.0                        26784.0                        26784.0
truck                             33234.9                        33234.9                           -1.0
(rounding errors might exist)
../_images/notebooks_previews_14_4.svg

Vehicle Capacity Utilization On Outbound Journey Preview Report

This report previews the inbound and outbound traffic with a focus on up to which extend the vehicle capacities will be exceeded. This is only an estimate, additional restrictions (such as the dwell time restrictions) might further reduce the number of containers one vehicle can in fact pick up for its outbound journey.

vehicle type     maximum capacity (in TEU) required capacity (in TEU) exceeded difference (in TEU)
deep sea vessel                    92132.4                   71135.8        no                 0.0
feeder                             43750.8                   41294.5        no                 0.0
barge                               4454.4                     185.4        no                 0.0
train                              26784.0                   31116.4       yes              4332.4
truck                                 -1.0                   33234.9        no                 0.0
(rounding errors might exist)
../_images/notebooks_previews_14_8.svg

Container Flow By Vehicle Type Preview Report

This report previews the container flow between vehicle types as defined by schedules and input distributions.

vehicle type (from) vehicle type (to) required capacity (in TEU)
deep sea vessel     deep sea vessel                          0.0
deep sea vessel     feeder                               22850.0
deep sea vessel     barge                                  154.9
deep sea vessel     train                                26000.9
deep sea vessel     truck                                27771.2
feeder              deep sea vessel                      25849.3
feeder              feeder                                   0.0
feeder              barge                                   30.5
feeder              train                                 5115.4
feeder              truck                                 5463.7
barge               deep sea vessel                       3162.1
barge               feeder                                 549.9
barge               barge                                    0.0
barge               train                                    0.0
barge               truck                                    0.0
train               deep sea vessel                      18798.4
train               feeder                                7985.6
train               barge                                    0.0
train               train                                    0.0
train               truck                                    0.0
truck               deep sea vessel                      23326.0
truck               feeder                                9908.9
truck               barge                                    0.0
truck               train                                    0.0
truck               truck                                    0.0
(rounding errors might exist)
../_images/notebooks_previews_14_12.svg

This report previews the container flow in terms of transshipment share and modal split for the hinterland. The reported statistics of the hinterland are separated into three groups: The containers that have been delivered to the container terminal on the inbound journey of a vehicle, the containers that have been picked up from the container terminal on the outbound journey of a vehicle, and the combination of both of them.

Role in network
transshipment traffic (in TEU):    48699.35 (27.52%)
inland gateway traffic (in TEU):  128267.56 (72.48%)

Modal split in hinterland traffic (only inbound traffic)
trucks (in TEU):    33234.9 (52.15%)
barges (in TEU):     3712.0 (5.82%)
trains (in TEU):    26784.0 (42.03%)

Modal split in hinterland traffic (only outbound traffic)
trucks (in TEU):    33234.9 (51.50%)
barges (in TEU):      185.4 (0.29%)
trains (in TEU):    31116.4 (48.22%)

Modal split in hinterland traffic (both inbound and outbound traffic)
trucks (in TEU):    66469.8 (51.82%)
barges (in TEU):     3897.4 (3.04%)
trains (in TEU):    57900.4 (45.14%)
(rounding errors might exist)
../_images/notebooks_previews_14_16.svg

Quay Side Throughput Preview Report

This report previews the inbound and outbound traffic at the quay side. This is only an estimate, additional restrictions (such as the dwell time restrictions) might further reduce the number of containers one vehicle can in fact pick up for its outbound journey.

discharged (in containers) loaded (in containers)
                     67806                  67323
(rounding errors might exist)
../_images/notebooks_previews_14_20.svg

Truck Gate Throughput Preview Report

This report previews the average truck gate throughput throughout the week as defined by schedules and input distributions.

Hourly view:
                 Minimum (trucks/h)  Maximum (trucks/h)  Average (trucks/h)  Sum (trucks/24h)
Day of the week
Monday                            0                 146                  75              1794
Tuesday                          10                 146                  76              1828
Wednesday                        10                 146                  76              1828
Thursday                         10                 146                  76              1828
Friday                           10                 146                  76              1828
Saturday                          0                  14                   6               156
Sunday                            0                   0                   0                 0
Total                             0                 146                  55              9262
Fewest trucks in a day: 0 on Sunday
Most trucks in a day: 1828 on Tuesday
Average trucks per day: 1323
../_images/notebooks_previews_14_24.svg

All previews have been presented.

Formulating Your Own Previews

A preview is a description of what the output is expected to look like before it is actually generated. Some previews are already shipped with ConFlowGen and more are planned in the future. If you have an idea for a preview that might be worth sharing, please have a look at Contributing. In addition, it is suggested to cross-check your expectations separately, e.g. by using spreadsheets or simple pen and paper.