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

📄 cservicearea.cpp

📁 这是cdma2000的一个分组调度算法实例
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//CServiceArea.cpp
//The implemetation of class CServiceArea
//////////////////////////////////////////////////////////

#include "CServiceArea.h"
#include "CDataMs.h"
#include "CCell.h"
#include "CSector.h"
#include "string.h"
//////////////////////////////////////////////////////////
//初始化函数循环初始化化各小区
//completed in 3.22
void CServiceArea::Initialization(int NumOfSlot)
{
	int m,n;
	CELLID_TYPE cellid;
    m_fCellRadius=(float)m_fSiteDistance/(2*(float)cos(PI/6));//基站距离到小区半径的转换。
													 //单位:km
	                                                 //小区半径=基站距离/(2*cos(30度))
	m_iTotalBsOutrage=0;                             //功率超标基站数置零
	m_iNumOfSlotInDrop=NumOfSlot;                    //CNetworkDrive类对象调用CServiceArea的
	                                                  //初始化函数时传入一个DROP内的时隙数  
	for (m=0;m<MM;m++)                                //循环初始化MM*NN个小区 
	{
		for (n=0;n<NN;n++)
		{
            cellid.m=m+1;
			cellid.n=n+1;
			m_aCellArray[m][n].m_stCellID=cellid;            //初始化小区标号         
			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;
			NeighborSet(cellid);                             //初始化相邻集     
            CandidateSet(cellid);                            //初始化候选集
        }
   
}

//根据小区标号获得对应小区	                                               
//completed in 3.20
CCell* CServiceArea::GetCell(CELLID_TYPE id)
{
    return &m_aCellArray[id.m-1][id.n-1]; 
}
//根据扇区标号获得对应扇区	
//completed in 3.20
CSector* CServiceArea::GetSector(SECTORID_TYPE id)
{
   return &m_aCellArray[id.stCellID.m-1][id.stCellID.n-1].m_aSectorInCell[id.s-1];   
}
//小区标号到小区坐标的映射
//completed in 3.20 and had been tested in 3.20
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;
}
//小区坐标到小区标号的映射
//completed in 3.21,and had been tested.
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;
	}

}
//坐标到对应小扇区的映射
//completed and had been tested in 3.21.
SECTORID_TYPE CServiceArea::GetUserCell(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;
}
//确定某小区的相邻集
//completed in 3.21
void CServiceArea::NeighborSet(CELLID_TYPE cellid)	               
{
	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;
		temp[3].n=n+1;
		temp[8].n=n-1;
		temp[12].n=n+2;
	}

	temp[5].m=temp[6].m=temp[14].m=temp[18].m=m-1;
	if(m%2==1)
	{
        temp[5].n=n;
		temp[6].n=n-1;
		temp[14].n=n+1;
		temp[18].n=n-2;
	}
	else
	{
        temp[5].n=n+1;
		temp[6].n=n;
		temp[14].n=n+2;
		temp[18].n=n-1;
	}
    for(int i=0;i<19;i++)
	{
		//存储相邻集小区的实际坐标,不进行小区影射,进行路径损耗和天线增益计算用
		m_aCellArray[m-1][n-1].m_aNeighborCellLocation[i]=GetCor(temp[i]);
		m_aCellArray[m-1][n-1].m_aNeighborCell[i]=GetCell(temp[i]); //由小区标号得到小区指针
	}
} 

//判断两小区是否为相邻小区
//completed in 3.22
bool CServiceArea::IsNeighbor(CELLID_TYPE cellid1, CELLID_TYPE cellid2)
{
	int m1,n1,m2,n2;
	m1=cellid1.m;
	n1=cellid1.n;
	m2=cellid2.m;
	n2=cellid2.n;

	if ( (m2==m1)&&(n2==n1-1) )
		return true;

	if ( (m2==m1)&&(n2==n1+1) )
		return true;

    if ( (m1%2==1)||((-m1)%2==1) )
	{
		if (m2==m1-1)
		{
			if ( (n2==n1-1)||(n2==n1) )
				return true;
		}
		if (m2==m1+1)
		{
			if( (n2==n1)||(n2==n1-1) )
				return true;
		}
	}
	else
	{
		if (m2==m1-1)
		{
			if ( (n2==n1)||(n2==n1+1) )
				return true;
		}
		if (m2==m1+1)
		{
			if ( (n2==n1+1)||(n2==n1) )
				return true;
		}
	}

	return false;
}
          

//确定某小区的候选集
//completed in 3.22
void CServiceArea::CandidateSet(CELLID_TYPE cellid)
{
	
	int k,s;
	SECTORID_TYPE sectorid;
	for (k=0;k<6;k++)                                  //根据定义,对本小区相邻的六个小区进行循环,
	{                                                  //分别找出六个相邻小区内相应扇区指针存入候选集数组
		sectorid.stCellID=GetNeighbor(cellid,k);       //选集数组0至5位,  
		switch(k)                                           
		{                                              //具体算法见《关于服务区环境模型的一些初步设想》  
			case 0: s=1;  break;
			case 1: s=2;  break;
			case 2: s=2;  break;
			case 3: s=3;  break;
			case 4: s=3;  break;
			case 5: s=1;  break;
			default:  ;
		}//end of switch
		sectorid.s=s;
		m_aCellArray[cellid.m-1][cellid.n-1].m_aCandidateSector[k]=GetSector(sectorid);
	}
	sectorid.stCellID=cellid;                      //再将本小区的三个扇区指针存入数组后三位
	for (s=1;s<=3;s++)
	{
		sectorid.s=s;
        m_aCellArray[cellid.m-1][cellid.n-1].m_aCandidateSector[s+5]=GetSector(sectorid);
	}
}
//获得某相邻小区
//completed in 3.22
CELLID_TYPE CServiceArea::GetNeighbor(CELLID_TYPE cellid, int index)
{
	int m,n;
	int m1,n1;
	m=cellid.m;
	n=cellid.n;
	switch(index)                                    
		{     case 0: m1=m;                            
                      n1=n-1;       break;
              case 1: m1=m+1;
	                  if( (m%2==1)||((-m)%2==1) )

⌨️ 快捷键说明

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