Skip to content

Commit

Permalink
Adjust tests to new separation of tasks, avoid using "capacity" when …
Browse files Browse the repository at this point in the history
…actually referring to container volumes
  • Loading branch information
1kastner committed May 26, 2024
1 parent 5def1d3 commit cec7a5e
Show file tree
Hide file tree
Showing 64 changed files with 829 additions and 469 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get_outbound_container_volume_by_vehicle_type(
large_scheduled_vehicle: LargeScheduledVehicle
for large_scheduled_vehicle in LargeScheduledVehicle.select():
maximum_capacity_of_vehicle = min(
int(large_scheduled_vehicle.moved_capacity * (1 + self.transportation_buffer)),
int(large_scheduled_vehicle.inbound_container_volume * (1 + self.transportation_buffer)),
large_scheduled_vehicle.capacity_in_teu
)
vehicle_type: ModeOfTransport = large_scheduled_vehicle.schedule.vehicle_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_inbound_and_outbound_capacity_of_each_vehicle(
# vehicle properties
vehicle_name = vehicle.vehicle_name
vehicle_arrival_time = vehicle.get_arrival_time()
used_capacity_on_inbound_journey = vehicle.moved_capacity
used_capacity_on_inbound_journey = vehicle.inbound_container_volume

if start_date and vehicle_arrival_time < start_date:
continue
Expand Down
23 changes: 13 additions & 10 deletions conflowgen/domain_models/factories/container_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import typing
from typing import Dict, MutableSequence, Sequence, Type

from conflowgen.application.services.vehicle_capacity_manager import VehicleCapacityManager
from conflowgen.domain_models.container import Container
from conflowgen.domain_models.distribution_repositories.container_length_distribution_repository import \
ContainerLengthDistributionRepository
Expand All @@ -17,7 +18,6 @@
from conflowgen.domain_models.data_types.container_length import ContainerLength
from conflowgen.domain_models.data_types.mode_of_transport import ModeOfTransport
from conflowgen.domain_models.data_types.storage_requirement import StorageRequirement
from conflowgen.domain_models.repositories.large_scheduled_vehicle_repository import LargeScheduledVehicleRepository
from conflowgen.domain_models.vehicle import AbstractLargeScheduledVehicle, LargeScheduledVehicle
from conflowgen.tools.distribution_approximator import DistributionApproximator
from conflowgen.application.repositories.random_seed_store_repository import get_initialised_random_object
Expand All @@ -36,14 +36,14 @@ def __init__(self):
self.container_length_distribution: dict[ContainerLength, float] | None = None
self.container_weight_distribution: dict[ContainerLength, dict[int, float]] | None = None
self.storage_requirement_distribution: dict[ContainerLength, dict[StorageRequirement, float]] | None = None
self.large_scheduled_vehicle_repository = LargeScheduledVehicleRepository()
self.vehicle_capacity_manager = VehicleCapacityManager()

def set_ramp_up_and_down_times(
self,
ramp_up_period_end: typing.Optional[datetime.datetime],
ramp_down_period_start: typing.Optional[datetime.datetime],
) -> None:
self.large_scheduled_vehicle_repository.set_ramp_up_and_down_times(
self.vehicle_capacity_manager.set_ramp_up_and_down_times(
ramp_up_period_end=ramp_up_period_end,
ramp_down_period_start=ramp_down_period_start
)
Expand All @@ -63,7 +63,7 @@ def create_containers_for_large_scheduled_vehicle(
Creates all containers a large vehicle delivers to a terminal.
"""

self.large_scheduled_vehicle_repository.reset_cache()
self.vehicle_capacity_manager.reset_cache()

created_containers: MutableSequence[Container] = []

Expand All @@ -72,30 +72,33 @@ def create_containers_for_large_scheduled_vehicle(
# noinspection PyTypeChecker
large_scheduled_vehicle: LargeScheduledVehicle = large_scheduled_vehicle_as_subtype.large_scheduled_vehicle

free_capacity_in_teu = self.large_scheduled_vehicle_repository.get_free_capacity_for_inbound_journey(
free_capacity_in_teu = self.vehicle_capacity_manager.get_free_capacity_for_inbound_journey(
large_scheduled_vehicle_as_subtype
)

# this is based on the assumption that the smallest container is a 20' container
maximum_number_of_containers = int(math.ceil(free_capacity_in_teu))
self._load_distribution_approximators(maximum_number_of_containers, delivered_by)

while (self.large_scheduled_vehicle_repository.get_free_capacity_for_inbound_journey(
large_scheduled_vehicle_as_subtype
) > self.ignored_capacity):
while free_capacity_in_teu > self.ignored_capacity:
container = self._create_single_container_for_large_scheduled_vehicle(
delivered_by_large_scheduled_vehicle_as_subtype=large_scheduled_vehicle_as_subtype
)
created_containers.append(container)
is_exhausted = self.large_scheduled_vehicle_repository.block_capacity_for_inbound_journey(
is_exhausted = self.vehicle_capacity_manager.block_capacity_for_inbound_journey(
vehicle=large_scheduled_vehicle_as_subtype,
container=container
)
if is_exhausted and not large_scheduled_vehicle.capacity_exhausted_while_determining_onward_transportation:
large_scheduled_vehicle.capacity_exhausted_while_determining_onward_transportation = True
large_scheduled_vehicle.save()
break

free_capacity_in_teu = self.vehicle_capacity_manager.get_free_capacity_for_inbound_journey(
large_scheduled_vehicle_as_subtype
)

free_capacity = self.large_scheduled_vehicle_repository.get_free_capacity_for_inbound_journey(
free_capacity = self.vehicle_capacity_manager.get_free_capacity_for_inbound_journey(
large_scheduled_vehicle_as_subtype
)

Expand Down
16 changes: 8 additions & 8 deletions conflowgen/domain_models/factories/fleet_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ def create_feeder_fleet(
)

for i, arrival in enumerate(arrivals):
moved_capacity = schedule.average_moved_capacity # here we can add randomness later
inbound_container_volume = schedule.average_inbound_container_volume # here we can add randomness later
vehicle_name = f"{i + 1}"
feeder = self.vehicle_factory.create_feeder(
vehicle_name=vehicle_name,
capacity_in_teu=schedule.average_vehicle_capacity,
moved_capacity=moved_capacity,
inbound_container_volume=inbound_container_volume,
scheduled_arrival=arrival,
schedule=schedule
)
Expand Down Expand Up @@ -112,13 +112,13 @@ def create_deep_sea_vessel_fleet(
)

for i, arrival in enumerate(arrivals):
moved_capacity = schedule.average_moved_capacity # here we can add randomness later
inbound_container_volume = schedule.average_inbound_container_volume # here we can add randomness later
vehicle_name = f"{i + 1}"

deep_sea_vessel = self.vehicle_factory.create_deep_sea_vessel(
vehicle_name=vehicle_name,
capacity_in_teu=schedule.average_vehicle_capacity,
moved_capacity=moved_capacity,
inbound_container_volume=inbound_container_volume,
scheduled_arrival=arrival,
schedule=schedule
)
Expand Down Expand Up @@ -146,13 +146,13 @@ def create_train_fleet(
)

for i, arrival in enumerate(arrivals):
moved_capacity = schedule.average_moved_capacity # here we can add randomness later
inbound_container_volume = schedule.average_inbound_container_volume # here we can add randomness later
vehicle_name = f"{i + 1}"

train = self.vehicle_factory.create_train(
vehicle_name=vehicle_name,
capacity_in_teu=schedule.average_vehicle_capacity,
moved_capacity=moved_capacity,
inbound_container_volume=inbound_container_volume,
scheduled_arrival=arrival,
schedule=schedule
)
Expand Down Expand Up @@ -180,13 +180,13 @@ def create_barge_fleet(
)

for i, arrival in enumerate(arrivals):
moved_capacity = schedule.average_moved_capacity # here we can add randomness later
inbound_container_volume = schedule.average_inbound_container_volume # here we can add randomness later
vehicle_name = f"{i + 1}"

barge = self.vehicle_factory.create_barge(
vehicle_name=vehicle_name,
capacity_in_teu=schedule.average_vehicle_capacity,
moved_capacity=moved_capacity,
inbound_container_volume=inbound_container_volume,
scheduled_arrival=arrival,
schedule=schedule
)
Expand Down
6 changes: 3 additions & 3 deletions conflowgen/domain_models/factories/schedule_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def add_schedule(
vehicle_arrives_at: datetime.date,
vehicle_arrives_at_time: datetime.time,
average_vehicle_capacity: int,
average_moved_capacity: int,
average_inbound_container_volume: int,
next_destinations: Optional[List[Tuple[str, float]]],
vehicle_arrives_every_k_days: Optional[int] = None
) -> None:
Expand All @@ -31,7 +31,7 @@ def add_schedule(
vehicle_arrives_at: date of day
vehicle_arrives_at_time: time of the day
average_vehicle_capacity: in TEU
average_moved_capacity: in TEU
average_inbound_container_volume: in TEU
next_destinations: distribution
vehicle_arrives_every_k_days: Be aware of special meaning of None and -1!
"""
Expand All @@ -44,7 +44,7 @@ def add_schedule(
vehicle_arrives_at=vehicle_arrives_at,
vehicle_arrives_at_time=vehicle_arrives_at_time,
average_vehicle_capacity=average_vehicle_capacity,
average_moved_capacity=average_moved_capacity
average_inbound_container_volume=average_inbound_container_volume
)
# if it is None, use the default set in peewee, otherwise overwrite
if vehicle_arrives_every_k_days is not None:
Expand Down
28 changes: 14 additions & 14 deletions conflowgen/domain_models/factories/vehicle_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def create_truck(
def _create_large_vehicle(
self,
capacity_in_teu: int,
moved_capacity: int,
inbound_container_volume: int,
scheduled_arrival: datetime.datetime,
realized_arrival: datetime.datetime,
schedule: Schedule,
Expand All @@ -91,13 +91,13 @@ def _create_large_vehicle(
if capacity_in_teu < 0:
raise UnrealisticValuesException(f"Vehicle capacity must be positive but it was {capacity_in_teu}")

if moved_capacity < 0:
raise UnrealisticValuesException(f"Vehicle must move positive amount but it was {moved_capacity}")
if inbound_container_volume < 0:
raise UnrealisticValuesException(f"Vehicle must move positive amount but it was {inbound_container_volume}")

if moved_capacity > capacity_in_teu:
if inbound_container_volume > capacity_in_teu:
raise UnrealisticValuesException(
f"Vehicle can't move more than its capacity but for the vehicle with an overall capacity of "
f"{capacity_in_teu} the moved capacity was set to {moved_capacity}"
f"{capacity_in_teu} the moved capacity was set to {inbound_container_volume}"
)

if vehicle_name is None:
Expand All @@ -106,7 +106,7 @@ def _create_large_vehicle(
lsv = LargeScheduledVehicle.create(
vehicle_name=vehicle_name,
capacity_in_teu=capacity_in_teu,
moved_capacity=moved_capacity,
inbound_container_volume=inbound_container_volume,
scheduled_arrival=scheduled_arrival,
realized_arrival=realized_arrival,
schedule=schedule
Expand All @@ -116,7 +116,7 @@ def _create_large_vehicle(
def create_feeder(
self,
capacity_in_teu: int,
moved_capacity: int,
inbound_container_volume: int,
scheduled_arrival: datetime.datetime,
schedule: Schedule,
vehicle_name: Optional[str] = None
Expand All @@ -126,7 +126,7 @@ def create_feeder(
lsv = self._create_large_vehicle(
vehicle_name=vehicle_name,
capacity_in_teu=capacity_in_teu,
moved_capacity=moved_capacity,
inbound_container_volume=inbound_container_volume,
scheduled_arrival=scheduled_arrival,
realized_arrival=scheduled_arrival,
schedule=schedule
Expand All @@ -139,7 +139,7 @@ def create_feeder(
def create_deep_sea_vessel(
self,
capacity_in_teu: int,
moved_capacity: int,
inbound_container_volume: int,
scheduled_arrival: datetime.datetime,
schedule: Schedule,
vehicle_name: Optional[str] = None
Expand All @@ -149,7 +149,7 @@ def create_deep_sea_vessel(
lsv = self._create_large_vehicle(
vehicle_name=vehicle_name,
capacity_in_teu=capacity_in_teu,
moved_capacity=moved_capacity,
inbound_container_volume=inbound_container_volume,
scheduled_arrival=scheduled_arrival,
realized_arrival=scheduled_arrival,
schedule=schedule
Expand All @@ -162,7 +162,7 @@ def create_deep_sea_vessel(
def create_train(
self,
capacity_in_teu: int,
moved_capacity: int,
inbound_container_volume: int,
scheduled_arrival: datetime.datetime,
schedule: Schedule,
vehicle_name: Optional[str] = None
Expand All @@ -172,7 +172,7 @@ def create_train(
lsv = self._create_large_vehicle(
vehicle_name=vehicle_name,
capacity_in_teu=capacity_in_teu,
moved_capacity=moved_capacity,
inbound_container_volume=inbound_container_volume,
scheduled_arrival=scheduled_arrival,
realized_arrival=scheduled_arrival,
schedule=schedule
Expand All @@ -185,7 +185,7 @@ def create_train(
def create_barge(
self,
capacity_in_teu: int,
moved_capacity: int,
inbound_container_volume: int,
scheduled_arrival: datetime.datetime,
schedule: Schedule,
vehicle_name: Optional[str] = None
Expand All @@ -195,7 +195,7 @@ def create_barge(
lsv = self._create_large_vehicle(
vehicle_name=vehicle_name,
capacity_in_teu=capacity_in_teu,
moved_capacity=moved_capacity,
inbound_container_volume=inbound_container_volume,
scheduled_arrival=scheduled_arrival,
realized_arrival=scheduled_arrival,
schedule=schedule
Expand Down
2 changes: 1 addition & 1 deletion conflowgen/domain_models/large_vehicle_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Schedule(BaseModel):
"This determines the number of ship-to-shore gantry cranes that can serve the vessel "
"or the length of the train that must be served by portal cranes in the subsequent model."
)
average_moved_capacity = IntegerField(
average_inbound_container_volume = IntegerField(
null=False,
help_text="All vehicles moving according to this schedule move approx. this amount of TEU. "
"The actual amount of moved TEU might deviate if necessary to realize the provided modal split."
Expand Down
5 changes: 2 additions & 3 deletions conflowgen/domain_models/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ class LargeScheduledVehicle(BaseModel):
help_text="This is the vehicle capacity. It can be used, e.g., to determine how many cranes can serve it in "
"the subsequent model that reads in this data."
)
moved_capacity = IntegerField(
inbound_container_volume = IntegerField(
null=False,
help_text="This is the actually moved container volume in TEU for a single terminal visit on the inbound "
"journey."
help_text="This is the actually moved container volume in TEU for a single terminal visit on the inbound journey."

Check notice on line 68 in conflowgen/domain_models/vehicle.py

View check run for this annotation

codefactor.io / CodeFactor

conflowgen/domain_models/vehicle.py#L68

Line too long (122/121) (line-too-long)
)
scheduled_arrival = DateTimeField(
null=False,
Expand Down
16 changes: 8 additions & 8 deletions conflowgen/tests/analyses/test_container_dwell_time_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ def test_with_single_container(self):
vehicle_arrives_at=now.date(),
vehicle_arrives_at_time=now.time(),
average_vehicle_capacity=300,
average_moved_capacity=300,
average_inbound_container_volume=300,
)
feeder_lsv = LargeScheduledVehicle.create(
vehicle_name="TestFeeder1",
capacity_in_teu=300,
moved_capacity=schedule.average_moved_capacity,
inbound_container_volume=schedule.average_inbound_container_volume,
scheduled_arrival=now,
schedule=schedule
)
Expand Down Expand Up @@ -98,12 +98,12 @@ def test_with_two_containers(self):
vehicle_arrives_at=now.date(),
vehicle_arrives_at_time=now.time(),
average_vehicle_capacity=300,
average_moved_capacity=300,
average_inbound_container_volume=300,
)
feeder_lsv = LargeScheduledVehicle.create(
vehicle_name="TestFeeder1",
capacity_in_teu=300,
moved_capacity=schedule.average_moved_capacity,
inbound_container_volume=schedule.average_inbound_container_volume,
scheduled_arrival=now,
schedule=schedule
)
Expand Down Expand Up @@ -166,12 +166,12 @@ def test_with_two_containers_and_end_time(self):
vehicle_arrives_at=now.date(),
vehicle_arrives_at_time=now.time(),
average_vehicle_capacity=300,
average_moved_capacity=300,
average_inbound_container_volume=300,
)
feeder_lsv = LargeScheduledVehicle.create(
vehicle_name="TestFeeder1",
capacity_in_teu=300,
moved_capacity=schedule.average_moved_capacity,
inbound_container_volume=schedule.average_inbound_container_volume,
scheduled_arrival=now,
schedule=schedule
)
Expand Down Expand Up @@ -235,12 +235,12 @@ def test_with_two_containers_and_start_and_end_time(self):
vehicle_arrives_at=now.date(),
vehicle_arrives_at_time=now.time(),
average_vehicle_capacity=300,
average_moved_capacity=300,
average_inbound_container_volume=300,
)
feeder_lsv = LargeScheduledVehicle.create(
vehicle_name="TestFeeder1",
capacity_in_teu=300,
moved_capacity=schedule.average_moved_capacity,
inbound_container_volume=schedule.average_inbound_container_volume,
scheduled_arrival=now,
schedule=schedule
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def setup_feeder_data():
vehicle_arrives_at=now.date(),
vehicle_arrives_at_time=now.time(),
average_vehicle_capacity=300,
average_moved_capacity=300,
average_inbound_container_volume=300,
)
feeder_lsv = LargeScheduledVehicle.create(
vehicle_name="TestFeeder1",
capacity_in_teu=300,
moved_capacity=schedule.average_moved_capacity,
inbound_container_volume=schedule.average_inbound_container_volume,
scheduled_arrival=now,
schedule=schedule
)
Expand Down
Loading

0 comments on commit cec7a5e

Please sign in to comment.