5G-LENA nr-v3.3-159-ga6832aa7
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-mac-scheduler-ue-info-ai.h
1// Copyright (c) 2024 Seoul National University (SNU)
2// Copyright (c) 2024 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3//
4// SPDX-License-Identifier: GPL-2.0-only
5
6#pragma once
7
8#include "nr-mac-scheduler-ue-info-qos.h"
9
10namespace ns3
11{
28{
29 public:
37 NrMacSchedulerUeInfoAi(float alpha, uint16_t rnti, BeamId beamId, const GetRbPerRbgFn& fn)
38 : NrMacSchedulerUeInfoQos(alpha, rnti, beamId, fn)
39 {
40 }
41
49 typedef std::unordered_map<uint8_t, double> Weights;
57 typedef std::unordered_map<uint8_t, Weights> UeWeightsMap;
58
67 {
68 uint16_t rnti;
69 uint8_t lcId;
70 uint8_t qci;
71 uint8_t priority;
72 uint16_t holDelay;
73 };
74
79 typedef std::function<void(const UeWeightsMap&)> UpdateAllUeWeightsFn;
91 typedef Callback<void,
92 const std::vector<LcObservation>&,
93 bool,
94 float,
95 const std::string&,
98
105 void ResetDlSchedInfo() override
106 {
107 m_weightsDl.clear();
109 }
110
117 void ResetUlSchedInfo() override
118 {
119 m_weightsUl.clear();
121 }
122
132 std::vector<LcObservation> GetDlObservation();
133
143 std::vector<LcObservation> GetUlObservation();
144
154 void UpdateDlWeights(Weights& weights);
155
165 void UpdateUlWeights(Weights& weights);
166
181 float GetDlReward();
182
197 float GetUlReward();
198
211 {
212 double lAiMetric = CalculateDlWeight(lue);
213 double rAiMetric = CalculateDlWeight(rue);
214
215 return (lAiMetric > rAiMetric);
216 }
217
228 {
229 double weight = 0;
230 auto uePtr = dynamic_cast<NrMacSchedulerUeInfoAi*>(ue.first.get());
231
232 for (const auto& ueLcg : ue.first->m_dlLCG)
233 {
234 std::vector<uint8_t> ueActiveLCs = ueLcg.second->GetActiveLCIds();
235
236 for (const auto lcId : ueActiveLCs)
237 {
238 auto it = uePtr->m_weightsDl.find(lcId);
239
240 NS_ASSERT_MSG(it != uePtr->m_weightsDl.end(), "Weight not found for LC " << lcId);
241 weight += it->second;
242 }
243 }
244 return weight;
245 }
246
259 {
260 double lAiMetric = CalculateUlWeight(lue);
261 double rAiMetric = CalculateUlWeight(rue);
262
263 return (lAiMetric > rAiMetric);
264 }
265
276 {
277 double weight = 0;
278 auto uePtr = dynamic_cast<NrMacSchedulerUeInfoAi*>(ue.first.get());
279
280 for (const auto& ueLcg : ue.first->m_ulLCG)
281 {
282 std::vector<uint8_t> ueActiveLCs = ueLcg.second->GetActiveLCIds();
283
284 for (const auto lcId : ueActiveLCs)
285 {
286 auto it = uePtr->m_weightsUl.find(lcId);
287
288 NS_ASSERT_MSG(it != uePtr->m_weightsUl.end(), "Weight not found for LC " << lcId);
289 weight += it->second;
290 }
291 }
292 return weight;
293 }
294
297};
298
299} // namespace ns3
Representation of a beam id.
Definition beam-id.h:26
std::pair< UePtr, uint32_t > UePtrAndBufferReq
Pair between a pointer to NrMacSchedulerUeInfo and its buffer occupancy.
UE representation for a AI-based scheduler.
std::vector< LcObservation > GetUlObservation()
Get the current observation for uplink.
void ResetUlSchedInfo() override
Reset UL AI scheduler info.
static bool CompareUeWeightsUl(const NrMacSchedulerNs3::UePtrAndBufferReq &lue, const NrMacSchedulerNs3::UePtrAndBufferReq &rue)
comparison function object (i.e. an object that satisfies the requirements of Compare) which returns ...
void UpdateUlWeights(Weights &weights)
Update the weights for uplink.
NrMacSchedulerUeInfoAi(float alpha, uint16_t rnti, BeamId beamId, const GetRbPerRbgFn &fn)
NrMacSchedulerUeInfoAi constructor.
void UpdateDlWeights(Weights &weights)
Update the weights for downlink.
std::vector< LcObservation > GetDlObservation()
Get the current observation for downlink.
float GetDlReward()
Get the reward for downlink.
Weights m_weightsDl
Weights assigned to each flow for a UE in the downlink.
static bool CompareUeWeightsDl(const NrMacSchedulerNs3::UePtrAndBufferReq &lue, const NrMacSchedulerNs3::UePtrAndBufferReq &rue)
comparison function object (i.e. an object that satisfies the requirements of Compare) which returns ...
std::unordered_map< uint8_t, double > Weights
A hash map for weights.
static double CalculateUlWeight(const NrMacSchedulerNs3::UePtrAndBufferReq &ue)
Calculate the weight of a UE in the uplink.
void ResetDlSchedInfo() override
Reset DL AI scheduler info.
std::unordered_map< uint8_t, Weights > UeWeightsMap
A hash map for UE weights.
Callback< void, const std::vector< LcObservation > &, bool, float, const std::string &, const UpdateAllUeWeightsFn & > NotifyCb
A callback type for notifying with specific parameters.
float GetUlReward()
Get the reward for uplink.
static double CalculateDlWeight(const NrMacSchedulerNs3::UePtrAndBufferReq &ue)
Calculate the weight of a UE in the downlink.
std::function< void(const UeWeightsMap &)> UpdateAllUeWeightsFn
A function type for updating the weights of all UEs.
Weights m_weightsUl
Weights assigned to each flow for a UE in the uplink.
UE representation for a QoS-based scheduler.
void ResetUlSchedInfo() override
Reset UL QoS scheduler info.
void ResetDlSchedInfo() override
Reset DL QoS scheduler info.