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

📄 cservicearea.cpp

📁 此程序为wcdma系统当中ftp/video业务模型的c++程序仿真 通过此程序 能得到此两种业务在多种条件下的吞吐量和无码率的性能
💻 CPP
📖 第 1 页 / 共 3 页
字号:
 ///////////////////////////////////////////////////////////////////
//                             WCDMA TEAM                        //
//                      BUPT Radio Research Center               //
///////////////////////////////////////////////////////////////////
//
//                          CServiceArea.cpp
//
//////////////////////////////////////////////////////////////////////
//                                                                  //
//            服务区环境类CServiceArea的成员函数的声明              //
//                                                                  //
// Written by:     李晶                                             //
// Date:      200404                                                // 
//                                                                  //
//                                                                  //
//////////////////////////////////////////////////////////////////////

#include "CServiceArea.h"
#include "CDataMs.h"
#include "CCell.h"
#include "CSector.h"
#include "string.h"
#include <stdio.h>
//////////////////////////////////////////////////////////////////////////
//TITLE:      Initialization(初始化函数)				        
//
//PARAMETERS:一个Drop所含的时隙数              
//
//PURPOSE AND ALGORITHMS:
//            初始化函数循环初始化各小区的标号、基站坐标、监测集,并调用
//            小区初始化函数,对小区内的3个扇区进行初始化。
//                                               
//AUTHOR:     Li Jing
//
//CALLING FUNCTIONS:
//            CServiceArea::GetCor(CELLID_TYPE CellID)
//            CCell::Initialization()
//
//CALLED FUNCTIONS:
//            CNetworkDrive::DropInitialization()
//
//////////////////////////////////////////////////////////////////////////
void CServiceArea::Initialization(int NumOfSlot, float fDropTime)
{
	for(int i=0;i<MAXNUMBER;i++)
	    m_fSectorAveragePower[i]=0.0;
	m_iArrayPosition=0;

	int m,n;
	CELLID_TYPE cellid;
    m_fCellRadius=m_fSiteDistance/(2*(float)cos(PI/6));
         //基站距离到小区半径的转换。小区半径=基站距离/(2*cos(30度))
	//m_iTotalBsOutrage=0;                             //功率超标基站数置零
	m_iNumOfSlotInDrop=NumOfSlot;                    //CNetworkDrive类对象调用CServiceArea的
	                                                  //初始化函数时传入一个DROP内的时隙数  
    m_fDropTime = fDropTime;
	m_sIntermediateFileName = &"CSeviceAreaIntermediateFile.txt";
#ifdef DEBUG_FTP
	cout<<"The function CServiceArea::Initialization() is being called!\n";
#endif

	for (m=0;m<MM;m++)                               //循环初始化MM*NN个小区 
		for (n=0;n<NN;n++)
		{
                cellid.m=m+1;                                    //小区标号的横向和纵向都是从1开始
			    cellid.n=n+1;
			    m_aCellArray[m][n].m_stCellID=cellid;            //初始化小区标号         

				cout<<"Initializing cell "<<"("<<m+1<<","<<n+1<<")"<<endl;

				m_aCellArray[m][n].m_stCellCor=GetCor(cellid);   //初始化小区基站坐标
				m_aCellArray[m][n].Initialization();             //调用小区初始化函数,对小区内的三个
			                                                 //扇区进行初始化。

		}
    for (m=0;m<MM;m++)
		for(n=0;n<NN;n++)
		{
	            cellid.m=m+1;
			    cellid.n=n+1;
			    MonitorSet(cellid);                              //根据小区标号确定某小区的监测集     
            
        }
   
}






//////////////////////////////////////////////////////////////////////////
//TITLE:      GetCell(获得对应小区函数)				        
//
//PARAMETERS:小区标号              
//
//PURPOSE AND ALGORITHMS:
//            根据小区标号和小区数组得到对应小区的指针
//                                               
//AUTHOR:     Li Jing
//
//CALLING FUNCTIONS:
//            NULL
//
//////////////////////////////////////////////////////////////////////////
CCell* CServiceArea::GetCell(CELLID_TYPE id)
{
    return &m_aCellArray[id.m-1][id.n-1]; 
}



//////////////////////////////////////////////////////////////////////////
//TITLE:      GetSector(获得对应扇区函数)				        
//
//PARAMETERS:扇区标号              
//
//PURPOSE AND ALGORITHMS:
//            根据扇区标号和小区数组得到对应扇区的指针
//                                               
//AUTHOR:     Li Jing
//
//CALLING FUNCTIONS:
//            NULL
//
//////////////////////////////////////////////////////////////////////////
CSector* CServiceArea::GetSector(SECTORID_TYPE id)
{
   return &m_aCellArray[id.stCellID.m-1][id.stCellID.n-1].m_aSectorInCell[id.s-1];   
}



