c - 快餐店模拟 : How to "queue" customers?

标签 c arrays loops queue simulation

<分区>

指向我的 PasteBin 的链接: http://pastebin.com/nzW3hZdT

I'm in the process of simulating a fast food restaurant over three hours. The three hours are divided into 18 intervals, consisting of 10 minutes each.

Based off an arrival rate of 'r' customers per minute, 'R' is established. R is the arrival rate, by probability, for all 18 intervals (which is more or less r/60).

The purpose of this simulation is to define 'r' ourselves and see the average waiting time (avgWait) of each customer in all 18 intervals. Generally, the greater the 'r', the greater the 'avgWait'.

此时在我的代码中(粘贴在上面),平均等待时间正确打印......对于一位客户。

假设第一位和第二位顾客分别在收银台 1 和收银台 2 接受订单大约需要 85 秒。在这 85 秒内,很有可能有更多的顾客到达,但是因为 cash1empty=FALSEcash2empty=FALSE 他们显然无法接受他们的订单。

我如何设置这个队列,以便程序知道在前两个订单得到服务后还有几个其他人在等待服务?

代码摘录:

if ((cash1empty==TRUE)&&(cash2empty==TRUE))
                    {
                        switch((rand()%2))
                        {
                            case 0:
                                cash1empty=FALSE;
                                break;
                            case 1:
                                cash2empty=FALSE;
                                break;

                        }
                    }

                    if (cash1empty==TRUE)
                    {
                        cash1empty=FALSE;

                        switch((rand()%2))
                        {
                            case 0:
                                cash1salad=(rand()%(66-55)+55);
                                totalWait+=cash1salad;
                                break;
                            case 1:
                                cash1burger=(rand()%(131-111)+111);
                                totalWait+=cash1burger;
                                break;
                        }
                    }
                    else if (cash2empty=TRUE)
                    {
                        cash2empty=FALSE;

                        switch(rand()%2)
                        {
                            case 0:
                                cash2salad=(rand()%(76-65)+65);
                                totalWait+=cash2salad;
                                break;
                            case 1:
                                cash2burger=(rand()%(141-121)+121);
                                totalWait+=cash2burger;
                                break;
                        }
                    }
                    else
                    {
                        queue++; // ???
                        /// I DON'T KNOW WHAT I'M DOING.
                    }

对于给您带来的不便,我深表歉意,但我不能使用“结构”。数组是可以接受的!

最佳答案

你为什么不使用 Queue ?使用常规数组似乎是不合理的。对于队列,您可以使用 Dequeue()方法获取第一个客户并将其从队列中删除,然后使用 [Enqueue()][3] 方法添加新客户。

为什么你会使用除队列以外的任何东西?

关于c - 快餐店模拟 : How to "queue" customers?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13325082/

相关文章:

c - 二维数组中值滤波

ios - 我怎样才能保护自己免受这次崩溃 *** -[__NSArrayM objectAtIndex :]: index 1 beyond bounds [0 . 。 0]?

javascript - PHP数组转JS数组并重构

c - 结果,While 循环无法开始忽略 if 语句和条件

c - 字段的类型不完整 - union 和结构

c - BZip2 解压非文件数据时不会出现错误?

Python 提前离开循环

python - 在 python 2.7 中搜索重复值列表

c - 提升指向未定义位置的指针是否合法?

c - 在结构中的数组末尾填充