Skip to content

Commit

Permalink
bridge scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedor Baart committed Mar 9, 2022
1 parent 06fc5e8 commit 2dd4318
Show file tree
Hide file tree
Showing 4 changed files with 1,211 additions and 5,455 deletions.
32 changes: 29 additions & 3 deletions dtv_backend/dtv_backend/fis.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

logger = logging.getLogger(__name__)

package_path = pathlib.Path(__file__).parent.parent

# define the coorinate system
geod = pyproj.Geod(ellps="WGS84")

Expand Down Expand Up @@ -157,10 +159,11 @@ def determine_max_draught_on_path(graph, origin, destination, lobith_discharge,
compute
"""
#TODO: the file "depth.csv" is missing... this should be loaded as discharge_df
if cache.get((origin.geometry, destination.geometry, lobith_discharge)):
return cache.get((origin.geometry, destination.geometry, lobith_discharge))

depth_path = pathlib.Path('~/data/vaarwegen/discharge/depth.csv')
# if cache.get((origin.geometry, destination.geometry, lobith_discharge)):
# return cache.get((origin.geometry, destination.geometry, lobith_discharge))

depth_path = package_path / 'data' / 'depth.csv'
discharge_df = pd.read_csv(depth_path)

# also return distance
Expand Down Expand Up @@ -215,6 +218,29 @@ def determine_max_draught_on_path(graph, origin, destination, lobith_discharge,
return max_draught


def determine_max_height_on_path(graph, origin, destination, lobith_discharge):

return 6

def determine_max_layers(height):
"""determine max number of container layers as a function of available height on the route"""

container_height = 2.591

max_layers = 0
if height <= 5.8:
max_layers = 2
elif height <= 8.5:
max_layers = 2
elif height <= 11.05:
max_layers = 3
else:
max_layers = 4

return max_layers




def shorted_path_by_dimensions(graph, source, destination, width, height, depth, length):
"""create a new constrained graph, based on dimensions, of the same type as graph and find the shortest path"""
Expand Down
55 changes: 47 additions & 8 deletions dtv_backend/dtv_backend/simple.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uuid
import datetime
import itertools
import logging

import numpy as np
import simpy
Expand Down Expand Up @@ -121,14 +122,16 @@ def load(self, source, destination, max_load=None):
# tonne / (tonne / hour) -> s
load_time = cargo_to_move * ureg.metric_ton / (self.loading_rate * (ureg.metric_ton / ureg.hour))
load_time = load_time.to(ureg.second).magnitude


# log cargo levels before/after
with self.log(
message="Load",
description=f"Loading ({source.name}) -> ({destination.name})",
destination=destination.cargo,
source=source.cargo,
geometry=self.geometry,
value=source.cargo
value=cargo_to_move
):
source.cargo.get(cargo_to_move)
# move it to the destination
Expand All @@ -155,6 +158,8 @@ def max_load(self):
# independent of trip
return self.cargo.capacity - self.cargo.level



def get_max_cargo_for_trip(self, origin, destination, lobith_discharge):
"""determin max cargo to take on a trip, given the discharge at lobith"""
# TODO: move this out of here?
Expand All @@ -167,13 +172,44 @@ def get_max_cargo_for_trip(self, origin, destination, lobith_discharge):
)
draught_full = self.metadata["Draught loaded [m]"]
draught_empty = self.metadata["Draught empty [m]"]
if max_draught > draught_full:
return self.cargo.capacity
if max_draught < draught_empty:
return 0
try:
if max_draught > draught_full:
return self.cargo.capacity
if max_draught < draught_empty:
return 0
except:
logging.exception("TODO Fix this")
pass


max_height = dtv_backend.fis.determine_max_height_on_path(
self.env.FG,
origin,
destination,
lobith_discharge
)
max_layers = dtv_backend.fis.determine_max_layers(max_height)

# TODO: separate function for container vs bulk ship
capacity = self.cargo.capacity
containers_per_layer = self.metadata.get('containers_per_layer', 87)

# max cargo under height limitation
max_cargo_height = max_layers * containers_per_layer

if max_cargo_height > capacity:
max_cargo_height = capacity

load_frac_draught = (max_draught - draught_empty) / (draught_full - draught_empty)

load_frac = (max_draught - draught_empty) / (draught_full - draught_empty)
max_cargo = self.cargo.capacity * load_frac
max_cargo_draught = self.cargo.capacity * load_frac_draught

try:
max_cargo = min(max_cargo_height, max_cargo_draught)
except:
logging.exception("TODO: fix this")
print(max_cargo_height)
max_cargo = max_cargo_height
return max_cargo

@property
Expand Down Expand Up @@ -249,8 +285,10 @@ def move_to(self, destination, limited=False):
)
total_distance = 0
for edge in zip(path[:-1], path[1:]):
distance = graph.edges[edge]['length']
distance = graph.edges[edge]['length_m']
total_distance += distance


if path:
# move to destination
end_node = graph.nodes[path[-1]]
Expand Down Expand Up @@ -305,6 +343,7 @@ def load_move_unload(self, source, destination, max_load=None):
#
max_cargo_for_trip = max_load
yield from self.load_at(source, max_cargo_for_trip)

# Don't sail empty
if self.cargo.level > 0:
yield from self.move_to(destination)
Expand Down
Loading

0 comments on commit 2dd4318

Please sign in to comment.