首页 > 解决方案 > 模拟配送线中包裹的过渡

问题描述

我是 python 新手,正在尝试模拟仓库物流。问题由四个主要代理组成:一个棚子、卡车、摩托车和一条配送线。卡车从一侧进入棚子,装载指定数量的箱子,到达棚子中心,停止并开始将箱子卸到配送线,配送线将箱子移动到棚子的另一侧,摩托车取货每人一盒。目标是改变棚子和分配线的大小,以找到可以在固定时间内交付更多盒子的形状(或计算分配固定数量的盒子所花费的时间,就像我现在的代码一样)

分配线是一个矩形,一个具有可变数量的行和列的网格,具体取决于棚子的大小,假设每个单元的每边都有 0,50m。

在代码中,我模拟了通过棚子的卡车,以及作为迭代通过的卡车数量,问题是:

如何模拟箱子从一侧通过网格(分配线)移动到另一侧,可能会在库存中积累直到自行车到达,然后让摩托车“抓住”它们并在箱子到达后出去?

我试图用“+= 1”函数计算盒子,但我不知道为什么它不起作用(也不太现实)

这是主要代码:

import time
from Vehicles import Truck, Motorbike

bike1 = Motorbike(10, 1)
truck1 = Truck(10, int(input("Enter how many loads the truck has: ")))
num_iterations = int(input("Enter number of iterations: "))

start = time.time()

shed_width = 4
shed_length = 12
truck_path = int(shed_length * truck1.truck_speed/2)

for n in range(num_iterations):
    truck_middle = False
    while truck_middle is not True:
        for i in range(truck_path):
            x = 100/truck_path
            if i == truck_path/2:
                truck_middle = True
            else:
    #the bar here is to just have some visual feedback while the code runs
                print("\r[%-60s] %d%%" % ('=' * i, x * i), end='')
                time.sleep(0.1)

        print("\ntruck is in the middle")
        truck_middle = True

    # while truck_middle is True:
    #     box = 0
    #     if box < truck1.truck_load:
    #         box += 1
    #     else:
    #         truck_middle = False
    print("This was iteration: " + str(n+1))
    time.sleep(0.01)


end = time.time()

print("\nDone! \nThe simulation took " + str(end - start) + " seconds to complete!")

我还在一个名为“Vehicles”的文件中为卡车和摩托车创建了一个类,我可以在其中定义它们的速度和它们可以承载的负载:

class Truck:
    def __init__(self, truck_speed, truck_load):
        self.truck_speed = truck_speed
        self.truck_load = truck_load

class Motorbike:
    def __init__(self, motorbike_speed, motorbike_load):
        self.motorbike_speed = motorbike_speed
        self.motorbike_load = motorbike_load

我愿意接受代码建议、库的指示以及我可以搜索和研究的其他资源,任何帮助将不胜感激!谢谢!

标签: pythonloopssimulation

解决方案


box = 0
while truck_middle == True:

    if box < truck1.truck_load:
        box += 1
    else:
        truck_middle = False

以你的方式, boxwill always be 1and truck_middleare always True, 它进入死循环


推荐阅读