/******************************************************************************
* Compilation: javac MM1Queue.java
* Execution: java MM1Queue lambda mu
* Dependencies: Queue.java Histogram.java
*
* Simulate an M/M/1 queue where arrivals and departures are Poisson
* processes with arrival rate lambda and service rate mu.
*
* % java MM1Queue .20 .33
*
* % java MM1Queue .20 .25
*
* % java MM1Queue .20 .21
*
*
* Remarks
* -------
* - We assume the interrarrival and service times are independent.
*
*
******************************************************************************/ public class MM1Queue { public static void main(String[] args) {
double lambda = Double.parseDouble(args[0]); // arrival rate
double mu = Double.parseDouble(args[1]); // service rate Queue<Double> q = new Queue<Double>(); // arrival times of customers
double nextArrival = StdRandom.exp(lambda); // time of next arrival
double nextDeparture = Double.POSITIVE_INFINITY; // time of next departure // histogram object
Histogram hist = new Histogram(60); // simulate an M/M/1 queue
while (true) { // it's an arrival
if (nextArrival <= nextDeparture) {
if (q.isEmpty()) nextDeparture = nextArrival + StdRandom.exp(mu);
q.enqueue(nextArrival);
nextArrival += StdRandom.exp(lambda);
} // it's a departure
else {
double wait = nextDeparture - q.dequeue();
StdOut.printf("Wait = %6.2f, queue size = %d\n", wait, q.size());
hist.addDataPoint(Math.min(60, (int) (Math.round(wait))));
hist.draw();
if (q.isEmpty()) nextDeparture = Double.POSITIVE_INFINITY;
else nextDeparture += StdRandom.exp(mu); }
} } }

最新文章

  1. qemu ubuntu for zynq(armhf)
  2. [转] Fix: Screen Clipping Shortcut In OneNote Not Working After Upgrading To Windows 8.1
  3. ETL利器Kettle
  4. 在ubuntu上搭建开发环境10---英文版ubuntu安装中文输入法
  5. 重新想象 Windows 8 Store Apps (56) - 系统 UI: Scale, Snap, Orientation, High Contrast 等
  6. hadoop(一):深度剖析hdfs原理
  7. Hbase之尝试使用错误列族获取数据
  8. linux ps命令详解
  9. Android emulator warning----Emulator window was out of view and was recentred
  10. 247. Strobogrammatic Number II
  11. HTML入门基础教程相关知识
  12. 认识基本的UI资源
  13. Linux系统学习笔记之 1 基础命令
  14. mongoDB2--mongoDB的下载和安装。
  15. UITableView回调和table相关成员方法详解
  16. poj2774 Long Long Message 后缀数组求最长公共子串
  17. WordCount项目
  18. (转载,但不知道谁原创)获取SPRING 代理对象的真实实例,可以反射私有方法,便于测试
  19. 2018上C语言程序设计(高级)博客作业样例
  20. 向 Nginx 主进程发送 USR1 信号

热门文章

  1. 【WCF】利用WCF实现上传下载文件服务
  2. Github-jcjohnson/torch-rnn代码详解
  3. 面试题13:在O(1)时间删除链表结点
  4. codeigniter教程:Codeigniter出现Unable to connect to your databas
  5. nyoj-952-最大四边形 (向量叉乘)
  6. PHP文件管理
  7. git教程5-查看关系图与no fast forward融合
  8. python 获取本机ip地址的方法(Unix 平台)
  9. PCM音量控制
  10. 关于java.lang.ClassNotFoundException