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