?? cnetworkdrive.cpp
字號:
///////////////////////////////////////////////////////////////////////////////
// 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 + -