Skip to content

Commit

Permalink
Modify test according to comments
Browse files Browse the repository at this point in the history
Modify test according to comments
  • Loading branch information
v-heli committed Jun 21, 2022
1 parent daecf0c commit 186427c
Show file tree
Hide file tree
Showing 13 changed files with 1,055 additions and 270 deletions.
37 changes: 25 additions & 12 deletions maro/simulator/scenarios/supply_chain/units/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,23 @@ class DistributionUnit(UnitBase):
"""

def __init__(
self, id: int, data_model_name: Optional[str], data_model_index: Optional[int],
facility: FacilityBase, parent: Union[FacilityBase, UnitBase], world: World, config: dict,
self,
id: int,
data_model_name: Optional[str],
data_model_index: Optional[int],
facility: FacilityBase,
parent: Union[FacilityBase, UnitBase],
world: World,
config: dict,
) -> None:
super(DistributionUnit, self).__init__(
id, data_model_name, data_model_index, facility, parent, world, config,
id,
data_model_name,
data_model_index,
facility,
parent,
world,
config,
)

self._vehicle_num: Dict[str, Optional[int]] = {}
Expand Down Expand Up @@ -88,6 +100,7 @@ def initialize(self) -> None:
self._busy_vehicle_num[vehicle_type] = 0

# TODO: add vehicle patient setting if needed

self.data_model.initialize()

for sku_id in self.facility.products.keys():
Expand All @@ -109,12 +122,14 @@ def place_order(self, order: Order) -> float:
float: The corresponding total order fee, will paid by the consumer.
"""
# TODO: to indicate whether it is a valid order or not in Return value?
if all([
order.sku_id in self.facility.downstream_vlt_infos,
order.dest_facility.id in self.facility.downstream_vlt_infos[order.sku_id],
order.vehicle_type in self.facility.downstream_vlt_infos[order.sku_id][order.dest_facility.id],
order.required_quantity > 0
]):
if all(
[
order.sku_id in self.facility.downstream_vlt_infos,
order.dest_facility.id in self.facility.downstream_vlt_infos[order.sku_id],
order.vehicle_type in self.facility.downstream_vlt_infos[order.sku_id][order.dest_facility.id],
order.required_quantity > 0,
],
):
self._order_queues[order.vehicle_type].append(order)
self._maintain_pending_order_info(order, is_increase=True)
self.total_order_num += 1
Expand Down Expand Up @@ -230,9 +245,7 @@ def step(self, tick: int) -> None:
# TODO: here do not distinguish on the way & pending unloading.
for order_list in self._order_on_the_way.values():
for order in order_list:
self.transportation_cost[order.sku_id] += (
order.unit_transportation_cost_per_day * order.payload
)
self.transportation_cost[order.sku_id] += order.unit_transportation_cost_per_day * order.payload

# Schedule orders
self.try_schedule_orders(tick)
Expand Down
2 changes: 2 additions & 0 deletions tests/data/supply_chain/case_01/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ world:
sku3:
init_stock: 80
has_manufacture: True
has_consumer: True
max_manufacture_rate: 50
manufacture_leading_time: 1
unit_product_cost: 1
Expand All @@ -105,6 +106,7 @@ world:
init_stock: 96
has_manufacture: True
max_manufacture_rate: 50
has_consumer: True
manufacture_leading_time: 1
unit_product_cost: 1
price: 100
Expand Down
25 changes: 24 additions & 1 deletion tests/data/supply_chain/case_05/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@ world:
unit_delay_order_penalty: 20
unit_order_cost: 0

- name: "Supplier_SKU1"
definition_ref: "SupplierFacility"
skus:
sku3:
init_stock: 80
has_manufacture: True
max_manufacture_rate: 50
manufacture_leading_time: 1
unit_product_cost: 1
price: 10
unit_delay_order_penalty: 10
has_consumer: True
children:
storage: *small_storage
distribution: *normal_distribution
config:
unit_delay_order_penalty: 20
unit_order_cost: 0

- name: "Warehouse_001"
definition_ref: "WarehouseFacility"
skus:
Expand Down Expand Up @@ -232,7 +251,7 @@ world:
storage: *single_storage
config:
unit_order_cost: 200
file_path: "tests/data/supply_chain/case_05/test_case_05.csv"
file_path: "tests/data/supply_chain/case_04/test_case_04.csv"

topology:

Expand All @@ -258,6 +277,10 @@ world:

Warehouse_001:
sku3:
"Supplier_SKU1":
"train":
vlt: 3
cost: 1
"Supplier_SKU3":
"train":
vlt: 3
Expand Down
Loading

0 comments on commit 186427c

Please sign in to comment.