快餐店的模拟:如何与QUOT;排队"顾客? [英] Fast food restaurant simulation : How to "queue" customers?

查看:127
本文介绍了快餐店的模拟:如何与QUOT;排队"顾客?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

A链接到我的引擎收录: http://pastebin.com / nzW3hZdT

我是在三个模拟快餐店的过程
  小时。三个小时数分为18个区间,由10
  每分钟。

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.

根据关每分钟'R'客户的到达率,'R'是
  成立。 R是到达率,用概率,为所有18
  间隔(这是或多或少转/ 60)

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).

此模拟的目的是定义为'r'自己和看
  平均等待时间在所有18间隔每个客户(avgWait)。
  通常,更大的R越大,'avgWait'

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'.

在我的code这点(高于粘贴),平均等待时间是正确的...打印一个客户。

At this point in my code (pasted above), the average wait times are printing properly...for ONE customer.

可以说,它需要大约85秒,第一个和第二个客户拿订单分别收银员1和2在这些85秒,极有可能更多的客户来了,但因为 cash1empty = FALSE cash2empty = FALSE 他们显然不能得到采取他们的订单。

Lets say it takes about 85 seconds for the first and second customer to take their orders respectively on cashier 1 and 2. In those 85 seconds, it is highly probable that more customers arrived, but since cash1empty=FALSE and cash2empty=FALSE they obviously can't get their order taken.

如何设置这个队列,以便那么程序知道有几个人等待两阶得到服务后,获得服务?

How can I set up this queue so then the program knows there are several others waiting to get serviced after the first two order gets serviced?

code的摘录:

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.
                    }

我的不便表示歉意,但我不能用结构。数组是可以接受的!

I apologize for the inconvenience but I cannot use "structures". Arrays are acceptable!

推荐答案

请客户数量的计数在队列中, queuedCustomers 。添加一个当每个新客户到达(在你增加的同时 totalCustomer )。减之一,当你服务于客户,也就是说,当你赛克 cash1empty = FALSE; cash2empty = FALSE;

Keep a count of the number of customers in the queue, queuedCustomers. Add one when each new customer arrives (at the same time you increment totalCustomer). Subtract one when you service the customer, i.e., when you sey cash1empty=FALSE; or cash2empty=FALSE;

修改

            if (customerArrive>=x)
            {

                // A customer arrived during this second!
                totalCustomer++;

            if (customerArrive>=x)
            {

                // A customer arrived during this second!
                totalCustomer++;
                queuedCustomers++;
            }
            if (queuedCustomers > 0)
            {

补遗回复:选择一个收银员......

Addendum re: choosing a cashier...

而不是部分 IF((cash1empty == TRUE)及及(cash2empty == TRUE))

做这样的事情:

cointoss = rand()%2

if ((cash1empty==TRUE) && ((cash2empty!=TRUE) || (cointoss == 1)))
{
    // use cashier 1
} 
else if (cash2empty==TRUE)
{
    // use cashier 2
} 
else
{
    // wait
}

这篇关于快餐店的模拟:如何与QUOT;排队"顾客?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