6#include "nr-mac-scheduler-tdma-ai.h"
8#include "ns3/boolean.h"
9#include "ns3/callback.h"
18NS_LOG_COMPONENT_DEFINE(
"NrMacSchedulerTdmaAi");
19NS_OBJECT_ENSURE_REGISTERED(NrMacSchedulerTdmaAi);
25 TypeId(
"ns3::NrMacSchedulerTdmaAi")
27 .AddConstructor<NrMacSchedulerTdmaAi>()
28 .AddAttribute(
"NotifyCbDl",
29 "The callback function to notify the AI model for the downlink",
30 CallbackValue(MakeNullCallback<NrMacSchedulerUeInfoAi::NotifyCb>()),
31 MakeCallbackAccessor(&NrMacSchedulerTdmaAi::m_notifyCbDl),
32 MakeCallbackChecker())
33 .AddAttribute(
"NotifyCbUl",
34 "The callback function to notify the AI model for the uplink",
35 CallbackValue(MakeNullCallback<NrMacSchedulerUeInfoAi::NotifyCb>()),
36 MakeCallbackAccessor(&NrMacSchedulerTdmaAi::m_notifyCbUl),
37 MakeCallbackChecker())
38 .AddAttribute(
"ActiveDlAi",
39 "The flag to activate the AI model for the downlink",
43 .AddAttribute(
"ActiveUlAi",
44 "The flag to activate the AI model for the uplink",
47 MakeBooleanChecker());
56std::shared_ptr<NrMacSchedulerUeInfo>
60 NS_LOG_FUNCTION(
this);
61 return std::make_shared<NrMacSchedulerUeInfoAi>(
93 NS_LOG_FUNCTION(
this);
94 m_notifyCbDl = notifyCb;
101 NS_LOG_FUNCTION(
this);
102 m_notifyCbUl = notifyCb;
106std::vector<NrMacSchedulerUeInfoAi::LcObservation>
108 const std::vector<NrMacSchedulerNs3::UePtrAndBufferReq>& ueVector)
const
110 NS_LOG_FUNCTION(
this);
111 std::vector<NrMacSchedulerUeInfoAi::LcObservation> observations;
112 for (
const auto& ue : ueVector)
114 auto uePtr = std::dynamic_pointer_cast<NrMacSchedulerUeInfoAi>(ue.first);
115 std::vector<NrMacSchedulerUeInfoAi::LcObservation> ueObservation =
116 uePtr->GetDlObservation();
117 observations.insert(observations.end(), ueObservation.begin(), ueObservation.end());
122std::vector<NrMacSchedulerUeInfoAi::LcObservation>
124 const std::vector<NrMacSchedulerNs3::UePtrAndBufferReq>& ueVector)
const
126 NS_LOG_FUNCTION(
this);
127 std::vector<NrMacSchedulerUeInfoAi::LcObservation> observations;
128 for (
const auto& ue : ueVector)
130 auto uePtr = std::dynamic_pointer_cast<NrMacSchedulerUeInfoAi>(ue.first);
131 std::vector<NrMacSchedulerUeInfoAi::LcObservation> ueObservation =
132 uePtr->GetUlObservation();
133 observations.insert(observations.end(), ueObservation.begin(), ueObservation.end());
152 const std::vector<NrMacSchedulerNs3::UePtrAndBufferReq>& ueVector)
const
154 NS_LOG_FUNCTION(
this);
156 for (
const auto& ue : ueVector)
158 auto uePtr = std::dynamic_pointer_cast<NrMacSchedulerUeInfoAi>(ue.first);
159 reward += uePtr->GetDlReward();
166 const std::vector<NrMacSchedulerNs3::UePtrAndBufferReq>& ueVector)
const
168 NS_LOG_FUNCTION(
this);
170 for (
const auto& ue : ueVector)
172 auto uePtr = std::dynamic_pointer_cast<NrMacSchedulerUeInfoAi>(ue.first);
173 reward += uePtr->GetUlReward();
180 const std::vector<NrMacSchedulerNs3::UePtrAndBufferReq>& ueVector)
const
182 NS_LOG_FUNCTION(
this);
183 if (!m_notifyCbDl.IsNull())
185 std::string extraInfo =
"";
189 std::placeholders::_1,
201 const std::vector<NrMacSchedulerNs3::UePtrAndBufferReq>& ueVector)
const
203 NS_LOG_FUNCTION(
this);
204 if (!m_notifyCbUl.IsNull())
206 std::string extraInfo =
"";
210 std::placeholders::_1,
223 const std::vector<NrMacSchedulerNs3::UePtrAndBufferReq>& ueVector)
const
225 NS_LOG_FUNCTION(
this);
226 for (
const auto& ue : ueVector)
228 auto uePtr = std::dynamic_pointer_cast<NrMacSchedulerUeInfoAi>(ue.first);
230 uePtr->UpdateDlWeights(weights);
237 const std::vector<NrMacSchedulerNs3::UePtrAndBufferReq>& ueVector)
const
239 NS_LOG_FUNCTION(
this);
240 for (
const auto& ue : ueVector)
242 auto uePtr = std::dynamic_pointer_cast<NrMacSchedulerUeInfoAi>(ue.first);
244 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.
NrMacSchedulerTdmaAi()
NrMacSchedulerTdma constructor.
std::shared_ptr< NrMacSchedulerUeInfo > CreateUeRepresentation(const NrMacCschedSapProvider::CschedUeConfigReqParameters ¶ms) const override
Create an UE representation of the type NrMacSchedulerUeInfoAi.
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.
void UpdateAllUeWeightsDl(const NrMacSchedulerUeInfoAi::UeWeightsMap &ueWeights, const std::vector< NrMacSchedulerNs3::UePtrAndBufferReq > &ueVector) const
Update weights of all UEs for downlink.
bool GetIsGameOverUl() const
Check if the uplink game is over.
void UpdateAllUeWeightsUl(const NrMacSchedulerUeInfoAi::UeWeightsMap &ueWeights, const std::vector< NrMacSchedulerNs3::UePtrAndBufferReq > &ueVector) const
Update weights of all UEs for uplink.
float GetUeRewardsDl(const std::vector< NrMacSchedulerNs3::UePtrAndBufferReq > &ueVector) const
Get rewards 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.
static TypeId GetTypeId()
GetTypeId.
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.
void SetNotifyCbDl(NrMacSchedulerUeInfoAi::NotifyCb notifyCb)
Set the notify callback function for downlink.
std::vector< NrMacSchedulerUeInfoAi::LcObservation > GetUeObservationsDl(const std::vector< NrMacSchedulerNs3::UePtrAndBufferReq > &ueVector) const
Get UE observations for downlink.
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.
bool GetIsGameOverDl() const
Check if the downlink game is over.
std::vector< NrMacSchedulerUeInfoAi::LcObservation > GetUeObservationsUl(const std::vector< NrMacSchedulerNs3::UePtrAndBufferReq > &ueVector) const
Get UE observations for uplink.
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.
Assign entire symbols in a 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 ...