//////////////////////////////////////////////////////////////////////////
//TITLE:      GetCor(获取小区坐标函数)				        
//
//PARAMETERS:小区标号              
//
//PURPOSE AND ALGORITHMS:
//            根据小区标号和小区的地理分布情况得到基站的坐标
//                                               
//AUTHOR:     Li Jing
//
//CALLING FUNCTIONS:
//            
//////////////////////////////////////////////////////////////////////////
LOCATION_TYPE CServiceArea::GetCor(CELLID_TYPE CellID)
{
    int m,n;
    LOCATION_TYPE b;
    m=CellID.m;
    n=CellID.n;
    b.x=(float)((1+((float)m-1)*1.5)*m_fCellRadius);
    if(m%2==1)
            b.y=(float)(1.7320508*(((float)n-1)+0.5)*m_fCellRadius);
    else
            b.y=(float)(1.7320508*(float)n*m_fCellRadius);
    return b;
	
}



//////////////////////////////////////////////////////////////////////////
//TITLE:      GetID(获取小区标号函数)				        
//
//PARAMETERS:小区坐标              
//
//PURPOSE AND ALGORITHMS:
//            根据小区坐标和小区分布的地理情况得到得到小区标号
//                                               
//AUTHOR:     Li Jing
//
//CALLING FUNCTIONS:
//            
//////////////////////////////////////////////////////////////////////////
CELLID_TYPE CServiceArea::GetID(LOCATION_TYPE a)
{
    CELLID_TYPE b;
    int m,n;
    int m1,m2;              // number of the two nearest cell
    int n11,n12,n21,n22;
    float x,y;
    float xx,yy;
    float xx1,xx2;
    float yy11,yy12,yy21,yy22;
    float d1,d2,d3,d4;
    float dmin;
    
    x=a.x;
    y=a.y;
    xx=m_fCellRadius;                   //horizontal coordinate of the first row's cell
    for(m=1;x>xx;m++)
	   xx=(1+(float)m*3/2)*m_fCellRadius;
    m1=m-1;                 //horizontal number(m1,m2) of the two nearest cell
    m2=m;
    xx1=(1+((float)m1-1)*3/2)*m_fCellRadius;   //horizontal coordinate of the two nearest cell
    xx2=xx;
    if((m1%2)==1)           //when m1 is an odd number
    {	yy=(float)(0.8660254*m_fCellRadius);
	    for(n=1;y>yy;n++)
	       yy=(float)(1.7320508*((float)n+0.5)*m_fCellRadius);
    }
    else                   //when m1 is an even
    {   yy=(float)(1.7320508*m_fCellRadius);
	    for(n=1;y>yy;n++)
	       yy=(float)(1.7320508*((float)n+1)*m_fCellRadius);
    }
    n11=n-1;              //vertical coordinate
    n12=n;
    yy11=(float)(yy-1.7320508*m_fCellRadius);
    yy12=yy;

    if(m2%2==1)
    {   yy=(float)(0.8660254*m_fCellRadius);
	    for(n=1;y>yy;n++)
	       yy=(float)(1.7320508*(n+0.5)*m_fCellRadius);
    }
    else
    {   yy=(float)(1.7320508*m_fCellRadius);
	    for(n=1;y>yy;n++)
	       yy=(float)(1.7320508*(n+1)*m_fCellRadius);
    }
    n21=n-1;
    n22=n;
    yy21=(float)(yy-1.7320508*m_fCellRadius);
    yy22=yy;

    d1=(x-xx1)*(x-xx1)+(y-yy11)*(y-yy11);     //find the nearest cell among
    dmin=d1;                                  //the four cell
    d2=(x-xx1)*(x-xx1)+(y-yy12)*(y-yy12);
    if(dmin>d2)
       dmin=d2;
    d3=(x-xx2)*(x-xx2)+(y-yy21)*(y-yy21);
    if(dmin>d3)
	   dmin=d3;
    d4=(x-xx2)*(x-xx2)+(y-yy22)*(y-yy22);
    if(dmin>d4)
	   dmin=d4;
    if(dmin==d1)
    {  b.m=m1;
       b.n=n11;
	   return b;
    }
    else if(dmin==d2)
    {  b.m=m1;
	   b.n=n12;
	   return b;
	}
	else if(dmin==d3)
	{  b.m=m2;
	   b.n=n21;
	   return b;
	}
	else
	{  b.m=m2;
	   b.n=n22;
	   return b;
	}

}




