大家好,我是小鸭酱,博客地址为:http://www.cnblogs.com/xiaoyajiang
以下鄙人实现了排队论思想,语言是C语言
 
#include<stdio.h>
#include<float.h>
 
int main()
{
 
/************************************what we know in the system**************************************/
    float arrivals[] = {0.4, 1.6, 2.1, 3.8, 4.0, 5.6, 5.8, 7.2};//the time of each customer's arrival
    float departures[] = {2.4, 3.1, 3.3, 4.9, 8.6};//the time of each customer's departure
    int acount = 0;//the index of arrivals array
    int dcount = 0;//the index of departures array
/***************the clock and clock event in the simulating system******************/
    float clock = 0;//simulation clock
    float clock_event[2] = {arrivals[acount],departures[dcount]};//clock[0] means arrival time,clock[1] means departure time
    int clock_event_times[2] = {0, 0}; //clock_event_times[0] means the count of arrival event happened;
                                        //clock_event_times[1] means the count of departure event happened
/*****************system state ****************************/
    int serve_status = 0;//false means ideal and 1 means busy
    int no_in_queue = 0;//the number in queue
    float time_of_arrival[4] = {0};//the time of arrival
    float time_of_last_event = 0;// the time of last event
 
/*****************statistical counters***************/
    int no_delayed = 0;//the number of delayed
    float total_delay = 0;//the total delay time
    float area_under_Q = 0;//the area under queue(t)
    float area_under_B = 0;//the area under busy(t)
    
/********the stop time***/
    char temp;
    int end_event;
    printf("Please input the stop event of this simulating system(a means arrival and d means departure): ");
    scanf("%c", &temp);
    if (temp == 'd')
        end_event = 1;
    else
        end_event = 0;
    int ordinal;
    printf("Please input the customer's ordinal of the stop event you have input:");
    scanf("%d", &ordinal);
    
/***********start********************/
    while(clock_event_times[end_event] < ordinal)
    {
 
        if(clock_event[0]<clock_event[1] )//arrival event
        {
            clock = clock_event[0];
            acount += 1;
            clock_event[0] = arrivals[acount];
            clock_event_times[0] += 1;
            if(serve_status == 0)//no body
            {
                serve_status = 1;
            }
            else
            {
                time_of_arrival[no_in_queue] = clock;
                area_under_B += serve_status * (clock - time_of_last_event);
                area_under_Q += no_in_queue * (clock - time_of_last_event);
                no_in_queue += 1;
            }
 
        }
        else//department event
        {
            clock = clock_event[1];
            dcount += 1;
            clock_event[1] = departures[dcount];
            clock_event_times[1] += 1;
            area_under_B += clock - time_of_last_event;
            if(no_in_queue == 0)
            {
                serve_status = 0;
            }
            else
            {
                clock_event[1] = departures[dcount];
                total_delay += clock - time_of_arrival[0];
                area_under_Q += no_in_queue * (clock - time_of_last_event);
                no_in_queue -= 1;
                time_of_arrival[0] = time_of_arrival[1];
                time_of_arrival[1] = time_of_arrival[2];
                time_of_arrival[2] = time_of_arrival[3];
 
            }
 
        }
        time_of_last_event = clock;
    }
    printf("Number delayed: %d\n", clock_event_times[1]);
    printf("Total delay: %2f\n", total_delay);
    printf("Area under Q(t): %2f\n", area_under_Q);
    printf("Area under B(t): %2f\n", area_under_B);
 
    return 0;
}

