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

📄 cnetworkdrive.cpp

📁 这是cdma2000的一个分组调度算法实例
💻 CPP
📖 第 1 页 / 共 4 页
字号:
///////////////////////////////////////////////////////////////////////////////
//  CNetworkDrive.cpp         CNetworkDrive 类的实现
///////////////////////////////////////////////////////////////////////////
//
//  建立日期:2001年3月19日上午
//  建立者:  欧阳晖
//
///////////////////////////////////////////////////////////////////////////
//  修改记录:
//
//	2001年3月20日:基本完成本模块设计
//
//	2001年3月21日:增加了一些成员变量:
//		数据采集的drop号、数据采集的时隙号、数据统计用文件个数。
//	以及它们的接口函数。
//		继续编写参数读入的程序段。
//
///////////////////////////////////////////////////////////////////////////////

#include "CNetworkDrive.h"
#include "CChannelModel.h"
#include <afx.h>
#include <string.h>
#include <iostream.h>
#include <crtdbg.h>

float fFastFadingValue_1[SubslotNumber*FastFadingValueLength];
float fFastFadingValue_2[SubslotNumber*FastFadingValueLength];
float fFastFadingValue_3[SubslotNumber*FastFadingValueLength];
float fFastFadingValue_4[SubslotNumber*FastFadingValueLength];
float fFastFadingValue_5[SubslotNumber*FastFadingValueLength];

///////////////////////////////////////////////////////////////////////////
//
//	TITLE:	系统初始化函数
//
//	PURPOSE:初始化本类的各个参数,调用包含的各个类的初始化函数,完成系统
//			初始化。主要工作是从数据文件中读入参数
//
//	SAMPLE CALL:
//			CNetworkDrive mysystem;
//			mysystem.SystemInitialization()
//
//	CALLED BY FUNCTIONS:
//			CNetworkDrive::SimulationRun()
//
//	CALLING FUNCTIONS:
//			CServiceArea::Initialization()
//			CMsManager::Initialization()
//			CLinkPrediction::Initialization()
//
//	AUTHOR:	Ouyang Hui
//
//	DATE:	01/04/04
//
//	MODIFICATIONS SINCE 01/04/04:
//			01/05/17	move m_ServiceArea.Initialization() to DropInitialization() 
//			01/05/18	modify the arguments of m_MsManager.Initialization()
//////////////////////////////////////////////////////////////////////////
	
void CNetworkDrive::SystemInitialization()
{
	ReadData();		//Read data from the parameter file

	//////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////

	Random R;		//initialize the random numbers
	R.Set(0.6616);

	//initialize the class CMsManager
	m_MsManager.Initialization(m_iSlotNum,SlotSize,
		m_fTimePerDrop,&(m_LinkPrediction));
	
	//initialize the class CLinkPrediction
	m_LinkPrediction.Initialization();
}

/////////////////////////////////////////////////////////////////////////////
//
//	TITLE:	Reading-data Function
//
//	PURPOSE:Read data from the parameter file (testdata.txt).
//
//	CALLED BY FUNCITONS:
//			CNetworkDrive::SystemInitialization()
//
//	CALLING FUNCTIONS:
//			CNetworkDrive::ReadData_Simulation()
//			CNetworkDrive::ReadData_ServiceArea()
//			CNetworkDrive::ReadData_ChannelModel()
//			CNetworkDrive::ReadData_VoiceMs()
//			CNetworkDrive::ReadData_DataMs()
//			CNetworkDrive::ReadData_HttpMs()
//			CNetworkDrive::ReadData_Handoff()
//			CNetworkDrive::ReadData_Statics()
//
//	AUTHOR:	Ouyang Hui
//
//	DATE:	01/04/04
//
//	MODIFICTIONS SINCE 01/04/04:
//			01/04/06 Ouyang Hui
//				Move the parts of reading data into their correspondent 
//				functions.
//
/////////////////////////////////////////////////////////////////////////////

void CNetworkDrive::ReadData()
{
	////////////////////////////////////////////////////////////////////
	//仿真程序参数的读入
	ReadData_Simulation();
	
	////////////////////////////////////////////////////////////////////
	//服务区环境参数的读入
	ReadData_ServiceArea();

	//////////////////////////////////////////////////////////////////////
	//链路模型参数读入
	ReadData_ChannelModel();
	
	//////////////////////////////////////////////////////////////////////
	//话音移动台参数的读入
	ReadData_VoiceMs();
	
	//////////////////////////////////////////////////////////////////////
	//数据业务移动台参数的读入
	ReadData_DataMs();
	
	//////////////////////////////////////////////////////////////////////
	//HTTP移动台参数的读入
	ReadData_HttpMs();
	
	//////////////////////////////////////////////////////////////////
	//软切换与小区交换参数的读入
	ReadData_Handoff();
	
	//////////////////////////////////////////////////////////////////
	//数据统计参数读入
	ReadData_Statics();
    //快衰落值参数读入
	ReadData_FastFadingValue();

	CheckTheInputs();
	
}

