⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 一个模拟沃尔玛柜台结账的排队论仿真
💻 CPP
字号:
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include "gen.h"
#include "sev.h"
#include "sched.h"
#include "event.h"
#include "link.h"
#include "para.h"

#define _FILE_
#define MIN_SHOW 15000
#define MAX_SHOW 15000

double max(Stcs** sts)
{
	double tem=sts[0]->varNq;
	for(int i=0;i<MAX_SEV;i++)
	{
		if((sts[i]->varNq)>tem)
			tem=sts[i]->varNq;
	}
	return tem;
}

void main()
{
	Sched sch;

	sch.gen->genEvt();

	for(int i=0;i<MAX_SEV;i++)
		sch.sev[i]->sevEvt();

#ifdef _FILE_
	ofstream of("data.txt");
	ofstream fd("results.txt");
#endif


	Mess* ms=NULL;

	double Tim=0;
/////////////////////////////////
	cout<<"Simulation is runing..."<<endl;
	for(int j=0;j<MAX_EVENTS;j++)
	{
		if(j%1000==0)
			cout<<j<<"th event was happened..."<<endl;
//////////////DEBUG/////////////////

		ms=sch.sch.viewHead();
#ifdef _DEBUG_
		if(j>MIN_SHOW && j<MAX_SHOW)
		{
			cout<<j<<"  ";
			cout<<*(ms);			
		}
#endif
//////////////FILE/////////////////
#ifdef _FILE_
	if(j>STA_POINT)
	{
		of<<j<<"  ";
		of<<*(ms);
	}
#endif
////****************************************
		sch.ProcNxt();
		if(max(sch.sts)<STOP_POINT && j>5000)
		{
			Tim=sch.ms->getTim();
			break;
		}
////****************************************
//////////////DEBUG/////////////////
#ifdef _DEBUG_
	if(j>MIN_SHOW && j<MAX_SHOW)
	{
		cout<<"  LQue[0]: "<<sch.sev[0]->que->getLen();
		cout<<"  LSev[0]: "<<sch.sev[0]->getSta();
		cout<<"  varNq: "<<sch.sts[0]->varNq<<endl;
	}
#endif
//////////////FILE/////////////////
#ifdef _FILE_
	if(j>STA_POINT)
	{
		of<<"  LQue[0]: "<<sch.sev[0]->que->getLen();
		of<<"  LSev[0]: "<<sch.sev[0]->getSta();
		of<<"  Nq: "<<sch.sts[0]->nq;
		of<<"  VarNq: "<<sch.sts[0]->varNq;
		of<<"  Sev[0]Tim: "<<sch.sev[0]->getTim()<<endl;
	}
#endif
	//
	//	st=sch.sts[0]->varNq;
#ifdef _DEBUG_
	if(j>MIN_SHOW && j<MAX_SHOW)
	{
		sch.sch.showList();
		cout<<"sev tim: "<<sch.sev[0]->getTim()<<endl;
	}
#endif
	}
//show arriving and departure
	cout<<"Ending at "<<j<<"th event"<<endl;
	cout<<"Simulation Ended..."<<endl<<endl;
///////////////////////////////////////////////////////////
	cout<<"******Statistic Results*****"<<endl;

	for(i=0;i<MAX_SEV;i++)
	{
		cout<<"VarNq["<<i<<"]="<<sch.sts[i]->varNq<<endl;
	}
	cout<<endl;
	double s_num=0;	
	double s_lbd=0;
	for(i=0;i<MAX_SEV;i++)
	{
		cout<<"Que["<<i<<"]"<<setiosflags(ios::fixed)
			<<setw(8)<<"Lbda="<<setprecision(6)<<(sch.sts[i]->nLda)/Tim		
			<<setw(5)<<"nq="<<sch.sts[i]->nq
			<<setw(5)<<"ns="<<sch.sts[i]->ns
			<<setw(5)<<"n="<<sch.sts[i]->num<<endl
			<<"   Throughput="<<(sch.sts[i]->nMu)/Tim
			<<setw(5)<<"w="<<sch.sts[i]->w
			<<setw(5)<<"s="<<sch.sts[i]->s
			<<setw(5)<<"r="<<sch.sts[i]->rsp<<endl;

		s_num=s_num+sch.sts[i]->num;
		s_lbd=s_lbd+sch.sts[i]->nLda/Tim;

#ifdef _FILE_
		fd<<"Que["<<i<<"]"<<setiosflags(ios::fixed)
			<<setw(8)<<"Lbda="<<setprecision(6)<<(sch.sts[i]->nLda)/Tim		
			<<setw(5)<<"nq="<<sch.sts[i]->nq
			<<setw(5)<<"ns="<<sch.sts[i]->ns
			<<setw(5)<<"n="<<sch.sts[i]->num<<endl
			<<"   Throughput="<<(sch.sts[i]->nMu)/Tim
			<<setw(5)<<"w="<<sch.sts[i]->w
			<<setw(5)<<"s="<<sch.sts[i]->s
			<<setw(5)<<"r="<<sch.sts[i]->rsp<<endl;

#endif

	}
	cout<<endl;
	cout<<"Sum of n: "<<s_num<<endl;
	cout<<"Sum of lambda: "<<s_lbd<<endl;
///////////////////////////////////////////////////////////

#ifdef _DEBUG_
	for(i=0;i<MAX_SEV;i++)
		cout<<sch.gen->cc[i]<<"  ";
	cout<<endl;
#endif

#ifdef _FILE_
	cout<<"Results are in 'result.txt'."<<endl;
	cout<<"Traces are in 'data.txt'."<<endl;
	fd.close();
	of.close();
#endif
	cout<<"Press any key to exit...";		
	cin.get();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -