void DL_my_algo_PacketScheduler2::RBsAllocation () { #ifdef SCHEDULER_DEBUG std::cout << " ---- DL_my_algo_PacketScheduler2::my_algo"; #endif FlowsToSchedule* flows = GetFlowsToSchedule (); int nbOfRBs = GetMacEntity ()->GetDevice ()->GetPhy ()->GetBandwidthManager ()->GetDlSubChannels ().size (); //create a matrix of flow metrics double metrics[nbOfRBs][flows->size ()]; /* for (int i = 0; i < nbOfRBs; i++) { for (int j = 0; j < flows->size (); j++) { metrics[i][j] = ComputeSchedulingMetric (flows->at (j)->GetBearer (), flows->at (j)->GetSpectralEfficiency ().at (i), i); } }*/ #ifdef SCHEDULER_DEBUG std::cout << ", available RBs " << nbOfRBs << ", flows " << flows->size () << std::endl; /*for (int ii = 0; ii < flows->size (); ii++) { std::cout << "\t metrics for flow " << flows->at (ii)->GetBearer ()->GetApplication ()->GetApplicationID () << ":"; for (int jj = 0; jj < nbOfRBs; jj++) { std::cout << " " << metrics[jj][ii]; } std::cout << std::endl; }*/ #endif AMCModule *amc = GetMacEntity ()->GetAmcModule (); double l_dAllocatedRBCounter = 0; int l_iNumberOfUsers = ((ENodeB*)this->GetMacEntity()->GetDevice())->GetNbOfUserEquipmentRecords(); bool * l_bFlowScheduled = new bool[flows->size ()]; int l_iScheduledFlows = 0; std::vector<double> * l_bFlowScheduledSINR = new std::vector<double>[flows->size ()]; int radius=NetworkManager::Init()->GetCellByID (0)->GetRadius()*1000; //get radius std::vector<UserEquipment*>* users = NetworkManager::Init()->GetUserEquipmentContainer(); int nbUE=users->size(); int nbCell = NetworkManager::Init()->GetNbCell(); int nbFlows = total_flow::Init()->get_total_flows(); const double guarantee_MB=total_flow::Init()->get_data_rate(); const double guarantee_bit = (guarantee_MB*1000*8.0)/100 ; //bit per TTI static std::vector<bool> IsCell_Center(nbUE*nbFlows , false); static std::vector<double> credit(nbUE,0.0); vector<bool> flag(nbUE*nbFlows, false); for (int i=0;i<nbUE;i++) { //---------------get ue radius---------- double x=users->at(i)->GetMobilityModel ()->GetAbsolutePosition()->GetCoordinateX(); //ue x,y position double y=users->at(i)->GetMobilityModel ()->GetAbsolutePosition()->GetCoordinateY(); double x1=users->at(i)->GetCell () ->GetCellCenterPosition ()->GetCoordinateX (); //enb x,y position double y1=users->at(i)->GetCell () ->GetCellCenterPosition ()->GetCoordinateY (); double ue_radius=sqrt( (x-x1)*(x-x1) + (y-y1)*(y-y1) ); //Enb ID = users->at(i)->GetCell ()->GetIdCell() //UEid = users->at(i)->GetIDNetworkNode() if(ue_radius < radius*2.0/3){ for(int k=i*nbFlows;k<(i+1)*nbFlows;k++){ IsCell_Center[k]=true; } }else{ for(int k=i*nbFlows;k<(i+1)*nbFlows;k++){ IsCell_Center[k]=false; } } } //RBs allocation std::vector<vector<double> > my_metrics(nbOfRBs, vector<double>(flows->size ())); int max_edge_RB=0; double edge_demand_bit=0; double center_demand_bit=0; double total_demand_bit=0; for(int k=0;k<flows->size ();k++) { if(IsCell_Center[flows->at (k)->GetBearer ()->GetApplication ()->GetApplicationID ()]==false){ edge_demand_bit+=flows->at (k)->GetDataToTransmit(); }else{ center_demand_bit+=flows->at (k)->GetDataToTransmit(); } } if( ( edge_demand_bit/(edge_demand_bit + center_demand_bit) ) * nbOfRBs < 1.0/5.0*nbOfRBs){ max_edge_RB=( edge_demand_bit/( edge_demand_bit + center_demand_bit) ) * nbOfRBs; } else{ max_edge_RB=1.0/5.0*nbOfRBs; } total_demand_bit = edge_demand_bit + center_demand_bit; vector<double> copy_credit(nbUE , 0.0 ); copy_credit.assign(credit.begin(), credit.end()); for(int i=0;i<nbUE;i++){ if(copy_credit[i]>0){ copy_credit[i]=0; } } double min= *min_element(copy_credit.begin(), copy_credit.end()); for(int i=0;i<nbUE;i++){ copy_credit[i]-=min; } double max= *max_element(copy_credit.begin(), copy_credit.end()); if(max==0){ max=1; } double sum_credit=0; for(int i=0;i<nbUE;i++){ //cout << "copy_credit[" << i << "] = " << copy_credit[i]/max << endl; sum_credit+=(2-copy_credit[i]/max); } vector<double> cqi(flows->size (),0.0); for (int j = 0; j < flows->size (); j++) { for (int s = 0; s < nbOfRBs; s++) { cqi.at(j)+=flows->at (j)->GetCqiFeedbacks ().at(s); } cqi.at(j)/=nbOfRBs; } for (int s = 0; s < nbOfRBs; s++) { for (int j = 0; j < flows->size (); j++) { my_metrics[s][j] = mlwdf_ComputeSchedulingMetric (flows->at (j)->GetBearer (), flows->at (j)->GetSpectralEfficiency ().at (s), s,copy_credit[flows->at (j)->GetBearer ()->GetApplication ()->GetApplicationID ()/nbFlows]/max , sum_credit/nbUE ,flows->at (j)->GetDataToTransmit(),flows->at (j)->GetCqiFeedbacks ().at(s)/cqi.at(j)); } for (int j = 0; j < flows->size (); j++) { metrics[s][j] = ComputeSchedulingMetric1 (flows->at (j)->GetBearer (), flows->at (j)->GetSpectralEfficiency ().at (s), s,flows->at (j)->GetDataToTransmit(), total_demand_bit,copy_credit[flows->at (j)->GetBearer ()->GetApplication ()->GetApplicationID ()/nbFlows]/max , sum_credit/nbUE); } if (l_iScheduledFlows == flows->size ()) break; double targetMetric = 0; bool RBIsAllocated = false; FlowToSchedule* scheduledFlow; int l_iScheduledFlowIndex = 0; //std::cout << "avg_cqi = " << avg_cqi << std::endl; RBIsAllocated = false; if(s<max_edge_RB) { targetMetric=-1; for(int k=0;k<flows->size ();k++) { if(metrics[s][k] > targetMetric && !l_bFlowScheduled[k] && flows->at (k)->GetDataToTransmit() >0 && IsCell_Center[flows->at (k)->GetBearer ()->GetApplication ()->GetApplicationID ()]==false) { targetMetric=metrics[s][k]; RBIsAllocated = true; scheduledFlow = flows->at (k); l_iScheduledFlowIndex = k; } } if(!RBIsAllocated) { targetMetric=-1; for(int k=0;k<flows->size ();k++) { if(my_metrics[s][k] > targetMetric && !l_bFlowScheduled[k] && flows->at (k)->GetDataToTransmit() >0 ) { targetMetric=my_metrics[s][k]; RBIsAllocated = true; scheduledFlow = flows->at (k); l_iScheduledFlowIndex = k; } } } }else { targetMetric=-1; l_iScheduledFlowIndex=0; for (int k = 0; k < flows->size (); k++) { if (my_metrics[s][k] > targetMetric && !l_bFlowScheduled[k] && flows->at (k)->GetDataToTransmit() >0 ) { targetMetric = my_metrics[s][k]; RBIsAllocated = true; scheduledFlow = flows->at (k); l_iScheduledFlowIndex = k; //std::cout << "\tschedule to flow : " << flows->at (k)->GetBearer ()->GetApplication ()->GetApplicationID () << std::endl; } } } if (RBIsAllocated) { l_dAllocatedRBCounter++; scheduledFlow->GetListOfAllocatedRBs()->push_back (s); // the s RB has been allocated to that flow! #ifdef SCHEDULER_DEBUG /* std::cout << "\t *** RB " << s << " assigned to the " " flow " << scheduledFlow->GetBearer ()->GetApplication ()->GetApplicationID () << std::endl;*/ std::cout << "\t *** RB " << s << " assigned to the " " flow " << scheduledFlow->GetBearer ()->GetApplication ()->GetApplicationID () << " cqi " << scheduledFlow->GetCqiFeedbacks ().at (s) << " cell_center " << IsCell_Center[scheduledFlow->GetBearer ()->GetApplication ()->GetApplicationID ()] << std::endl; #endif double sinr = amc->GetSinrFromCQI (scheduledFlow->GetCqiFeedbacks ().at (s)); l_bFlowScheduledSINR[l_iScheduledFlowIndex].push_back(sinr); double effectiveSinr = GetEesmEffectiveSinr (l_bFlowScheduledSINR[l_iScheduledFlowIndex]); int mcs = amc->GetMCSFromCQI (amc->GetCQIFromSinr (effectiveSinr)); int transportBlockSize = amc->GetTBSizeFromMCS (mcs, scheduledFlow->GetListOfAllocatedRBs ()->size ()); if (transportBlockSize >= scheduledFlow->GetDataToTransmit() * 8) { #ifdef SCHEDULER_DEBUG cout << "-- FLOW " << scheduledFlow->GetBearer ()->GetApplication ()->GetApplicationID () << ", demand = " << scheduledFlow->GetDataToTransmit()*8 << ", transportBlockSize = " << transportBlockSize << endl; #endif l_bFlowScheduled[l_iScheduledFlowIndex] = true; l_iScheduledFlows++; } } } delete [] l_bFlowScheduled; delete [] l_bFlowScheduledSINR; //Finalize the allocation PdcchMapIdealControlMessage *pdcchMsg = new PdcchMapIdealControlMessage (); for (FlowsToSchedule::iterator it = flows->begin (); it != flows->end (); it++) { FlowToSchedule *flow = (*it); if (flow->GetListOfAllocatedRBs ()->size () > 0) { //cout << "----------------------------------" << endl; //this flow has been scheduled std::vector<double> estimatedSinrValues; for (int rb = 0; rb < flow->GetListOfAllocatedRBs ()->size (); rb++ ) { double sinr = amc->GetSinrFromCQI ( flow->GetCqiFeedbacks ().at (flow->GetListOfAllocatedRBs ()->at (rb))); //cout << "CQI = " << flow->GetCqiFeedbacks ().at (flow->GetListOfAllocatedRBs ()->at (rb)) << endl; estimatedSinrValues.push_back (sinr); } //compute the effective sinr double effectiveSinr = GetEesmEffectiveSinr (estimatedSinrValues); //get the MCS for transmission //cout << "effectiveCQI = " << amc->GetCQIFromSinr (effectiveSinr) << endl; int mcs = amc->GetMCSFromCQI (amc->GetCQIFromSinr (effectiveSinr)); //define the amount of bytes to transmit //int transportBlockSize = amc->GetTBSizeFromMCS (mcs); int transportBlockSize = amc->GetTBSizeFromMCS (mcs, flow->GetListOfAllocatedRBs ()->size ()); double bitsToTransmit = transportBlockSize; flow->UpdateAllocatedBits (bitsToTransmit); #ifdef SCHEDULER_DEBUG std::cout << "\t\t --> flow " << flow->GetBearer ()->GetApplication ()->GetApplicationID () << " has been scheduled: " << "\n\t\t\t nb of RBs " << flow->GetListOfAllocatedRBs ()->size () << "\n\t\t\t effectiveSinr " << effectiveSinr << "\n\t\t\t tbs " << transportBlockSize << "\n\t\t\t bitsToTransmit " << bitsToTransmit << std::endl; #endif credit[flow->GetBearer ()->GetApplication ()->GetApplicationID()/nbFlows]+=bitsToTransmit; //new add //create PDCCH messages for (int rb = 0; rb < flow->GetListOfAllocatedRBs ()->size (); rb++ ) { pdcchMsg->AddNewRecord (PdcchMapIdealControlMessage::DOWNLINK, flow->GetListOfAllocatedRBs ()->at (rb), flow->GetBearer ()->GetDestination (), mcs); } } } if (pdcchMsg->GetMessage()->size () > 0) { GetMacEntity ()->GetDevice ()->GetPhy ()->SendIdealControlMessage (pdcchMsg); } delete pdcchMsg; for (int i = 0; i< nbUE ; i++ ) //new add { credit[i]-=guarantee_bit; //cout << "credit[" << i << "] = " << credit[i] << endl; } }
void DownlinkPacketScheduler::RBsAllocation () { #ifdef SCHEDULER_DEBUG std::cout << " ---- DownlinkPacketScheduler::RBsAllocation"; #endif FlowsToSchedule* flows = GetFlowsToSchedule (); int nbOfRBs = GetMacEntity ()->GetDevice ()->GetPhy ()->GetBandwidthManager ()->GetDlSubChannels ().size (); //create a matrix of flow metrics double metrics[nbOfRBs][flows->size ()]; for (int i = 0; i < nbOfRBs; i++) { for (int j = 0; j < flows->size (); j++) { metrics[i][j] = ComputeSchedulingMetric (flows->at (j)->GetBearer (), flows->at (j)->GetSpectralEfficiency ().at (i), i); } } #ifdef SCHEDULER_DEBUG std::cout << ", available RBs " << nbOfRBs << ", flows " << flows->size () << std::endl; for (int ii = 0; ii < flows->size (); ii++) { std::cout << "\t metrics for flow " << flows->at (ii)->GetBearer ()->GetApplication ()->GetApplicationID () << ":"; for (int jj = 0; jj < nbOfRBs; jj++) { std::cout << " " << metrics[jj][ii]; } std::cout << std::endl; } #endif AMCModule *amc = GetMacEntity ()->GetAmcModule (); double l_dAllocatedRBCounter = 0; int l_iNumberOfUsers = ((ENodeB*)this->GetMacEntity()->GetDevice())->GetNbOfUserEquipmentRecords(); bool * l_bFlowScheduled = new bool[flows->size ()]; int l_iScheduledFlows = 0; std::vector<double> * l_bFlowScheduledSINR = new std::vector<double>[flows->size ()]; for (int k = 0; k < flows->size (); k++) l_bFlowScheduled[k] = false; //RBs allocation for (int s = 0; s < nbOfRBs; s++) { if (l_iScheduledFlows == flows->size ()) break; double targetMetric = 0; bool RBIsAllocated = false; FlowToSchedule* scheduledFlow; int l_iScheduledFlowIndex = 0; for (int k = 0; k < flows->size (); k++) { if (metrics[s][k] > targetMetric && !l_bFlowScheduled[k] && flows->at (k)->GetDataToTransmit() >0 ) { targetMetric = metrics[s][k]; RBIsAllocated = true; scheduledFlow = flows->at (k); l_iScheduledFlowIndex = k; } } if (RBIsAllocated) { l_dAllocatedRBCounter++; scheduledFlow->GetListOfAllocatedRBs()->push_back (s); // the s RB has been allocated to that flow! #ifdef SCHEDULER_DEBUG std::cout << "\t *** RB " << s << " assigned to the " " flow " << scheduledFlow->GetBearer ()->GetApplication ()->GetApplicationID () << std::endl; #endif double sinr = amc->GetSinrFromCQI (scheduledFlow->GetCqiFeedbacks ().at (s)); l_bFlowScheduledSINR[l_iScheduledFlowIndex].push_back(sinr); double effectiveSinr = GetEesmEffectiveSinr (l_bFlowScheduledSINR[l_iScheduledFlowIndex]); int mcs = amc->GetMCSFromCQI (amc->GetCQIFromSinr (effectiveSinr)); int transportBlockSize = amc->GetTBSizeFromMCS (mcs, scheduledFlow->GetListOfAllocatedRBs ()->size ()); if (transportBlockSize >= scheduledFlow->GetDataToTransmit() * 8) { l_bFlowScheduled[l_iScheduledFlowIndex] = true; l_iScheduledFlows++; } } } delete [] l_bFlowScheduled; delete [] l_bFlowScheduledSINR; //Finalize the allocation PdcchMapIdealControlMessage *pdcchMsg = new PdcchMapIdealControlMessage (); for (FlowsToSchedule::iterator it = flows->begin (); it != flows->end (); it++) { FlowToSchedule *flow = (*it); if (flow->GetListOfAllocatedRBs ()->size () > 0) { //this flow has been scheduled std::vector<double> estimatedSinrValues; for (int rb = 0; rb < flow->GetListOfAllocatedRBs ()->size (); rb++ ) { double sinr = amc->GetSinrFromCQI ( flow->GetCqiFeedbacks ().at (flow->GetListOfAllocatedRBs ()->at (rb))); estimatedSinrValues.push_back (sinr); } //compute the effective sinr double effectiveSinr = GetEesmEffectiveSinr (estimatedSinrValues); //get the MCS for transmission int mcs = amc->GetMCSFromCQI (amc->GetCQIFromSinr (effectiveSinr)); //define the amount of bytes to transmit //int transportBlockSize = amc->GetTBSizeFromMCS (mcs); int transportBlockSize = amc->GetTBSizeFromMCS (mcs, flow->GetListOfAllocatedRBs ()->size ()); double bitsToTransmit = transportBlockSize; flow->UpdateAllocatedBits (bitsToTransmit); #ifdef SCHEDULER_DEBUG std::cout << "\t\t --> flow " << flow->GetBearer ()->GetApplication ()->GetApplicationID () << " has been scheduled: " << "\n\t\t\t nb of RBs " << flow->GetListOfAllocatedRBs ()->size () << "\n\t\t\t effectiveSinr " << effectiveSinr << "\n\t\t\t tbs " << transportBlockSize << "\n\t\t\t bitsToTransmit " << bitsToTransmit << std::endl; #endif //create PDCCH messages for (int rb = 0; rb < flow->GetListOfAllocatedRBs ()->size (); rb++ ) { pdcchMsg->AddNewRecord (PdcchMapIdealControlMessage::DOWNLINK, flow->GetListOfAllocatedRBs ()->at (rb), flow->GetBearer ()->GetDestination (), mcs); } } } if (pdcchMsg->GetMessage()->size () > 0) { GetMacEntity ()->GetDevice ()->GetPhy ()->SendIdealControlMessage (pdcchMsg); } delete pdcchMsg; }