/////////////////////////////////////////////////////////////////////////
//
//	TITLE:	Functions Reading Data
//
//	PURPOSE:Reading Simulation's parameter from the data file
//
//	CALLED BY FUNCTIONS:
//			CNetworkDrive::ReadData()
//
//	COMMENTS:
//			The format of this part of data in the file is:
//			<begin>
//			1.仿真程序参数
//			仿真的drop数 = 10
//			每drop内的时间长度 = 5 (s)
//			每扇区的话音用户数 = 1
//			每扇区的分组用户数 = 2
//			分组用户中的HTTP用户比例 = 0.5
//			分组用户中的FTP用户比例 = 0.5
//			<end>
//
//			Notes:
//			1.The first line should contain the specific string, (Here is
//			"仿真程序参数").
//			2.On the left of '=' there must be the parameter name, which
//			should be typed exactly regardless of blank and tab.
//			3.On the right of '=' there must be the value of the parameter.
//			And between '=' and the figure there should be no other characters
//			than blank and tab.
//			4.The order of parameters should not be changed. And none of
//			them can be omitted.
//			5.You can insert some lines without '=' for comments. You can
//			also add strings after the figures which indicate some information
//			like unit.
//
//	AUTHOR:	Ouyang Hui
//
//	DATE:	01/04/06
//
//	MODIFICTIONS SINCE 01/04/06
//
/////////////////////////////////////////////////////////////////////////
void CNetworkDrive::ReadData_Simulation()
{

	int NUM_VALUE;
	const char* cSpecificString;
	bool bFlag;
	char* pname[15];
		
	double pval[15];
	CStdioFile f1;		//定义一个I/O文件对象
	CString s1,s2,s3;		//定义三个字符串对象
	double x;
	int i,j,k,iEqualPos;
	char* q;
	char buf[100];	//定义一个数据缓冲区,用于存放一行字符串

//	cout<<ParameterFile<<endl;
	
	/* 打开数据文件准备读*/
	if(!f1.Open(ParameterFile,CFile::modeRead))
	{
	#ifdef _DEBUG
		afxDump<<"Unable to open file"<<"\n";	//异常处理
	#endif
	}

	pname[0]="仿真的drop数";
	pname[1]="每drop内的时间长度";
	pname[2]="每扇区的话音用户数";
	pname[3]="每扇区的分组用户数";
	pname[4]="分组用户中的HTTP用户比例";
	pname[5]="分组用户中的FTP用户比例";

	i=0;NUM_VALUE=6;
	cSpecificString="仿真程序参数";
	bFlag=FALSE;
	
	while(f1.ReadString(buf,100)!=NULL)
	{
		s1=buf; //把这一行字符串内容赋给对象s1
		if (s1.Find(cSpecificString)>=0) 
		{
			bFlag=TRUE;
			break;
		}
	}

	if (!bFlag)
	{
		cerr<<"Cannot find the specific string "<<cSpecificString<<endl;
		f1.Close();
		exit(0);
	}

	/*从数据文件依次读入每一行字符串,对每一行字符串进行处理*/
	while(f1.ReadString(buf,100)!=NULL)
	{
		if (i>=NUM_VALUE)
			break;

		s1=buf; //把这一行字符串内容赋给对象s1

		iEqualPos=s1.Find("=");
		if (iEqualPos<0)
			continue;

		s2=s1.Left(iEqualPos);
		s3=s1.Right(s1.GetLength()-iEqualPos-1);

		j=0;
		k=iEqualPos-1;
		while ((s2[j]==' ')||(s2[j]=='\t')) j++;
		while ((s2[k]==' ')||(s2[k]=='\t')) k--;
		s2=s2.Mid(j,k-j+1);

		if (s2!=pname[i]) 
		{
			cerr<<"Unexpected parameter name  "<<s2<<"."<<endl
				<<"Should be "<<pname[i]<<endl;
			f1.Close();
			exit(0);
		}

		x=strtod(s3,&q);

		pval[i]=x;
		i++;
	}

	m_iDropNum=(int)pval[0];
	m_fTimePerDrop=(float)pval[1];
	m_iSlotNum=(int)(pval[1]*1000/SlotSize);
	m_MsManager.SetVoiceNumPerSector((int)pval[2]);
	m_MsManager.SetDataNumPerSector((int)pval[3]);
	m_MsManager.SetFractionHttp((float)pval[4]);
	m_MsManager.SetFractionFtp((float)pval[5]);
	
	f1.Close();//关闭参数文件

}

