#include <stdio.h>
#include <string>
#include <iostream>
#include <cstring>
#include "monte_carlo_5g.h"
#ifndef API_DATA_FOLDER
#define API_DATA_FOLDER "../../api/winprop/data/"
#endif // !API_DATA_FOLDER
#define SERVICES_5G 7
#define MAX_CELLS 3
void AntennaPropertiesSet(
WinProp_Antenna* Antenna,
double CoordinateX,
double CoordinateY,
double Height,
double Frequency,
const char* Name,
double Power,
WINPROP_POWER_MODE PowerMode,
WINPROP_MODEL_INDOOR Model,
double Azimuth,
double Downtilt,
int Id)
{
Antenna->Longitude_X = CoordinateX;
Antenna->Latitude_Y = CoordinateY;
Antenna->Height = Height;
Antenna->Power = Power;
Antenna->PowerMode = PowerMode;
Antenna->Frequency = Frequency;
sprintf(Antenna->Name, "%s", Name);
Antenna->Model = Model;
Antenna->Azimuth = Azimuth;
Antenna->Downtilt = Downtilt;
Antenna->Id = Id;
}
int main(int argc, char** argv)
{
WinProp_ParaMain GeneralParameters;
WinProp_Pattern WinPropPattern;
WinProp_Antenna Antenna[MAX_CELLS];
WinProp_Carrier Carrier[MAX_CELLS];
WinProp_Propagation_Results OutputResults;
WinProp_Result PropResults[MAX_CELLS];
int ProjectHandle = 0, Error = 0;
int ParaValueInt = 0;
double ParaValueDouble = 0.;
int NrPredictionHeights = 1;
double PredictionHeights[1] = {1.5};
WinProp_Structure_Init_ParameterMain(&GeneralParameters);
WinProp_Structure_Init_Pattern(&WinPropPattern);
WinProp_Structure_Init_Propagation_Results(&OutputResults);
for (int cell = 0; cell < MAX_CELLS; cell++)
{
WinProp_Structure_Init_Antenna(&Antenna[cell]);
WinProp_Structure_Init_Carrier(&Carrier[cell]);
WinProp_Structure_Init_Result(&PropResults[cell]);
}
const char* my_odb_database = API_DATA_FOLDER "outdoor/Frankfurt";
GeneralParameters.ScenarioMode = SCENARIOMODE_URBAN;
GeneralParameters.PredictionModelUrban = PREDMODEL_UDP;
GeneralParameters.UrbanLowerLeftX = 475080.0;
GeneralParameters.UrbanLowerLeftY = 551860.0;
GeneralParameters.UrbanUpperRightX = 476840.0;
GeneralParameters.UrbanUpperRightY = 553200.0;
GeneralParameters.RuralLowerLeftX = GeneralParameters.UrbanLowerLeftX;
GeneralParameters.RuralLowerLeftY = GeneralParameters.UrbanLowerLeftY;
GeneralParameters.RuralUpperRightX = GeneralParameters.UrbanUpperRightX;
GeneralParameters.RuralUpperRightY = GeneralParameters.UrbanUpperRightY;
GeneralParameters.Resolution = 10.0;
GeneralParameters.NrLayers = NrPredictionHeights;
GeneralParameters.PredictionHeights = PredictionHeights;
GeneralParameters.BuildingsMode = BUILDINGSMODE_BINARY;
sprintf(GeneralParameters.BuildingsName, "%s", my_odb_database);
WinPropPattern.Mode = PATTERN_MODE_FILE;
sprintf(WinPropPattern.Filename, "%s", API_DATA_FOLDER "antennas/Beams2Control4Data.ffe");
GeneralParameters.OutputResults = &OutputResults;
sprintf(OutputResults.ResultPath, "%s", API_DATA_FOLDER "output/monte_carlo_5g");
OutputResults.FieldStrength = 1;
OutputResults.PathLoss = 1;
if (Error == 0)
{
Error = WinProp_Net_Project_Open(&ProjectHandle, NET_AIRINTERFACE_5G_FDD_GENERIC, NULL);
}
if (Error == 0)
{
char ProjectName[200];
sprintf(ProjectName, "%s", "MonteCarlo-5G");
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_PROJECTNAME, NULL, NULL, ProjectName);
}
if (Error == 0)
{
double FrequencyUL = 0.;
double FrequencyDL = 0.;
double CarrierSeparation = 20.;
for (int CurrentCarrier = 0; CurrentCarrier < 3; CurrentCarrier++)
{
FrequencyUL = 1930.0 + (CurrentCarrier * CarrierSeparation);
FrequencyDL = 2120.0 + (CurrentCarrier * CarrierSeparation);
Error = WinProp_Net_Carrier_Add(ProjectHandle, CurrentCarrier + 1);
Error = WinProp_Net_Carrier_Para_Set(
ProjectHandle, CurrentCarrier + 1, NET_PARA_CARRIER_FREQ_DL, &FrequencyDL, NULL, NULL);
Error = WinProp_Net_Carrier_Para_Set(
ProjectHandle, CurrentCarrier + 1, NET_PARA_CARRIER_FREQ_UL, &FrequencyUL, NULL, NULL);
}
}
if (Error == 0)
{
int NrCarriers = 0;
Error = WinProp_Net_Project_Para_Get(ProjectHandle, NET_PARA_CARRIERS, NULL, &NrCarriers, NULL);
if (Error == 0)
{
if (NrCarriers != 3)
Error = 1;
}
}
char AntennaName[MAX_CELLS][500] = { "Ant 3", "Ant 2", "Ant 1" };
double SiteX = 475500.;
double SiteY = 552897.;
double SiteZ = 12.;
double Power = 40.;
double Azmith[MAX_CELLS] = { 240., 120., 0. };
double Frequency[MAX_CELLS] = { 2160., 2140., 2120. };
double Downtilt = 0.;
int AntennaCarrier[MAX_CELLS] = { 3, 2, 1 };
if (Error == 0)
{
for (int cell = 0; cell < MAX_CELLS; cell++)
{
AntennaPropertiesSet(
&Antenna[cell], SiteX, SiteY, SiteZ, Frequency[cell], AntennaName[cell],
Power, WINPROP_POWER_OUTPUT, WINPROP_MODEL_DPM, Azmith[cell], Downtilt, cell + 1);
Carrier[cell].CarrierID = AntennaCarrier[cell];
Carrier[cell].NrAntennaBeams = 2;
CarrierPropertiesSet(&Antenna[cell], &Carrier[cell]);
}
}
if (Error == 0)
{
const char* TransmissionMode_Name[SERVICES_5G] = {
"00 - QPSK - R 120",
"04 - QPSK - R 602",
"08 - 16 QAM - R 553",
"12 - 64 QAM - R 517",
"18 - 64 QAM - R 822",
"21 - 256 QAM - R 711",
"27 - 256 QAM - R 948" };
double TransmissionMode_Bitrate[SERVICES_5G] = { 0, 0, 0, 0, 0, 0, 0 };
double TransmissionMode_SNIR[SERVICES_5G] = { -3.0, 2, 7.9, 13.0, 17.5, 22.0, 27.0 };
int TransmissionMode_Coderate_K[SERVICES_5G] = { 120, 602, 553, 517, 822, 711, 948 };
int TransmissionMode_Coderate_N[SERVICES_5G] = { 1024, 1024, 1024, 1024, 1024, 1024, 1024 };
int TransmissionMode_MCS[SERVICES_5G] = { 2, 2, 4, 6, 6, 8, 8 };
double TransmissionMode_Backoff[SERVICES_5G] = { 0.0, 0.0, 3.0, 3.0, 3.0, 3.0, 3.0 };
int TransmissionMode_Resource_Blocks_DL[SERVICES_5G] = { 1, 1, 1, 1, 1, 1, 1 };
int TransmissionMode_Resource_Blocks_UL[SERVICES_5G] = { 1, 1, 1, 1, 1, 1, 1 };
double TransmissionMode_Overhead_Ratio_DL[SERVICES_5G] = { 14., 14., 14., 14., 14., 14., 14. };
double TransmissionMode_Overhead_Ratio_UL[SERVICES_5G] = { 8., 8., 8., 8., 8., 8., 8. };
for (int CurrentService = 0; CurrentService < SERVICES_5G; CurrentService++)
{
char ServiceName[100];
sprintf(ServiceName, "%s", TransmissionMode_Name[CurrentService]);
Error = WinProp_Net_TransmissionMode_Add(ProjectHandle, ServiceName, CurrentService);
ParaValueInt = SERVICES_5G - CurrentService;
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_POSITION, NULL, &ParaValueInt, NULL);
ParaValueDouble = TransmissionMode_Bitrate[CurrentService];
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_BITRATE_DL, &ParaValueDouble, NULL, NULL);
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_BITRATE_UL, &ParaValueDouble, NULL, NULL);
ParaValueInt = TransmissionMode_Coderate_K[CurrentService];
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_CODERATE_K_DL, NULL, &ParaValueInt, NULL);
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_CODERATE_K_UL, NULL, &ParaValueInt, NULL);
ParaValueInt = TransmissionMode_Coderate_N[CurrentService];
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_CODERATE_N_DL, NULL, &ParaValueInt, NULL);
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_CODERATE_N_UL, NULL, &ParaValueInt, NULL);
ParaValueInt = TransmissionMode_Resource_Blocks_DL[CurrentService];
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_RESOURCE_BLOCKS_DL, NULL, &ParaValueInt, NULL);
ParaValueInt = TransmissionMode_Resource_Blocks_UL[CurrentService];
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_RESOURCE_BLOCKS_UL, NULL, &ParaValueInt, NULL);
ParaValueDouble = TransmissionMode_Overhead_Ratio_UL[CurrentService];
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_OVERHEAD_RATIO_UL, &ParaValueDouble, NULL, NULL);
ParaValueDouble = TransmissionMode_Overhead_Ratio_DL[CurrentService];
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_OVERHEAD_RATIO_DL, &ParaValueDouble, NULL, NULL);
ParaValueDouble = TransmissionMode_SNIR[CurrentService];
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_SNIR_DL, &ParaValueDouble, NULL, NULL);
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_SNIR_UL, &ParaValueDouble, NULL, NULL);
ParaValueInt = TransmissionMode_MCS[CurrentService];
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_MODULATION_UL, NULL, &ParaValueInt, NULL);
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_MODULATION_DL, NULL, &ParaValueInt, NULL);
ParaValueDouble = TransmissionMode_Backoff[CurrentService];
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_POWER_BACKOFF_UL, &ParaValueDouble, NULL, NULL);
Error = WinProp_Net_TransmissionMode_Para_Set(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_POWER_BACKOFF_DL, &ParaValueDouble, NULL, NULL);
Error = WinProp_Net_TransmissionMode_Para_Get(
ProjectHandle, CurrentService, NET_PARA_TRANS_MODE_BITRATE_DL, &ParaValueDouble, NULL, NULL);
TransmissionMode_Bitrate[CurrentService] = ParaValueDouble;
}
}
if (Error == 0)
{
int NrServices = 0;
Error = WinProp_Net_Project_Para_Get(ProjectHandle, NET_PARA_SERVICES, NULL, &NrServices, NULL);
if (Error == 0)
{
if (NrServices != SERVICES_5G)
Error = 1;
}
}
if (Error == 0)
{
ParaValueDouble = 23.;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_MS_MAX_TX_POWER, &ParaValueDouble, NULL, NULL);
}
if (Error == 0)
{
ParaValueDouble = GeneralParameters.Resolution;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_RESOLUTION, &ParaValueDouble, NULL, NULL);
}
if (Error == 0)
{
ParaValueDouble = GeneralParameters.UrbanLowerLeftX;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_AREA_LL_X, &ParaValueDouble, NULL, NULL);
}
if (Error == 0)
{
ParaValueDouble = GeneralParameters.UrbanLowerLeftY;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_AREA_LL_Y, &ParaValueDouble, NULL, NULL);
}
if (Error == 0)
{
ParaValueDouble = GeneralParameters.UrbanUpperRightX;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_AREA_UR_X, &ParaValueDouble, NULL, NULL);
}
if (Error == 0)
{
ParaValueDouble = GeneralParameters.UrbanUpperRightY;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_AREA_UR_Y, &ParaValueDouble, NULL, NULL);
}
if (Error == 0)
{
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_OUTPUT_WINPROP, NULL, NULL, API_DATA_FOLDER "output/monte_carlo_5g");
}
if (Error == 0)
{
ParaValueDouble = -3.;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_CELL_ASSIGNMENT_MIN_REQ_SNIR, &ParaValueDouble, NULL, NULL);
}
if (Error == 0)
{
ParaValueDouble = -95.;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_CELL_ASSIGNMENT_MIN_REQ_POWER, &ParaValueDouble, NULL, NULL);
}
if (Error == 0)
{
ParaValueInt = 1;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_ANTENNA_MASKING_MODE, NULL, &ParaValueInt, NULL);
}
if (Error == 0)
{
ParaValueInt = NET_PARA_5G_NUMEROLOGY0_20MHZ_FR1;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_BANDWIDTH_MODE_5G, NULL, &ParaValueInt, NULL);
}
if (Error == 0)
{
ParaValueInt = 1000;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_SUBCARRIERS_CONTROL, NULL, &ParaValueInt, NULL);
}
if (Error == 0)
{
ParaValueInt = 200;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_SUBCARRIERS_REFERENCE, NULL, &ParaValueInt, NULL);
}
if (Error == 0)
{
ParaValueInt = 31;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_SUBCARRIERS_GUARD, NULL, &ParaValueInt, NULL);
}
if (Error == 0)
{
ParaValueInt = 10;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_SYMBOLS_DATA, nullptr, &ParaValueInt, nullptr);
}
if (Error == 0)
{
ParaValueInt = 1;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_SYMBOLS_CONTROL, NULL, &ParaValueInt, NULL);
}
if (Error == 0)
{
ParaValueInt = 3;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_SYMBOLS_REFERENCE, NULL, &ParaValueInt, NULL);
}
if (Error == 0)
{
ParaValueInt = 2048;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_FFT_SIZE, NULL, &ParaValueInt, NULL);
}
if (Error == 0)
{
ParaValueInt = NET_TRAFFIC_MODE_STATIC_MONTE_CARLO;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_TRAFFIC_MODE, nullptr, &ParaValueInt, nullptr);
}
if (Error == 0)
{
ParaValueInt = 5;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_TRAFFIC_MONTE_CARLO_LOOPS, nullptr, &ParaValueInt, nullptr);
}
if (Error == 0)
{
ParaValueInt = NET_APPLICATION_AREA_MODE_KILOMETER;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_APPLICATION_AREA_MODE, nullptr, &ParaValueInt, nullptr);
}
if (Error == 0)
{
ParaValueInt = 1;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_TRAFFIC_CELL_SELECT_CONSIDER_PRIO, nullptr, &ParaValueInt, nullptr);
}
if (Error == 0)
{
ParaValueInt = 20;
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_TRAFFIC_MAX_ITERATIONS, nullptr, &ParaValueInt, nullptr);
}
if (Error == 0)
{
char ClutterTraffic[200];
sprintf(ClutterTraffic, "%s.odb", my_odb_database);
Error = WinProp_Net_Clutter_Set(ProjectHandle, CLUTTERMODE_FILE, ClutterTraffic, false, "", nullptr);
}
if (Error == 0)
{
int ApplID = 0;
int ApplPriority = 0;
float ApplActivity = 1.f;
int ApplTrafficMode = NET_APPLICATION_TRAFFIC_MODE_OFFERED_TRAFFIC;
const char* ApplName = "Browsing";
Error = WinProp_Net_Application_Add(ProjectHandle, ApplID, ApplPriority, ApplActivity, ApplTrafficMode, ApplName);
if (Error == 0)
{
int ClutterClassID = 1;
float ArrivalRate = 0.f;
float HoldTime = 0.f;
float OfferedTraffic = 50.f;
WinProp_Net_Application_ClutterClass_Link(ProjectHandle, ApplID, ClutterClassID, ArrivalRate, HoldTime, OfferedTraffic);
}
if (Error == 0)
{
int TransModeID = 5;
Error = WinProp_Net_Application_TransmissionMode_Link(ProjectHandle, ApplID, TransModeID, 0);
}
}
WinProp_Callback Callback;
WinProp_Structure_Init_Callback(&Callback);
Callback.Percentage = CallbackProgress;
Callback.Message = CallbackMessage;
Callback.Error = CallbackError;
for (int cell = 0; cell < MAX_CELLS; cell++)
{
Error = OutdoorPlugIn_ComputePrediction(
&Antenna[cell], &GeneralParameters, NULL, 0, NULL, NULL, NULL, NULL, &Callback, &PropResults[cell], NULL, NULL, NULL);
if (Error == 0)
{
char PowerOutputFile[1200];
sprintf(PowerOutputFile, "%s%s%s%s", API_DATA_FOLDER, "output/monte_carlo_5g/", Antenna[cell].Name,".txt");
write_ascii(&PropResults[cell], PowerOutputFile);
}
else
{
CallbackError(GeneralParameters.ErrorMessageMain, Error);
break;
}
}
if (Error == 0)
{
int MapIndex[MAX_CELLS];
for (int Count = 0; Count < MAX_CELLS; Count++)
{
if (Error == 0)
{
Antenna[Count].Pattern = &WinPropPattern;
Error = WinProp_Net_PropagationMap_Add(
ProjectHandle, &MapIndex[Count], &Antenna[Count], &PropResults[Count]);
}
}
}
if (Error == 0)
Error = WinProp_Net_Project_Result_Switch(ProjectHandle, NET_RESULT_BEST_SERVER, 1);
if (Error == 0)
Error = WinProp_Net_Project_Result_Switch(ProjectHandle, NET_RESULT_MAX_DATARATE, 1);
if (Error == 0)
Error = WinProp_Net_Project_Result_Switch(ProjectHandle, NET_RESULT_MAX_REC_POWER, 1);
if (Error == 0)
Error = WinProp_Net_Project_Result_Switch(ProjectHandle, NET_RESULT_REC_POWER, 1);
if (Error == 0)
Error = WinProp_Net_Project_Result_Switch(ProjectHandle, NET_RESULT_SNIR, 1);
if (Error == 0)
Error = WinProp_Net_Project_Result_Switch(ProjectHandle, NET_RESULT_TRAFFIC_OFFERED, 1);
if (Error == 0)
Error = WinProp_Net_Project_Result_Switch(ProjectHandle, NET_RESULT_TRAFFIC_SERVED, 1);
if (Error == 0)
Error = WinProp_Net_Project_Result_Switch(ProjectHandle, NET_RESULT_TRAFFIC_BLOCKED, 1);
if (Error == 0)
Error = WinProp_Net_Project_Result_Switch(ProjectHandle, NET_RESULT_TRAFFIC_STATE, 1);
if (Error == 0)
{
char HeightString[200];
sprintf(HeightString, "%s", "");
for (int Height = 0; Height < NrPredictionHeights; Height++)
{
char thisHeightStr[50];
sprintf(thisHeightStr, "%.2f ", PredictionHeights[Height]);
strcat(HeightString, thisHeightStr);
}
Error = WinProp_Net_Project_Para_Set(ProjectHandle, NET_PARA_HEIGHT_MULTIPLE, NULL, NULL, HeightString);
if (Error == 0)
{
Error = WinProp_Net_Project_Compute(ProjectHandle, &Callback);
}
}
if (Error == 0)
{
WinProp_ResultMonteCarlo* ResultMonteCarlo = NULL;
Error = WinProp_Net_NetworkMonteCarloStats_Get(ProjectHandle, &ResultMonteCarlo);
if (Error == 0)
{
char NameForOutput[1200];
sprintf(NameForOutput, "%s%s", API_DATA_FOLDER, "output/monte_carlo_5g/MonteCarloStatistics.txt");
write_ascii_monte_carlo_statistic(ResultMonteCarlo, NameForOutput);
}
}
if (Error == 0)
{
WinProp_Result* MaxThroughput = NULL;
Error = WinProp_Net_NetworkMap_Get(ProjectHandle, -1, NET_RESULT_MAX_THROUGHPUT, &MaxThroughput);
if (Error == 0)
{
char NameForOutput[1200];
sprintf(NameForOutput, "%s%s", API_DATA_FOLDER, "output/monte_carlo_5g/Max Throughput DownLink.txt");
write_ascii(MaxThroughput, NameForOutput);
}
}
if (Error == 0)
{
WinProp_Result* MaxPower = NULL;
Error = WinProp_Net_NetworkMap_Get(ProjectHandle, -1, NET_RESULT_MAX_REC_POWER, &MaxPower);
if (Error == 0)
{
char NameForOutput[1200];
sprintf(NameForOutput, "%s%s", API_DATA_FOLDER, "output/monte_carlo_5g/Max Received Power.txt");
write_ascii(MaxPower, NameForOutput);
}
}
if (Error == 0)
{
WinProp_Result* MaxSNIR = NULL;
Error = WinProp_Net_NetworkMap_Get(ProjectHandle, -1, NET_RESULT_SNIR, &MaxSNIR);
if (Error == 0)
{
char NameForOutput[1200];
sprintf(NameForOutput, "%s%s", API_DATA_FOLDER, "output/monte_carlo_5g/Max SNIR.txt");
write_ascii(MaxSNIR, NameForOutput);
}
}
for (int Count = 0; Count < MAX_CELLS; Count++)
{
WinProp_FreeResult(&PropResults[Count]);
}
Error = WinProp_Net_Project_Close(ProjectHandle);
return 0;
}
int _STD_CALL CallbackMessage(const char * Text)
{
if (Text == nullptr)
return 0;
std::cout << "\n" << Text;
return(0);
}
int _STD_CALL CallbackError(const char * Text, int Error)
{
if (Text == nullptr)
return 0;
std::cout << "\n";
#ifdef __LINUX
std::cout << "\033[31m" << "Error (" << Error << "): ";
#else
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, FOREGROUND_RED);
std::cout << "Error (" << Error << "): ";
#endif // __LINUX
std::cout << Text;
#ifdef __LINUX
std::cout << "\033[0m";
#else
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
#endif // __LINUX
return 0;
}
int _STD_CALL CallbackProgress(int value, const char* text)
{
char Line[200];
sprintf(Line, "\n%d%% %s", value, text);
std::cout << Line;
return(0);
}
void write_ascii(const WinProp_Result *Resultmatrix, const char* Filename) {
if (Resultmatrix)
{
FILE* OutputFile = fopen(Filename, "w");
if (OutputFile)
{
for (int x = 0; x < Resultmatrix->Columns; x++)
{
for (int y = 0; y < Resultmatrix->Lines; y++)
{
double Coordinate_X = Resultmatrix->LowerLeftX + ((double)x + 0.5) * Resultmatrix->Resolution;
double Coordinate_Y = Resultmatrix->LowerLeftY + ((double)y + 0.5) * Resultmatrix->Resolution;
if (Resultmatrix->Matrix[0][x][y] > -1000)
{
fprintf(OutputFile, "%.5f\t%.5f\t%.4f\n", Coordinate_X, Coordinate_Y, Resultmatrix->Matrix[0][x][y]);
}
else
{
fprintf(OutputFile, "%.5f\t%.5f\t%s\n", Coordinate_X, Coordinate_Y, "N.C.");
}
}
}
fclose(OutputFile);
}
else
{
printf("\nCould not open the File: %s for writing.\n", Filename);
}
}
}
void CarrierPropertiesSet(WinProp_Antenna *Antenna, const WinProp_Carrier *Carrier) {
Antenna->Carriers.CarrierID = Carrier->CarrierID;
Antenna->Carriers.SystemID = Carrier->SystemID;
Antenna->Carriers.CellLoad = Carrier->CellLoad;
Antenna->Carriers.MimoID = Carrier->MimoID;
Antenna->Carriers.NoiseRiseUL = Carrier->NoiseRiseUL;
Antenna->Carriers.PowerBackoffPilotDL = Carrier->PowerBackoffPilotDL;
Antenna->Carriers.Numerology = Carrier->Numerology;
Antenna->Carriers.SymbolsPerSlot = Carrier->SymbolsPerSlot;
Antenna->Carriers.NrAntennaBeams = Carrier->NrAntennaBeams;
Antenna->Carriers.BeamGainCtrlServer = Carrier->BeamGainCtrlServer;
Antenna->Carriers.BeamGainCtrlInterferer = Carrier->BeamGainCtrlInterferer;
Antenna->Carriers.BeamGainDataServer = Carrier->BeamGainDataServer;
Antenna->Carriers.BeamGainDataInterferer = Carrier->BeamGainDataInterferer;
Antenna->Carriers.TDD_Slots_DL = Carrier->TDD_Slots_DL;
Antenna->Carriers.TDD_Slots_UL = Carrier->TDD_Slots_UL;
Antenna->Carriers.TDD_Slots_Flex = Carrier->TDD_Slots_Flex;
}
void write_ascii_monte_carlo_statistic(
const WinProp_ResultMonteCarlo* ResultMonteCarlo,
const char* Filename)
{
if (ResultMonteCarlo == NULL)
return;
FILE* Outfile = fopen(Filename, "w+");
if (Outfile)
{
char sepChar = ' ';
char format1[100];
char format2[100];
char text[400];
fprintf(Outfile, "%s", "-------------------------------------------------------------------\n");
fprintf(Outfile, "Number of evaluated snapshots:%c%d\n", sepChar, ResultMonteCarlo->nbrSnapshots);
fprintf(Outfile, "Number of evaluated cells:%c%d\n", sepChar, ResultMonteCarlo->nbrCells);
fprintf(Outfile, "Number of evaluated applications:%c%d\n", sepChar, ResultMonteCarlo->nbrApplications);
fprintf(Outfile, "%s", "-------------------------------------------------------------------\n");
fprintf(Outfile, "%s", "\n");
sprintf(format1, "%%%ds", 15);
sprintf(format2, "%%%ds", 14);
for (int cell = -1; cell < (int)ResultMonteCarlo->nbrCells; cell++)
{
fprintf(Outfile, "%s", "********************************\n");
if (cell >= 0)
{
fprintf(Outfile, "***%cCell %d", sepChar, (cell + 1));
fprintf(Outfile, "%s", "\n********************************");
}
else
{
sprintf(text, "***%cTotal simulation area", sepChar);
fprintf(Outfile, "%-30s", text);
fprintf(Outfile, "%s", "\n********************************");
}
for (int snapshot = (int)ResultMonteCarlo->nbrSnapshots; snapshot >= 0; snapshot--)
{
if (snapshot == (int)ResultMonteCarlo->nbrSnapshots)
sprintf(text, "%cAverage", sepChar);
else
sprintf(text, "%cSnapshot %d", sepChar, (snapshot + 1));
if (snapshot == (int)ResultMonteCarlo->nbrSnapshots)
fprintf(Outfile, format2, text);
else
fprintf(Outfile, format1, text);
}
fprintf(Outfile, "%s", "\n");
if (cell >= 0)
{
fprintf(Outfile, "%-31s", " Tx Power Load (Downlink): ");
for (int snapshot = (int)ResultMonteCarlo->nbrSnapshots; snapshot >= 0; snapshot--)
{
if (snapshot == (int)ResultMonteCarlo->nbrSnapshots)
{
float average = 0.f;
for (unsigned int s = 0; s < ResultMonteCarlo->nbrSnapshots; s++)
{
average += ResultMonteCarlo->trxLoad[s][cell].LoadPowerDL;
}
if (ResultMonteCarlo->nbrSnapshots > 0)
{
average /= ResultMonteCarlo->nbrSnapshots;
}
sprintf(text, "%c%.1f%c%%", sepChar, average * 100.f, sepChar);
fprintf(Outfile, format2, text);
}
else
{
sprintf(text, "%c%.1f%c%%", sepChar, ResultMonteCarlo->trxLoad[snapshot][cell].LoadPowerDL * 100.f, sepChar);
fprintf(Outfile, format1, text);
}
}
fprintf(Outfile, "%s", "\n");
}
if (cell >= 0)
{
fprintf(Outfile, "%-33s", " Noise Rise (Uplink): ");
for (int snapshot = (int)ResultMonteCarlo->nbrSnapshots; snapshot >= 0; snapshot--)
{
if (snapshot == (int)ResultMonteCarlo->nbrSnapshots)
{
float average = 0.f;
for (unsigned int s = 0; s < ResultMonteCarlo->nbrSnapshots; s++)
{
average += ResultMonteCarlo->trxLoad[s][cell].NoiseRiseUL;
}
if (ResultMonteCarlo->nbrSnapshots > 0)
{
average /= ResultMonteCarlo->nbrSnapshots;
}
sprintf(text, "%c%.1f%cdB", sepChar, average, sepChar);
fprintf(Outfile, format2, text);
}
else
{
sprintf(text, "%c%.1f%cdB", sepChar, ResultMonteCarlo->trxLoad[snapshot][cell].NoiseRiseUL, sepChar);
fprintf(Outfile, format1, text);
}
}
fprintf(Outfile, "%s", "\n");
}
if (cell >= 0)
{
fprintf(Outfile, "%-32s", " Resources Load (Downlink): ");
for (int snapshot = (int)ResultMonteCarlo->nbrSnapshots; snapshot >= 0; snapshot--)
{
if (snapshot == (int)ResultMonteCarlo->nbrSnapshots)
{
float average = 0.f;
for (unsigned int s = 0; s < ResultMonteCarlo->nbrSnapshots; s++)
{
average += ResultMonteCarlo->trxLoad[s][cell].LoadResourcesDL;
}
if (ResultMonteCarlo->nbrSnapshots > 0)
{
average /= ResultMonteCarlo->nbrSnapshots;
}
sprintf(text, "%c%.1f%c%%", sepChar, average * 100.f, sepChar);
fprintf(Outfile, format2, text);
}
else
{
sprintf(text, "%c%.1f%c%%", sepChar, ResultMonteCarlo->trxLoad[snapshot][cell].LoadResourcesDL * 100.f, sepChar);
fprintf(Outfile, format1, text);
}
}
fprintf(Outfile, "%s", "\n");
}
if (cell >= 0)
{
fprintf(Outfile, "%-32s", " Resources Load (Uplink): ");
for (int snapshot = (int)ResultMonteCarlo->nbrSnapshots; snapshot >= 0; snapshot--)
{
if (snapshot == (int)ResultMonteCarlo->nbrSnapshots)
{
float average = 0.f;
for (unsigned int s = 0; s < ResultMonteCarlo->nbrSnapshots; s++)
{
average += ResultMonteCarlo->trxLoad[s][cell].LoadResourcesUL;
}
if (ResultMonteCarlo->nbrSnapshots > 0)
{
average /= ResultMonteCarlo->nbrSnapshots;
}
sprintf(text, "%c%.1f%c%%", sepChar, average * 100.f, sepChar);
fprintf(Outfile, format2, text);
}
else
{
sprintf(text, "%c%.1f%c%%", sepChar, ResultMonteCarlo->trxLoad[snapshot][cell].LoadResourcesUL * 100.f, sepChar);
fprintf(Outfile, format1, text);
}
}
fprintf(Outfile, "%s", "\n");
}
if (cell >= 0)
{
fprintf(Outfile, "%-33s", " Throughput (Downlink): ");
for (int snapshot = (int)ResultMonteCarlo->nbrSnapshots; snapshot >= 0; snapshot--)
{
float ThroughputDL = 0.f;
if (snapshot == (int)ResultMonteCarlo->nbrSnapshots)
{
float average = 0.f;
for (unsigned int s = 0; s < ResultMonteCarlo->nbrSnapshots; s++)
{
average += ResultMonteCarlo->trxLoad[s][cell].ThroughputUL;
}
if (ResultMonteCarlo->nbrSnapshots > 0)
{
average /= ResultMonteCarlo->nbrSnapshots;
}
ThroughputDL = average;
}
else
{
ThroughputDL = ResultMonteCarlo->trxLoad[snapshot][cell].ThroughputUL;
}
if (ThroughputDL > 1e9)
sprintf(text, "%c%.1f%cGB/s", sepChar, ThroughputDL / 1e9, sepChar);
else if (ThroughputDL > 1e6)
sprintf(text, "%c%.1f%cMB/s", sepChar, ThroughputDL / 1e6, sepChar);
else if (ThroughputDL > 1e3)
sprintf(text, "%c%.1f%ckB/s", sepChar, ThroughputDL / 1e3, sepChar);
else
sprintf(text, "%c%.1f%cB/s", sepChar, ThroughputDL, sepChar);
if (snapshot == (int)ResultMonteCarlo->nbrSnapshots)
fprintf(Outfile, format2, text);
else
fprintf(Outfile, format1, text);
}
fprintf(Outfile, "%s", "\n");
}
if (cell >= 0)
{
fprintf(Outfile, "%-33s", " Throughput (uplink): ");
for (int snapshot = (int)ResultMonteCarlo->nbrSnapshots; snapshot >= 0; snapshot--)
{
float ThroughputUL = 0.f;
if (snapshot == (int)ResultMonteCarlo->nbrSnapshots)
{
float average = 0.f;
for (unsigned int s = 0; s < ResultMonteCarlo->nbrSnapshots; s++)
{
average += ResultMonteCarlo->trxLoad[s][cell].ThroughputUL;
}
if (ResultMonteCarlo->nbrSnapshots > 0)
{
average /= ResultMonteCarlo->nbrSnapshots;
}
ThroughputUL = average;
}
else
{
ThroughputUL = ResultMonteCarlo->trxLoad[snapshot][cell].ThroughputUL;
}
if (ThroughputUL > 1e9)
sprintf(text, "%c%.1f%cGB/s", sepChar, ThroughputUL / 1e9, sepChar);
else if (ThroughputUL > 1e6)
sprintf(text, "%c%.1f%cMB/s", sepChar, ThroughputUL / 1e6, sepChar);
else if (ThroughputUL > 1e3)
sprintf(text, "%c%.1f%ckB/s", sepChar, ThroughputUL / 1e3, sepChar);
else
sprintf(text, "%c%.1f%cB/s", sepChar, ThroughputUL, sepChar);
if (snapshot == (int)ResultMonteCarlo->nbrSnapshots)
fprintf(Outfile, format2, text);
else
fprintf(Outfile, format1, text);
}
fprintf(Outfile, "%s", "\n");
}
for (unsigned int app = 0; app <= ResultMonteCarlo->nbrApplications; app++)
{
if (app < ResultMonteCarlo->nbrApplications)
sprintf(text, "%s %d", "\n Applications id: ", app);
else
sprintf(text, "%s", "\nAll Applications");
fprintf(Outfile, "%-20s\n", text);
for (int MobileType = 0; MobileType < 4; MobileType++)
{
switch (MobileType)
{
case 0:
fprintf(Outfile, " %cMobiles served: ", sepChar);
break;
case 1:
fprintf(Outfile, " %cMobiles blocked (traffic):", sepChar);
break;
case 2:
fprintf(Outfile, " %cMobiles blocked (quality):", sepChar);
break;
case 3:
fprintf(Outfile, " %cMobiles not assigned: ", sepChar);
break;
default:
break;
}
for (int snapshot = (int)ResultMonteCarlo->nbrSnapshots; snapshot >= 0; snapshot--)
{
float nbr = 0.f;
if (app == ResultMonteCarlo->nbrApplications)
{
for (unsigned int a = 0; a < ResultMonteCarlo->nbrApplications; a++)
{
if (cell >= 0)
{
if (snapshot == (int)ResultMonteCarlo->nbrSnapshots)
{
for (unsigned int s = 0; s < ResultMonteCarlo->nbrSnapshots; s++)
{
switch (MobileType)
{
case 0:
nbr += ResultMonteCarlo->statisticCell[s][cell][a].nbrServed;
break;
case 1:
nbr += ResultMonteCarlo->statisticCell[s][cell][a].nbrBlocked;
break;
case 2:
nbr += ResultMonteCarlo->statisticCell[s][cell][a].nbrNotConnected;
break;
case 3:
nbr += ResultMonteCarlo->statisticCell[s][cell][a].nbrNotAssigned;
break;
default:
break;
}
}
}
else
{
switch (MobileType)
{
case 0:
nbr += ResultMonteCarlo->statisticCell[snapshot][cell][a].nbrServed;
break;
case 1:
nbr += ResultMonteCarlo->statisticCell[snapshot][cell][a].nbrBlocked;
break;
case 2:
nbr += ResultMonteCarlo->statisticCell[snapshot][cell][a].nbrNotConnected;
break;
case 3:
nbr += ResultMonteCarlo->statisticCell[snapshot][cell][a].nbrNotAssigned;
break;
default:
break;
}
}
}
else
{
if (snapshot == (int)ResultMonteCarlo->nbrSnapshots)
{
for (unsigned int s = 0; s < ResultMonteCarlo->nbrSnapshots; s++)
{
switch (MobileType)
{
case 0:
nbr += ResultMonteCarlo->statisticTotal[s][a].nbrServed;
break;
case 1:
nbr += ResultMonteCarlo->statisticTotal[s][a].nbrBlocked;
break;
case 2:
nbr += ResultMonteCarlo->statisticTotal[s][a].nbrNotConnected;
break;
case 3:
nbr += ResultMonteCarlo->statisticTotal[s][a].nbrNotAssigned;
break;
default:
break;
}
}
}
else
{
switch (MobileType)
{
case 0:
nbr += ResultMonteCarlo->statisticTotal[snapshot][a].nbrServed;
break;
case 1:
nbr += ResultMonteCarlo->statisticTotal[snapshot][a].nbrBlocked;
break;
case 2:
nbr += ResultMonteCarlo->statisticTotal[snapshot][a].nbrNotConnected;
break;
case 3:
nbr += ResultMonteCarlo->statisticTotal[snapshot][a].nbrNotAssigned;
break;
default:
break;
}
}
}
}
}
else
{
if (cell >= 0)
{
if (snapshot == (int)ResultMonteCarlo->nbrSnapshots)
{
for (unsigned int s = 0; s < ResultMonteCarlo->nbrSnapshots; s++)
{
switch (MobileType)
{
case 0:
nbr += ResultMonteCarlo->statisticCell[s][cell][app].nbrServed;
break;
case 1:
nbr += ResultMonteCarlo->statisticCell[s][cell][app].nbrBlocked;
break;
case 2:
nbr += ResultMonteCarlo->statisticCell[s][cell][app].nbrNotConnected;
break;
case 3:
nbr += ResultMonteCarlo->statisticCell[s][cell][app].nbrNotAssigned;
break;
default:
break;
}
}
}
else
{
switch (MobileType)
{
case 0:
nbr += ResultMonteCarlo->statisticCell[snapshot][cell][app].nbrServed;
break;
case 1:
nbr += ResultMonteCarlo->statisticCell[snapshot][cell][app].nbrBlocked;
break;
case 2:
nbr += ResultMonteCarlo->statisticCell[snapshot][cell][app].nbrNotConnected;
break;
case 3:
nbr += ResultMonteCarlo->statisticCell[snapshot][cell][app].nbrNotAssigned;
break;
default:
break;
}
}
}
else
if (snapshot == (int)ResultMonteCarlo->nbrSnapshots)
{
for (unsigned int s = 0; s < ResultMonteCarlo->nbrSnapshots; s++)
{
switch (MobileType)
{
case 0:
nbr += ResultMonteCarlo->statisticTotal[s][app].nbrServed;
break;
case 1:
nbr += ResultMonteCarlo->statisticTotal[s][app].nbrBlocked;
break;
case 2:
nbr += ResultMonteCarlo->statisticTotal[s][app].nbrNotConnected;
break;
case 3:
nbr += ResultMonteCarlo->statisticTotal[s][app].nbrNotAssigned;
break;
default:
break;
}
}
}
else
{
switch (MobileType)
{
case 0:
nbr += ResultMonteCarlo->statisticTotal[snapshot][app].nbrServed;
break;
case 1:
nbr += ResultMonteCarlo->statisticTotal[snapshot][app].nbrBlocked;
break;
case 2:
nbr += ResultMonteCarlo->statisticTotal[snapshot][app].nbrNotConnected;
break;
case 3:
nbr += ResultMonteCarlo->statisticTotal[snapshot][app].nbrNotAssigned;
break;
default:
break;
}
}
}
if (snapshot == (int)ResultMonteCarlo->nbrSnapshots)
{
double nbrDouble = ((double)nbr) / ((double)ResultMonteCarlo->nbrSnapshots);
sprintf(text, "%c%.1lf", sepChar, nbrDouble);
fprintf(Outfile, format2, text);
}
else
{
sprintf(text, "%c%.1f", sepChar, nbr);
fprintf(Outfile, format1, text);
}
}
fprintf(Outfile, "%s", "\n");
}
}
fprintf(Outfile, "%s", "\n\n\n");
}
fclose(Outfile);
}
else
{
printf("\nCould not open the File: %s for writing.\n", Filename);
}
}