事件驱动的对象模拟
我正在编写一个事件驱动的模拟程序。我有 3 个继承 1 个基类的子类。我需要随机生成这三个子类,每个子类将经历不同的事件路径(抱歉,它有点难以描述我的意思),我举一个例子:
假设我们在商场有一个停车场模拟,我们有基础车辆类,以及汽车、摩托车、卡车集装箱子类。汽车和摩托车只是停放一段时间(随机)然后离开,而卡车集装箱只需要在装卸集装箱时停放并离开,集装箱的数量将决定卡车停放的时间。
我如何随机创建这3个对象,假设1分钟内有5-10辆汽车进入停车场,10分钟内有1-3辆摩托车,一天内只有1-2个卡车集装箱?
谢谢
i am writing an event driven simulation program. i have 3 subclasses that inherit 1 base class. i need to generate those three randomly and each subclass will go through different event path (sorry its a bit hard to describe what i meant), ill give an example:
let say we have a car park simulation at a mall, we have the base class Vehicle, and subclasses Car, Motorbike, TruckContainer. the Car and Motorbike is just going to park for a period of time(random) and leave while TruckContainer need to park only for unloading and loading the container and leave, the number of container will decide how long the truck will park.
how can i create those 3 objects randomly, let say 5-10 car will enter the car park in 1minute, 1-3 motorbike in 10minute, and only 1-2 truck container in a day?
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能会带你到那里
This might lead u there
据我了解,您想要一个在(例如您的汽车类别)5-10、1-2(卡车)和 1-3(自行车)范围内的随机数生成器...
您可以使用伪随机数生成器 rand()...
用于您的汽车:
但不要忘记通过 srand() 初始化您的 rand!...
当然,您需要控制在时间片内(例如 10 分钟)的时间自行车将会到达...
希望这有帮助
So as far as I understood You want a random number generator within the limits of (for example your car class) 5-10, 1-2 (truck) and 1-3 (bike)...
You may do this by using the pseudo-random-number generator rand()...
for Your car:
but dont forget to initialize your rand via srand()!...
Of course You need to control when in the time slice (for example the 10 minutes) the bikes will arrive...
Hope this helps