排队论的C实现的更多相关文章

  1. JAVA实现排队论

    转载请注明出处:http://blog.csdn.net/xiaojimanman/article/details/50401727 http://www.llwjy.com/blogdetail/3 ...

  2. 建模算法(七)——排队论模型

    (一)基本概念 一.排队过程的一般表示 凡是要求服务的对象称为顾客,凡是为顾客服务的称为服务员 二.排队系统的组成和特征 主要由输入过程.排队规则.服务过程三部分组成 三.排队模型的符号表示 1.X: ...

  3. 更新过程 renewal process

    一类随机过程.是描述元件或设备更新现象的一类随机过程.设对某元件的工作进行观测.假定元件的使用寿命是一随机变量,当元件发生故障时就进行修理或换上新的同类元件,而且元件的更新是即时的(修理或更换元件所需 ...

  4. 十分钟了解分布式计算:GraphLab

    GraphLab是一个面向大规模机器学习/图计算的分布式内存计算框架,由CMU在2009年开始的一个C++项目,这里的内容是基于论文 Low, Yucheng, et al. "Distri ...

  5. SQL Server 内存数据库原理解析

    前言 关系型数据库发展至今,细节上以做足文章,在寻求自身突破发展的过程中,内存与分布式数据库是当下最流行的主题,这与性能及扩展性在大数据时代的需求交相辉映.SQL Server作为传统的数据库也在最新 ...

  6. little's law(律特法则)

    参考:https://en.wikipedia.org/wiki/Little%27s_law(周末看一下) 最近在做性能压力测试,开始时,压力压不上去,参考: N = X * E[T] ,N就是你的 ...

  7. [珠玑之椟]估算的应用与Little定律

    [珠玑之椟]估算的应用与Little定律 估算的数据主要依赖于所能获得的数据和常识,有时还包括实践而不仅仅是理论.它常常作为一个大问题中的子问题,恰当地估算可以省去精确计算的时间和开销.在计算机领域, ...

  8. RabbitMQ-从基础到实战(6)— 与Spring集成

    0.目录 RabbitMQ-从基础到实战(1)- Hello RabbitMQ RabbitMQ-从基础到实战(2)- 防止消息丢失 RabbitMQ-从基础到实战(3)- 消息的交换(上) Rabb ...

  9. 【概率论与数理统计】小结4 - 一维连续型随机变量及其Python实现

    注:上一小节总结了离散型随机变量,这个小节总结连续型随机变量.离散型随机变量的可能取值只有有限多个或是无限可数的(可以与自然数一一对应),连续型随机变量的可能取值则是一段连续的区域或是整个实数轴,是不 ...

随机推荐

  1. Codeforces 519E A and B and Lecture Rooms

    http://codeforces.com/contest/519/problem/E 题意: 给出一棵树和m次询问,每次询问给出两个点,求出到这两个点距离相等的点的个数. 思路: lca...然后直 ...

  2. inux xsel 拷贝复制命令行输出放在系统剪贴板上

    转载自:http://oldratlee.com/post/2012-12-23/command-output-to-clip 为什么要这么做?直接把命令的输出(比如 grep/awk/sed/fin ...

  3. 【转】深入理解Android的startservice和bindservice--不错

    原文网址:http://www.cnblogs.com/yejiurui/p/3429451.html 一.首先,让我们确认下什么是service?         service就是android系 ...

  4. hdu3308--LCIS 最大连续递增序列长度

    这个是动态的,所以要用线段树维护.代码里有注释因为ls敲成lsum,rs敲成rsum查错查了好久.. #include <set> #include <map> #includ ...

  5. c语言结构体1之定义

    这是在复习阶段随便小结的一些东西 别喷哦 结构体定义的三种方式 注意事项: 1结构体括号后面有分号 2#define得放在程序上面 3成员名可以和结构体名相同 4结构体类型不能直接访问成员,也不能赋值 ...

  6. java基础 二分查找算法

    /*   * 折半查找法:   * 思路:   * 定义三个变量记录查找范围中最大.最小和中间的索引值,每次都是使用中间索引值与要查找的目标进行对比,如果不符合,那么就不停缩小查找范围   * */  ...

  7. ZigBee心电传输(一)

    第一次接触模拟的东西哈,也算是一次新的学习旅程以及对ZigBee的再一次探索吧. 首先是方案制定,以及采用芯片AD8232,这样节省了不少时间,把模拟的东西都搬到数字上了,不过还是需要学习不少模电知识 ...

  8. JMeter简单的性能测试实例

    JMeter基础之——一个简单的性能测试 我们了解了jmeter的一此主要元件,那么这些元件如何使用到性能测试中呢.这一节创建一个简单的测试计划来使用这些元件.该计划对应的测试需求. 1)测试目标网站 ...

  9. PHP中$_SERVER的具体參数与说明

    PHP编程中常常须要用到一些server的一些资料.特把$_SERVER的具体參数整理下,方便以后使用. $_SERVER['PHP_SELF'] #当前正在执行脚本的文件名称,与 document ...

  10. jQuery中 $ 符号的冲突问题

    jQuery中 $ 符号的冲突问题是常见问题之一.   在jQuery中,$是jQuery的别名,为了书写方便,我们更习惯用$('#id')这一类的方式来书写代码.当同一页面引用了jQuery多个版本 ...