我是python的新手,正在尝试对仓库物流进行模拟。该问题由四个主要主体组成: 棚子,卡车,摩托车和配电线。卡车以指定数量的箱子进入棚的一侧,到达棚的中心,停止并开始将箱子卸到分配线,分配线将箱子移到棚的另一侧,供摩托车取货每个一盒。 目的是改变棚屋和分配线的大小,以找到可以在固定的时间内交付更多箱子的形状(或像我现在的代码中那样计算分配固定数量的箱子所花费的时间)>
分配线是一个矩形,是一个网格,具有不同数量的行和列,具体取决于棚的大小,比方说每个单元的每侧有0,50m。
在代码中,我模拟了通过棚子的卡车以及经过迭代的卡车数量,问题是:
如何模拟通过网格(配电线)从一侧移动到另一侧的盒子,也许在库存中积累直到自行车到达,然后让摩托车“抓住”它们并在盒子到达后熄灭? / p>
我试图用“ + = 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
我愿意接受代码建议,图书馆指示以及我可以搜索和学习的其他资源,任何帮助将不胜感激!谢谢!
答案 0 :(得分:0)
public class HomeController : Controller
{
private readonly IMapper _mapper;
private readonly ApplicationDbContext _context;
public HomeController(IMapper mapper
, ApplicationDbContext context)
{
_mapper = mapper;
_context = context;
}
public async Task<IActionResult> Index()
{
CreatePostRequestDTO createPostRequestDTO = new CreatePostRequestDTO {
Body = "B1",
UserId = 1,
PostItems = new List<PostItemDTO> {
new PostItemDTO { AttachmentId = 1, TaggedUsers = new List<PostItemTagDTO>{
new PostItemTagDTO{ UserId = 1, X = 1, Y= 11 }
} }
}
};
var post = _mapper.Map<Post>(createPostRequestDTO);
await _context.AddAsync(post);
await _context.SaveChangesAsync();
return View();
}
}
以您的方式,box = 0
while truck_middle == True:
if box < truck1.truck_load:
box += 1
else:
truck_middle = False
始终为box
,1
始终为truck_middle
,并且陷入死循环