/////////////////////////////////////////////////////////////////////////
//
//	TITLE:	Functions Reading parameters
//
//	PURPOSE:Read the service area's parameters from the data file
//
//	CALLED BY FUNCTIONS:
//			CNetworkDrive::ReadData()
//
//	COMMENTS:
//			The format of this part of data in the file is:
//			<begin>
//			2.服务区环境参数
//			基站间间隔 = 2 (km)
//			BTS的最大发射功率 = 43 (dBm)
//			分组数据信道的最大功率比例 = 0.7
//			前向信道的正交因子 = 0.4
//			<end>
//
//			Notes:
//			1.The first line should contain the specific string, (Here is
//			"服务区环境参数").
//			2.On the left of '=' there must be the parameter name, which
//			should be typed exactly regardless of blank and tab.
//			3.On the right of '=' there must be the value of the parameter.
//			And between '=' and the figure there should be no other characters
//			than blank and tab.
//			4.The order of parameters should not be changed. And none of
//			them can be omitted.
//			5.You can insert some lines without '=' for comments. You can
//			also add strings after the figures which indicate some information
//			like unit.
//
//	AUTHOR:	Ouyang Hui
//
//	DATE:	01/04/06
//
//	MODIFICTIONS SINCE 01/04/06
//
/////////////////////////////////////////////////////////////////////////
void CNetworkDrive::ReadData_ServiceArea()
{
	int NUM_VALUE;
	const char* cSpecificString;
	bool bFlag;
	char* pname[15];
		
	double pval[15];
	CStdioFile f1;		//定义一个I/O文件对象
	CString s1,s2,s3;		//定义三个字符串对象
	double x;
	int i,j,k,iEqualPos;
	char* q;
	char buf[100];	//定义一个数据缓冲区,用于存放一行字符串

	/* 打开数据文件准备读*/
	if(!f1.Open(ParameterFile,CFile::modeRead))
	{
	#ifdef _DEBUG
		afxDump<<"Unable to open file"<<"\n";	//异常处理
	#endif
	}

	pname[0]="基站间间隔";
	pname[1]="BTS的最大发射功率";
	pname[2]="分组数据信道的最大功率比例";
	pname[3]="前向信道的正交因子";

	i=0;NUM_VALUE=4;
	cSpecificString="服务区环境参数";
	bFlag=FALSE;

	while(f1.ReadString(buf,100)!=NULL)
	{
		s1=buf; //把这一行字符串内容赋给对象s1
		if (s1.Find(cSpecificString)>=0) 
		{
			bFlag=TRUE;
			break;
		}
	}

	if (!bFlag)
	{
		cerr<<"Cannot find the specific string "<<cSpecificString<<endl;
		f1.Close();
		exit(0);
	}

	/*从数据文件依次读入每一行字符串,对每一行字符串进行处理*/
	while(f1.ReadString(buf,100)!=NULL)
	{
		if (i>=NUM_VALUE)
			break;

		s1=buf; //把这一行字符串内容赋给对象s1

		iEqualPos=s1.Find("=");
		if (iEqualPos<0)
			continue;

		s2=s1.Left(iEqualPos);
		s3=s1.Right(s1.GetLength()-iEqualPos-1);

		j=0;
		k=iEqualPos-1;
		while ((s2[j]==' ')||(s2[j]=='\t')) j++;
		while ((s2[k]==' ')||(s2[k]=='\t')) k--;
		s2=s2.Mid(j,k-j+1);

		if (s2!=pname[i]) 
		{
			cerr<<"Unexpected parameter name  "<<s2<<"."<<endl
				<<"Should be "<<pname[i]<<endl;
			f1.Close();
			exit(0);
		}

		x=strtod(s3,&q);

		pval[i]=x;
		i++;
	}

	m_ServiceArea.SetSiteDistance((float)pval[0]);
	m_ServiceArea.SetOrthogonalFactor((float)pval[3]);
	float ptemp=(float)pow(10,(float)pval[1]/10.);
	ptemp=(float)(ptemp*(float)pval[2]);
	for (int ii=0;ii<MM;ii++)
		for (int jj=0;jj<NN;jj++)
			for (int kk=0;kk<SectorNumber;kk++)
			{
				SECTORID_TYPE id;
				id.stCellID.m=ii+1;
				id.stCellID.n=jj+1;
				id.s=kk+1;
				m_ServiceArea.GetSector(id)
					->SetMaxPower((float)pow(10,pval[1]/10.0));
				m_ServiceArea.GetSector(id)->SetMaxPacketPower(ptemp);
			}
			
	f1.Close();
}

/////////////////////////////////////////////////////////////////////////
//
//	TITLE:	Function of Reading Parameters
//
//	PURPOSE:Reading channel model's parameters from the data file.
//
//	CALLED BY FUNCTIONS:
//			CNetworkDrive::ReadData()
//
//	COMMENTS:
//			The format of this part of data in the file is:
//			<begin>
//			3.链路模型参数
//			<begin>
//			慢衰的标准差 = 8.9 (dB)
//			信道类型的数量 = 5
//			每种信道类型所占的比例 = 0.30 (Pedestrian A, 1 Finger, 3 kmph)
//									 0.30 (Pedestrian B, 3 Fingers, 10 kmph)
//									 0.20 (Vehicular A, 2 Fingers, 30 kmph)

⌨️ 快捷键说明

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