//////////////////////////////////////////////////////////////////////////
//TITLE:      GetUserSector(由移动台坐标获得所属扇区函数)				        
//
//PARAMETERS:移动台坐标              
//
//PURPOSE AND ALGORITHMS:
//            首先调用CServiceArea::GetID函数得到移动台所属小区的标号;
//            再利用移动台、小区基站的连线与x轴的夹角来最终确定移动台
//            在所属小区中对应的扇区标号
//                                               
//AUTHOR:     Li Jing
//
//CALLING FUNCTIONS:
//            CServiceArea::GetID(LOCATION_TYPE)
//            CServiceArea::GetCor(CELLID_TYPE)
//            
//////////////////////////////////////////////////////////////////////////
SECTORID_TYPE CServiceArea::GetUserSector(LOCATION_TYPE location)
{
	CELLID_TYPE cellid;
	SECTORID_TYPE sectorid;
	LOCATION_TYPE loc;
        float angle;
	
	cellid=GetID(location);                  //由移动台地理坐标获得所在小区标号
	sectorid.stCellID=cellid;                
	
	loc=GetCor(cellid);                      //由小区标号计算基站的地理坐标  
        angle=(float)atan2(location.y-loc.y,location.x-loc.x);   //通过移动台、所在小区基站的连线与x轴的夹角
	                                                         //确定移动台所在扇区标号
        if((angle>0)&&(angle<=2*PI/3))           //若夹角在0到2PI/3之间,移动台在一号扇区                 
		sectorid.s=1;          
	else if((angle<=0)&&(angle>-2*PI/3))     //若夹角在0到-2PI/3之间,移动台在三号扇区
		sectorid.s=3;
	else sectorid.s=2;                       //否则移动台在二号扇区
	return sectorid;
}



//////////////////////////////////////////////////////////////////////////
//TITLE:      MonitorSet(确定某小区的监测集)				        
//
//PARAMETERS:小区标号              
//
//PURPOSE AND ALGORITHMS:
//            首先根据监测集的地理部署情况得到7个相邻小区(包括本小区和
//            它周围的6个小区)的小区标号,利用GetCor()函数即可以得到
//            此小区m_aMonitorCellLocation数组;再利用GetSector()函数
//            就可以得到此小区的m_aMonitorSector数组
//                                               
//AUTHOR:     Li Jing
//
//CALLING FUNCTIONS:
//            CServiceArea::GetCor(CELLID_TYPE)
//            CServiceArea::Translation(CELLID_TYPE)
//            CServiceArea::GetSector(SECTORID_TYPE)
//            
//NOTES:     1.CCell.h中,去掉CCell*  m_aNeighborCell[19];
//            LOCATION_TYPE   m_aNeighborCellLocation[19]; 
//            CSector*	 m_aCandidateSector[6+SectorNumber];
//            改为要定义CSector* m_aMonitorSector[7*SectorNumber]及
//            LOCATION_TYPE   m_aMonitorCellLocation[7]
//
//            2.在利用CServiceArea::GetCor(CELLID_TYPE)函数求监测小区的
//            坐标之前,不需要进行小区映射。否则得到的坐标就可能不是和它
//            相邻的小区坐标
//                     
//////////////////////////////////////////////////////////////////////////
//by zl 20050512
void CServiceArea::MonitorSet(CELLID_TYPE cellid)	               
{
	SECTORID_TYPE sectorid;
	CELLID_TYPE temp[19];     
	int m,n;                                        //具体算法详见文档《服务区环境模型-Ⅱ》
	m=cellid.m;                                    
	n=cellid.n;
	
	temp[0].m=m;              
	temp[0].n=n;

	temp[1].m=temp[4].m=temp[7].m=temp[13].m=m;
	temp[1].n=n-1;
    temp[4].n=n+1;
	temp[7].n=n-2;
	temp[13].n=n+2;

	temp[9].m=temp[10].m=temp[11].m=m+2;
	temp[9].n=n-1;
	temp[10].n=n;
	temp[11].n=n+1;

	temp[15].m=temp[16].m=temp[17].m=m-2;
	temp[15].n=n+1;
	temp[16].n=n;
	temp[17].n=n-1;

	temp[2].m=temp[3].m=temp[8].m=temp[12].m=m+1;
	if(m%2==1)
	{
		temp[2].n=n-1;
		temp[3].n=n;
		temp[8].n=n-2;
		temp[12].n=n+1;
	}
	else
	{
        temp[2].n=n;

⌨️ 快捷键说明

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