資源簡介
m/m/1理發(fā)排隊仿真,隨機產生理發(fā)人進理發(fā)店進行理發(fā),理發(fā)師根據(jù)來的先后順序進行理發(fā),從而算出各個理發(fā)人的時間,離開時間,理發(fā)師的利率效率,

代碼片段和文件信息
#include?“EventTable.h“
void?Delay(int?time)
{
clock_t?now?=?clock();
while?(?clock()-now}
EventTable::EventTable()
{
_simulateTime?=?150;
_waitNum?=?0;
_currentTime?=?0;
_totalWaitTime?=?0;
_totalWorkTime?=?0;
_totalConsumerNum?=?0;
_maxLine?=?0;
}
EventTable::EventTable(int?time)
{
_simulateTime?=?time;
_waitNum?=?0;
_currentTime?=?0;
_totalWaitTime?=?0;
_totalWorkTime?=?0;
_totalConsumerNum?=?0;
_maxLine?=?0;
}
int?EventTable::poissonRand(float?lamda)
{
if?(lamda==0)
{
return?0;
}
srand((unsigned?int)time(0)?+?rand());
int?result?=?0;
while(result==0)
{
float?r?=?rand()?/?float(RAND_MAX);
result?=?(int)(-log(r)?*?lamda);
}
return?result;
}
void?EventTable::makeTable()
{
Event?e0?e1;
e0.type?=?0;
e0.time?=?0;
e1.type?=?1;
e1.time?=?0;
int?tmpTime?=?0;
int?index?=?0;
while?(tmpTime<_simulateTime)
{
e0.index?=?index;
e0.time?+=?poissonRand(5);
_arriveEvent.push_back(e0);
e1.index?=?index++;
e1.time?=?poissonRand(4);
_leaveEvent.push_back(e1);
tmpTime?=?e0.time;
}
_arriveEvent.erase(_arriveEvent.end()-1);
_leaveEvent.erase(_leaveEvent.end()-1);
}
void?EventTable::simulate()
{
_currentTime?=?0;
bool?barberBusy?=?false;
int?startWorkTime?=?0;
int?endWorkTime?=?0;
int?lastEventTime?=?0;
int?currentConsumer?=?0;
int?benchNum?=?0;
//? vector?bench;
Event?event;//?lastEvent;
/* vector::iterator?iter;*/
while?(_currentTime<_simulateTime?&&?0!=_leaveEvent.size())
{
if?(_arriveEvent.size()>0?&&?_arriveEvent[0].time<=_leaveEvent[0].time)
event?=?_arriveEvent[0];
else?if?(currentConsumer==0)
event?=?_arriveEvent[0];
else
event?=?_leaveEvent[0];
_currentTime?=?event.time<=_simulateTime???event.time?:?_simulateTime;
_totalWaitTime?+=?benchNum?*?(_currentTime?-?lastEventTime);
lastEventTime?=?_currentTime;
//? if?(_currentTime?>?_simulateTime)
//? break;
cout?<“當前時間:“?< switch(event.type)
{
case?0:
cout?<“第“?< if?(barberBusy)
{
benchNum++;
if?(benchNum?>?_maxLine)
_maxLine?=?benchNum;
//cout?<“有“?< }
else
{
benchNum?=?(benchNum==0)???0?:?(--benchNum);
//cout?<“第“?< barberBusy?=?true;
startWorkTime?=?_currentTime;
currentConsumer++;
_leaveEvent[0].time?+=?event.time;
}
cout?<“第“?< cout?<“有“?< _arriveEvent.erase(_arriveEvent.begin());
break;
case?1:
_totalConsumerNum++;
barberBusy?=?false;
endWorkTime?=?_currentTime;
_totalWorkTime?+=?endWorkTime?-?startWorkTime;
cout?<“第“?< if?(benchNum)
{
benchNum--;
barberBusy?=?true;
startWorkTime?=?_currentTime;
_leaveEvent[1].time?+=?_c
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-07-07?10:19??simulate\
?????目錄???????????0??2015-07-07?10:27??simulate\simulate\
?????目錄???????????0??2015-07-07?10:19??simulate\simulate\Debug\
?????文件???????65024??2015-07-07?10:22??simulate\simulate\Debug\simulate.exe
?????文件??????492716??2015-07-07?10:22??simulate\simulate\Debug\simulate.ilk
?????文件??????945152??2015-07-07?10:22??simulate\simulate\Debug\simulate.pdb
?????文件????????1807??2015-07-07?10:19??simulate\simulate\UpgradeLog.xm
?????目錄???????????0??2015-07-07?10:19??simulate\simulate\_UpgradeReport_Files\
?????文件????????3348??2015-07-07?10:19??simulate\simulate\_UpgradeReport_Files\UpgradeReport.css
?????文件???????12505??2015-07-07?10:19??simulate\simulate\_UpgradeReport_Files\UpgradeReport.xslt
?????文件??????????69??2015-07-07?10:19??simulate\simulate\_UpgradeReport_Files\UpgradeReport_Minus.gif
?????文件??????????71??2015-07-07?10:19??simulate\simulate\_UpgradeReport_Files\UpgradeReport_Plus.gif
?????目錄???????????0??2015-07-07?10:26??simulate\simulate\ipch\
?????目錄???????????0??2015-07-07?10:26??simulate\simulate\ipch\simulate-5a5e3db9\
?????文件????27656192??2015-07-07?10:26??simulate\simulate\ipch\simulate-5a5e3db9\simulate-2bbc8870.ipch
?????目錄???????????0??2015-07-07?10:19??simulate\simulate\simulate\
?????目錄???????????0??2015-07-07?10:22??simulate\simulate\simulate\Debug\
?????文件????????6308??2015-07-07?10:19??simulate\simulate\simulate\Debug\BuildLog.htm
?????文件???????24538??2015-07-07?10:22??simulate\simulate\simulate\Debug\CL.read.1.tlog
?????文件????????1102??2015-07-07?10:22??simulate\simulate\simulate\Debug\CL.write.1.tlog
?????文件??????175397??2015-07-07?10:22??simulate\simulate\simulate\Debug\EventTable.obj
?????文件????????1418??2015-07-07?10:22??simulate\simulate\simulate\Debug\cl.command.1.tlog
?????文件???????????2??2015-07-07?10:22??simulate\simulate\simulate\Debug\li
?????文件???????????2??2015-07-07?10:22??simulate\simulate\simulate\Debug\li
?????文件????????1324??2015-07-07?10:22??simulate\simulate\simulate\Debug\li
?????文件????????3058??2015-07-07?10:22??simulate\simulate\simulate\Debug\li
?????文件?????????674??2015-07-07?10:22??simulate\simulate\simulate\Debug\li
?????文件???????50301??2015-07-07?10:22??simulate\simulate\simulate\Debug\main.obj
?????文件???????????2??2015-07-07?10:19??simulate\simulate\simulate\Debug\mt.command.1.tlog
?????文件??????????63??2015-07-07?10:19??simulate\simulate\simulate\Debug\mt.dep
?????文件???????????2??2015-07-07?10:19??simulate\simulate\simulate\Debug\mt.read.1.tlog
............此處省略29個文件信息
- 上一篇:遙感影像去云處理
- 下一篇:Delaunay三角網生成算法
評論
共有 條評論