本文整理汇总了Python中simulation.Simulation.schedule_event方法的典型用法代码示例。如果您正苦于以下问题:Python Simulation.schedule_event方法的具体用法?Python Simulation.schedule_event怎么用?Python Simulation.schedule_event使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类simulation.Simulation
的用法示例。
在下文中一共展示了Simulation.schedule_event方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WarehouseManager
# 需要导入模块: from simulation import Simulation [as 别名]
# 或者: from simulation.Simulation import schedule_event [as 别名]
class WarehouseManager(object):
def __init__(self, num_of_drones, warehouse_drone_nums, warehouse_order_ids, warehouse_info, order_info, drone_load):
self.warehouses = WarehouseManager.create_warehouses(warehouse_info)
self.delivery_drones, self.assistant_drones = self.initialize_drones(num_of_drones,
warehouse_drone_nums,
self.warehouses)
self.assign_orders_to_warehouse(warehouse_order_ids)
self.simulation = Simulation()
self.order_info = order_info
self.drone_load = drone_load
@staticmethod
def create_warehouses(warehouse_info):
return [Warehouse(i, w['loc'], w['stock']) for i, w in enumerate(warehouse_info.values())]
def initialize_drones(self, num_of_drones, warehouse_drone_nums, warehouses):
delivery_drones = []
assistant_drones = []
i = 0
for w_id, (delivery_drone_count, assistant_drone_count) in warehouse_drone_nums.iteritems():
delivery_drone_count = int(delivery_drone_count)
assistant_drone_count = int(assistant_drone_count)
ddrones = [DeliveryDrone(c) for c in xrange(i, i+delivery_drone_count)]
map(lambda d: self.simulation.schedule_event(d.go(warehouses[w_id].loc)), ddrones)
delivery_drones.extend(ddrones)
i += delivery_drone_count
asdrones = [AssistantDrone(c) for c in xrange(i, i+assistant_drone_count)]
map(lambda d: self.simulation.schedule_event(d.go(warehouses[w_id].loc)), asdrones)
assistant_drones.extend(ddrones)
i += assistant_drone_count
# TODO: It seems like this is an error (syntactically)
warehouses[w_id].assign_drones(ddrones + asdrones)
return delivery_drones, assistant_drones
def assign_orders_to_warehouse(self, warehouse_order_ids):
for warehouse_id, orders in warehouse_order_ids.iteritems():
self.warehouses[warehouse_id].assign_orders(orders)
def schedule_remaining_orders_in_the_warehouse(self, warehouse):
drones = warehouse.drones
unassigned_drones = Queue()
for drone in drones:
unassigned_drones.put(drone)
orders = warehouse.orders
inventory = warehouse.stock
def is_satisfiable(order):
order_as_array = [self.order_info[order][product_id] for product_id in self.order_info[order].keys()]
return all(map(lambda x: x[0] >= x[1], zip(inventory, order_as_array)))
for order in orders:
if is_satisfiable(order):
next_unassigned_drone = unassigned_drones.get()
if next_unassigned_drone
def start_delivering(self, order_info):
# Not Finished
for warehouse in self.warehouses:
for order in warehouse.orders:
if order in warehouse.stock:
pass
def transfer_remaining_orders_to_warehouses(self):
# find the closest warehouse pairs.
w2w_distances = Warehouse.calc_w2w_distances(self.warehouses)
orders = dd(list)
for w in self.warehouses:
for order in w.orders:
for product in order:
# product id
w1 = Warehouse.find_product_closest_warehouse(product, w2w_distances[w.id])
# key: (from_warehouse, to_warehouse)
orders[(w1.id, w.id)].append(product)
optimized_orders = {}
for k, order_list in orders.iteritems():
optimized_orders[k] = Counter(order_list)