Example #1
0
bool GeoAlgorithms::getAngleToNorth(const RasterElement* pRaster, double& angle, LocationType pixelStart)
{
   if (pRaster == NULL || !pRaster->isGeoreferenced())
   {
      return false;
   }

   const RasterDataDescriptor* pDescriptor = static_cast<const RasterDataDescriptor*>(pRaster->getDataDescriptor());
   if (pDescriptor != NULL)
   {
      if (pixelStart.mY > pDescriptor->getRowCount() - 1)
      {
         pixelStart.mY = pDescriptor->getRowCount() - 1;
      }
      else if (pixelStart.mY < 0.0)
      {
         pixelStart.mY = 0.0;
      }
      if (pixelStart.mX > pDescriptor->getColumnCount() - 1)
      {
         pixelStart.mX = pDescriptor->getColumnCount() - 1;
      }
      else if (pixelStart.mX < 0.0)
      {
         pixelStart.mX = 0.0;
      }
   }

   LocationType geocoordStart = pRaster->convertPixelToGeocoord(pixelStart);
   // The amount of separation in Latitude needs to be great enough that geoToPixel
   // in the respective georeference methods returns a distance that produces a 
   // reliable angle. Here we picked 10 degrees but any sufficiently large value will do.
   double degLatDelta = 10.0;

   LocationType geocoordEnd = LocationType(geocoordStart.mX + degLatDelta, geocoordStart.mY);
   LocationType pixelEnd = pRaster->convertGeocoordToPixel(geocoordEnd);

   double dDeltaX = pixelEnd.mX - pixelStart.mX;
   double dDeltaY = pixelEnd.mY - pixelStart.mY;
   if (dDeltaX == 0.0)
   {
      return false;
   }

   // atan2 uses positive x as 0 degrees and we want positive y so offset by PI/2 radians = 90 degrees
   angle = 90 + GeoConversions::convertRadToDeg(atan2(dDeltaY, dDeltaX));
   return true;
}
//-------------------------------------------------------
main() {
 int Gbs_x=map_x/Rbs; // Number of grids on y=1
 int Gbs_y=map_y/Rbs; // Number of grids on x=1
 int Nbs_x1=floor(Gbs_x/2);	//Number og BSs on y=1
 int Nbs_x2=floor(((map_x-Rbs)/Rbs)/2);	//Number og BSs on y=2
 int Nbs_y1=floor(Gbs_y/2);	//Number og BSs on x=1
 int Nbs_y2=floor(((map_y-Rbs)/Rbs)/2);	//Number og BSs on x=2
 int Tbs=(Nbs_x1*Nbs_y1)+(Nbs_x2*Nbs_y2);	//Total BS on map
 int length=Rbs/space;	//real length
 int Px=map_x/space;	//number of points on x-axis
 int Py=map_y/space;	//number of points on y-axis
 double TN;	//Thermal Noise
 int i,j;

 ptrD=&D[0][0];
 ptrBR=&BR[0];
 ptrModulation=&Modulation[0];
 ptrSensitivity=&Sensitivity[0];
 ptrDP=&DP[0];
 ptrSNR=&SNR[0];
 ptrBPL=&BPL[0];
 ptrLT=&LT[0];
 ptrDS=&DS[0];
 ptrPLT=&PathLossType[0][0];
 ptrPL=&PL[0][0];
 //ptrP=&P[0][0];
//printf("\n%d\n",Nbs_x1);printf("\n%d\n",Nbs_x2);printf("\n%d\n",Nbs_y1);printf("\n%d\n",Nbs_y2);printf("\n%d\n",Tbs);

 //for(counter=0;counter<_t;counter++)
	 //totalr+=R[counter];//totalr = 4+6+8+5+2


 //checkInputs();
 fillCoordinatesBSs(Xbs,Ybs,Gbs_x,Gbs_y,Nbs_x1,Nbs_x2,Nbs_y1,Nbs_y2,length); 
 /*for(i=1;i<=Tbs;i++)
	 printf("Xbs[%d],Ybs[%d]=(%d,%d)\n",i,i,Xbs[i],Ybs[i]);
 printf("\n");*/
 fillCoordinatesTPs(Xtp,Ytp,Px,Py,Tbs,Xbs,Ybs);
 /*for(i=1;i<=Ntp;i++)
	 printf("Xtp[%d],Ytp[%d]=(%d,%d)\n",i,i,Xtp[i],Ytp[i]);*/
 fillDistance(Xbs,Ybs,Xtp,Ytp,ptrD,Tbs);
 printf("\n");
/*for(i=1;i<=Tbs;i++)
	for(j=1;j<=Ntp;j++)
		printf("D[%d][%d]=%.2lf\n",i,j,D[i][j]);
printf("\n");	*/
 fillMs(ptrBR);
/* for(i=1;i<=Ntp;i++)
	 printf("BR[%d]:%.2lf Mbps\n",i,BR[i]);
 printf("\n");*/
 TN=ThermalNoise();
 //printf("%.2lf\n",TN);
 //printf("\n");
 modulation(TN,ptrBR,Modulation,Sensitivity,DP,SNR);
 //for(i=1;i<=Ntp;i++)
//	 printf("TP[%d] with modulation %d, DP: %.2lf, SNR: %.2lf, S: %.2lf\n",i,Modulation[i],DP[i],SNR[i],Sensitivity[i]);
 //printf("\n");
 LocationType(ptrLT,Xtp,Ytp);
 bpl(ptrLT,ptrBPL);
 //for(i=1;i<=Ntp;i++)
//	 printf("TP[%d]'s location type is %d, bpl is %d\n",i,LT[i],BPL[i]);
 DataSubcarriers(ptrDS,ptrBR,ptrDP);
 //printf("\n");
 //for(i=1;i<=Ntp;i++)
//	 printf("data subcarriers for TP[%d]:%d\n",i,DS[i]);
// printf("\n");
 
 PathLoss(ptrD,ptrPLT,ptrLT,Tbs,ptrPL);
power(Tbs,TN);
FixedCellSize(Tbs,DS,ptrD,P[0],ptrBR,Xbs,Ybs,Xtp,Ytp);

FILE *PowerSavingCPLEX;
if((PowerSavingCPLEX=fopen("PowerSavingCPLEX","w"))==NULL)
	printf("\nerror!Fail to open file!");
else
	printf("\nOpen PowerSavingCPLEX successfully!\n");
fprintf(PowerSavingCPLEX,"This is the input to CPLEX for power saving model.\n");
 objective(Tbs,PowerSavingCPLEX);
fprintf(PowerSavingCPLEX,"st\n");
 printf("st\n");
 constraint1(Tbs,ptrDS,PowerSavingCPLEX);
 constraint2(Tbs,PowerSavingCPLEX);
 constraint3(Tbs,PowerSavingCPLEX);
 constraint4(Tbs,PowerSavingCPLEX);
 constraint5(Tbs,PowerSavingCPLEX);
 //constraint5(nr,nt,totalr);
 constraint6(Tbs,PowerSavingCPLEX);
 constraint7(Tbs);
 constraint8(Tbs);
 constraint9(Tbs);
fprintf(PowerSavingCPLEX,"bounds\n");
 printf("bounds\n");
 bounds(Tbs,PowerSavingCPLEX);

 specifyTypes(Tbs,PowerSavingCPLEX);
fprintf(PowerSavingCPLEX,"end\n");
 printf("end\n");
fclose(PowerSavingCPLEX);
 checkMSsites(Tbs);
	heuristic(Tbs,P[0],Ntp,MP,DSt,BP,DS,Xbs,Ybs,Xtp,Ytp,ptrD,BR);
	printf("===================================================================================================================================\n");
	Sheuristic(Tbs,P[0],Ntp,MP,DSt,BP,DS,Xbs,Ybs,Xtp,Ytp,ptrD,BR); 

FILE *outfile, *outfile1;
 if ((outfile=fopen("outfile1.txt", "w")) == NULL)
printf("\n\nerror!Fail to open file!");
else
printf("\n\nOpen file successfully!\n");
fprintf(outfile,"BS%dMS%dBP%g\n",Tbs,Ntp,BP);
for(i=1;i<=Tbs;i++)
for(j=1;j<=Ntp;j++)
	fprintf(outfile,"%d. BS[%d]=%d,%d MS[%d]=%d,%d DS=%d power=%g mW BW=%g Mbps\n",(i-1)*Ntp+j,i,Xbs[i],Ybs[i],j,Xtp[j],Ytp[j],DS[j],P[i][j],BR[j]);
fclose(outfile);

if ((outfile1=fopen("coordinates.txt", "w")) == NULL)
printf("\n\nerror!Fail to open file!");
else
printf("\n\nOpen coordinates.txt successfully!\n");

fprintf(outfile1,"#BS%dMS%dBP%g\n",Tbs,Ntp,BP);
for(i=1;i<=Tbs;i++){
for(j=1;j<=Ntp;j++)
fprintf(outfile1,"%d. BS[%d] %d %d MS[%d] %d %d DS %d power %g mW BW %g Mbps\n",(i-1)*Ntp+j,i,Xbs[i],Ybs[i],j,Xtp[j],Ytp[j],DS[j],P[i][j],BR[j]);
}
fprintf(outfile1,"\n\n");
for(i=1;i<=Tbs;i++)
fprintf(outfile1," BS[%d]=%d,%d \n",i,Xbs[i],Ybs[i]);

fclose(outfile1);
 //system("pause");
 return;
}