From 32b39900ba2a52a4d7a83d80fbf222ffa5243546 Mon Sep 17 00:00:00 2001 From: Liudvikas Date: Thu, 25 Apr 2024 13:36:46 +0000 Subject: [PATCH 1/2] feat: add GetKey method to dict container --- model/gym-interface/cpp/container.cc | 13 +++++++++++++ model/gym-interface/cpp/container.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/model/gym-interface/cpp/container.cc b/model/gym-interface/cpp/container.cc index 88a643f..56b774f 100644 --- a/model/gym-interface/cpp/container.cc +++ b/model/gym-interface/cpp/container.cc @@ -332,6 +332,19 @@ OpenGymTupleContainer::Print(std::ostream& where) const where << ")"; } +std::vector +OpenGymDictContainer::GetKeys() +{ + std::vector keys; + for (std::map>::iterator it = m_dict.begin(); + it != m_dict.end(); + ++it) + { + keys.push_back(it->first); + } + return keys; +} + TypeId OpenGymDictContainer::GetTypeId() { diff --git a/model/gym-interface/cpp/container.h b/model/gym-interface/cpp/container.h index 5577d11..05f64c4 100644 --- a/model/gym-interface/cpp/container.h +++ b/model/gym-interface/cpp/container.h @@ -336,6 +336,8 @@ class OpenGymDictContainer : public OpenGymDataContainer void Print(std::ostream& where) const override; + std::vector GetKeys(); + friend std::ostream& operator<<(std::ostream& os, const Ptr container) { container->Print(os); From 7fea11769e60c135f03c92b6a4033fc91c13e8a0 Mon Sep 17 00:00:00 2001 From: OliverZim Date: Sun, 9 Jun 2024 22:21:11 +0000 Subject: [PATCH 2/2] feat: allow setting specific value in box container --- model/gym-interface/cpp/container.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/model/gym-interface/cpp/container.h b/model/gym-interface/cpp/container.h index 05f64c4..98f7099 100644 --- a/model/gym-interface/cpp/container.h +++ b/model/gym-interface/cpp/container.h @@ -26,6 +26,7 @@ #include #include +#include namespace ns3 { @@ -106,7 +107,7 @@ class OpenGymBoxContainer : public OpenGymDataContainer container->Print(os); return os; } - + void SetValue(uint32_t idx, T value); bool AddValue(T value); T GetValue(uint32_t idx); @@ -243,6 +244,16 @@ OpenGymBoxContainer::AddValue(T value) return true; } +template +void +OpenGymBoxContainer::SetValue(uint32_t idx, T value) +{ + if (idx < m_data.size()) + { + m_data[idx] = value; + } +} + template T OpenGymBoxContainer::GetValue(uint32_t idx)