第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

對事件驅(qū)動模擬器進(jìn)行改進(jìn),求解!謝謝(下面的程序在vc已經(jīng)運行成功)

對事件驅(qū)動模擬器進(jìn)行改進(jìn),求解!謝謝(下面的程序在vc已經(jīng)運行成功)

C C++
Lydia_Lv 2016-06-21 08:50:10
需要添加:一個客戶從某窗口離開,有其他窗口的比該窗口的人數(shù)多2,那么從其他窗口隊列中,有一個客戶從隊尾離開,排到該窗口。(希望詳細(xì)一些)//main.cpp#include"simulation.h"int main(){ Simulation S; S.RunSimulation(); S.PrintSimulationResults(); return 0;}//simulation.h#ifndef Simulation_H?#define Simulation_H?#include"pqueue.h" //優(yōu)先級隊列類模板#include"queue.h" //隊列類模板#include<conio.h>#include<iostream.h>#include <stdlib.h>?#include <iomanip.h>class Event //事件類型 { int time; //事件發(fā)生時間 int etype; //事件類型:0表示到達(dá),1、2、3、4……表示從幾號窗口離開public: Event():time(0),etype(0){} Event(int t,int e):time(t),etype(e){} operator int()const{return(time);} int GetTime()const{return(time);} int GetEventType()const{return(etype);}};struct Service //排隊客戶信息結(jié)構(gòu){ int arrivalTime; int serviceTime;};struct TellerStats //窗口信息結(jié)構(gòu){ int totalCustomer; int totalService; int totalWait;};class Simulation{ int SimulationLength; //模擬時間長度 int numTellers; //服務(wù)窗口個數(shù) int arrivalLow; //客戶到達(dá)的最短間隔 int arrivalHigh; //客戶到達(dá)的最長間隔 int serviceLow; //客戶最短的服務(wù)時間 int serviceHigh; //客戶最長的服務(wù)時間 TellerStats t[11]; //最多是個窗口,TellerStats t[1]~TellerStats t[10] Queue<Service>Q[11]; PQueue<Event>PQ; int GetIntertime() {return(arrivalLow+rand()%(arrivalHigh-arrivalLow+1));} int GetServiceTime() {return(serviceLow+rand()%(serviceHigh-serviceLow+1));} int GetNextTeller();//(1)選擇人少的排隊 void Arrived(const Event&e); void Daparture(const Event&e); void PrintPQueue(); void PrintQueue();public: Simulation(); Simulation(int L,int nT,int aL,int aH,int sL,int sH); void RunSimulation(); void PrintSimulationResults();};Simulation::Simulation() //模擬過程的初始化{ cout<<"input the simulation time in minutes:"; cin>>SimulationLength; cout<<"input the number of tellers(2-10):"; cin>>numTellers; cout<<"input the range of arrival times in minutes:"; cin>>arrivalLow>>arrivalHigh; cout<<"input the range of service times in minutes:"; cin>>serviceLow>>serviceHigh; for(int i=1;i<=numTellers;i++) { t[i].totalCustomer=0; t[i].totalService=0; t[i].totalWait=0; } PQ.Push(Event(0,0));}Simulation::Simulation(int L,int nT,int aL,int aH,int sL,int sH){ SimulationLength=L; numTellers=nT; arrivalLow=aL; arrivalHigh=aH; serviceLow=sL; serviceHigh=sH; for(int i=1;i<=numTellers;++i) { t[i].totalCustomer=0; t[i].totalService=0; t[i].totalWait=0; } PQ.Push(Event(0,0));}int Simulation::GetNextTeller()//(1)選擇人少的排隊{ int i,size=Q[1].size(),min=1; for(i=2;i<=numTellers;i++) if(Q[i].size()<size) { size=Q[i].size(); min=i; } return min;}void Simulation::Arrived(const Event&e){ Service s; int next,i; s.arrivalTime=e.GetTime(); s.serviceTime=GetServiceTime(); i=GetNextTeller(); Q[i].Push(s); if(Q[i].size()==1) PQ.Push(Event(s.arrivalTime+s.serviceTime,i)); next=e.GetTime()+GetIntertime(); if(next<SimulationLength) PQ.Push(Event(next,0)); cout<<"ServiceTime NextTeller next\n"; cout<<setw(5)<<s.serviceTime; cout<<setw(12)<<i; cout<<setw(8)<<next<<endl;}void Simulation::Daparture(const Event&e){ int i=e.GetEventType(); Service s=Q[i].Pop(); t[i].totalCustomer++; t[i].totalService+=s.serviceTime; t[i].totalWait+=e.GetTime()-s.arrivalTime; if(!Q[i].Empty()) { s=Q[i].Front(); PQ.Push(Event(e.GetTime()+s.serviceTime,i)); }}void Simulation::PrintPQueue(){ int n=PQ.Size(); int i=0; Event e,*p=new Event[n]; cout<<"*****EventQueue*****\n"; while(!PQ.Empty()) { e=PQ.Pop(); cout<<'('<<e.GetTime()<<" "<<e.GetEventType()<<')'; p[i++]=e; } for(i=0;i<n;++i) PQ.Push(p[i]); cout<<endl; delete[]p;}void Simulation::PrintQueue() //顯示窗口隊列{ int n; Service s; cout<<"*****Tellers*****\n"; for(int t=1;t<=numTellers;t++) { cout<<t<<":"; n=Q[t].size(); for(int i=1;i<=n;i++) { s=Q[t].Pop(); cout<<'('<<s.arrivalTime<<" "<<s.serviceTime<<')'; Q[t].Push(s); } cout<<endl; }}void Simulation::RunSimulation() //執(zhí)行模擬{ Event e; PrintPQueue(); PrintQueue(); cout<<endl; getch(); while(!PQ.Empty()) { e=PQ.Pop(); if(e.GetEventType()==0) { Arrived(e); PrintPQueue(); PrintQueue(); cout<<endl; } else { Daparture(e); PrintPQueue(); PrintQueue(); cout<<endl; } getch(); }}void Simulation::PrintSimulationResults() //顯示模擬結(jié)果{ int i,totalCustomers=0,totalWait=0; for(i=1;i<=numTellers;i++) { totalCustomers+=t[i].totalCustomer; totalWait+=t[i].totalWait; } cout<<totalCustomers<<endl; cout<<totalWait<<endl;}#endif
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關(guān)注
  • 1682 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號