6#include "nr-mac-scheduler-ofdma-ai.h"
8#include "ns3/boolean.h"
16NS_LOG_COMPONENT_DEFINE(
"NrMacSchedulerOfdmaAi");
17NS_OBJECT_ENSURE_REGISTERED(NrMacSchedulerOfdmaAi);
23 TypeId(
"ns3::NrMacSchedulerOfdmaAi")
25 .AddConstructor<NrMacSchedulerOfdmaAi>()
26 .AddAttribute(
"NotifyCbDl",
27 "The callback function to notify the AI model for the downlink",
28 CallbackValue(MakeNullCallback<NrMacSchedulerUeInfoAi::NotifyCb>()),
29 MakeCallbackAccessor(&NrMacSchedulerOfdmaAi::m_notifyCbDl),
30 MakeCallbackChecker())
31 .AddAttribute(
"NotifyCbUl",
32 "The callback function to notify the AI model for the uplink",
33 CallbackValue(MakeNullCallback<NrMacSchedulerUeInfoAi::NotifyCb>()),
34 MakeCallbackAccessor(&NrMacSchedulerOfdmaAi::m_notifyCbUl),
35 MakeCallbackChecker())
36 .AddAttribute(
"ActiveDlAi",
37 "The flag to activate the AI model for the downlink",
41 .AddAttribute(
"ActiveUlAi",
42 "The flag to activate the AI model for the uplink",
45 MakeBooleanChecker());
54std::shared_ptr<NrMacSchedulerUeInfo>
58 NS_LOG_FUNCTION(
this);
59 return std::make_shared<NrMacSchedulerUeInfoAi>(
91 NS_LOG_FUNCTION(
this);
92 m_notifyCbDl = notifyCb;
99 NS_LOG_FUNCTION(
this);
100 m_notifyCbUl = notifyCb;
104std::vector<NrMacSchedulerUeInfoAi::LcObservation>
106 const std::vector<NrMacSchedulerNs3::UePtrAndBufferReq>& ueVector)
const
108 NS_LOG_FUNCTION(
this);
109 std::vector<NrMacSchedulerUeInfoAi::LcObservation> observations;
110 for (
const auto& ue : ueVector)
112 auto uePtr = std::dynamic_pointer_cast<NrMacSchedulerUeInfoAi>(ue.first);
113 std::vector<NrMacSchedulerUeInfoAi::LcObservation> ueObservation =
114 uePtr->GetDlObservation();
115 observations.insert(observations.end(), ueObservation.begin(), ueObservation.end());
120std::vector<NrMacSchedulerUeInfoAi::LcObservation>
122 const std::vector<NrMacSchedulerNs3::UePtrAndBufferReq>& ueVector)
const
124 NS_LOG_FUNCTION(
this);
125 std::vector<NrMacSchedulerUeInfoAi::LcObservation> observations;
126 for (
const auto& ue : ueVector)
128 auto uePtr = std::dynamic_pointer_cast<NrMacSchedulerUeInfoAi>(ue.first);
129 std::vector<NrMacSchedulerUeInfoAi::LcObservation> ueObservation =
130 uePtr->GetUlObservation();
131 observations.insert(observations.end(), ueObservation.begin(), ueObservation.end());
150 const std::vector<NrMacSchedulerNs3::UePtrAndBufferReq>& ueVector)
const
152 NS_LOG_FUNCTION(
this);
154 for (
const auto& ue : ueVector)
156 auto uePtr = std::dynamic_pointer_cast<NrMacSchedulerUeInfoAi>(ue.first);
157 reward += uePtr->GetDlReward();
164 const std::vector<NrMacSchedulerNs3::UePtrAndBufferReq>& ueVector)
const
166 NS_LOG_FUNCTION(
this);
168 for (
const auto& ue : ueVector)
170 auto uePtr = std::dynamic_pointer_cast<NrMacSchedulerUeInfoAi>(ue.first);
171 reward += uePtr->GetUlReward();
178 const std::vector<NrMacSchedulerNs3::UePtrAndBufferReq>& ueVector)
const
180 NS_LOG_FUNCTION(
this);
181 if (!m_notifyCbDl.IsNull())
183 std::string extraInfo =
"";
187 std::placeholders::_1,
199 const std::vector<NrMacSchedulerNs3::UePtrAndBufferReq>& ueVector)
const
201 NS_LOG_FUNCTION(
this);
202 if (!m_notifyCbUl.IsNull())
204 std::string extraInfo =
"";
208 std::placeholders::_1,
221 const std::vector<NrMacSchedulerNs3::UePtrAndBufferReq>& ueVector)
const
223 NS_LOG_FUNCTION(
this);
224 for (
const auto& ue : ueVector)
226 auto uePtr = std::dynamic_pointer_cast<NrMacSchedulerUeInfoAi>(ue.first);
228 uePtr->UpdateDlWeights(weights);
235 const std::vector<NrMacSchedulerNs3::UePtrAndBufferReq>& ueVector)
const
237 NS_LOG_FUNCTION(
this);
238 for (
const auto& ue : ueVector)
240 auto uePtr = std::dynamic_pointer_cast<NrMacSchedulerUeInfoAi>(ue.first);
242 uePtr->UpdateUlWeights(weights);
bool m_activeUlAi
Flag for activating AI for uplink.
bool m_activeDlAi
Flag for activating AI for downlink.
uint64_t GetNumRbPerRbg() const
Private function that is used to get the number of resource blocks per resource block group and also ...
std::pair< UePtr, uint32_t > UePtrAndBufferReq
Pair between a pointer to NrMacSchedulerUeInfo and its buffer occupancy.
bool GetIsGameOverUl() const
Check if the uplink game is over.
float GetUeRewardsDl(const std::vector< NrMacSchedulerNs3::UePtrAndBufferReq > &ueVector) const
Get rewards for downlink.
void SetNotifyCbDl(NrMacSchedulerUeInfoAi::NotifyCb notifyCb)
Set the notify callback function for downlink.
std::vector< NrMacSchedulerUeInfoAi::LcObservation > GetUeObservationsUl(const std::vector< NrMacSchedulerNs3::UePtrAndBufferReq > &ueVector) const
Get UE observations for uplink.
void UpdateAllUeWeightsDl(const NrMacSchedulerUeInfoAi::UeWeightsMap &ueWeights, const std::vector< NrMacSchedulerNs3::UePtrAndBufferReq > &ueVector) const
Update weights of all UEs for downlink.
std::function< bool(const NrMacSchedulerNs3::UePtrAndBufferReq &lhs, const NrMacSchedulerNs3::UePtrAndBufferReq &rhs)> GetUeCompareUlFn() const override
Return the comparison function to sort UL UEs according to the scheduler policy.
float GetUeRewardsUl(const std::vector< NrMacSchedulerNs3::UePtrAndBufferReq > &ueVector) const
Get rewards for uplink.
void SetNotifyCbUl(NrMacSchedulerUeInfoAi::NotifyCb notifyCb)
Set the notify callback function for uplink.
bool GetIsGameOverDl() const
Check if the downlink game is over.
std::function< bool(const NrMacSchedulerNs3::UePtrAndBufferReq &lhs, const NrMacSchedulerNs3::UePtrAndBufferReq &rhs)> GetUeCompareDlFn() const override
Return the comparison function to sort DL UEs according to the scheduler policy.
std::shared_ptr< NrMacSchedulerUeInfo > CreateUeRepresentation(const NrMacCschedSapProvider::CschedUeConfigReqParameters ¶ms) const override
Create an UE representation of the type NrMacSchedulerUeInfoAi.
static TypeId GetTypeId()
GetTypeId.
void UpdateAllUeWeightsUl(const NrMacSchedulerUeInfoAi::UeWeightsMap &ueWeights, const std::vector< NrMacSchedulerNs3::UePtrAndBufferReq > &ueVector) const
Update weights of all UEs for uplink.
std::vector< NrMacSchedulerUeInfoAi::LcObservation > GetUeObservationsDl(const std::vector< NrMacSchedulerNs3::UePtrAndBufferReq > &ueVector) const
Get UE observations for downlink.
void CallNotifyUlFn(const std::vector< NrMacSchedulerNs3::UePtrAndBufferReq > &ueVector) const override
Call the notify callback function in the OpenGymEnv class in the ns3-gym module for uplink.
void CallNotifyDlFn(const std::vector< NrMacSchedulerNs3::UePtrAndBufferReq > &ueVector) const override
Call the notify callback function in the OpenGymEnv class in the ns3-gym module for downlink.
NrMacSchedulerOfdmaAi()
NrMacSchedulerOfdmaAi constructor.
Assign frequencies in QoS-based fashion.
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 ...
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.
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.
std::function< void(const UeWeightsMap &)> UpdateAllUeWeightsFn
A function type for updating the weights of all UEs.
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 ...
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 ...