diff --git a/examples/agent-functionalities/CMakeLists.txt b/examples/agent-functionalities/CMakeLists.txt new file mode 100644 index 0000000..077f183 --- /dev/null +++ b/examples/agent-functionalities/CMakeLists.txt @@ -0,0 +1,5 @@ +add_executable(agent-functionalities agent-functionalities.cpp) +ROSA_add_library_dependencies(agent-functionalities ROSAConfig) +ROSA_add_library_dependencies(agent-functionalities ROSACore) +ROSA_add_library_dependencies(agent-functionalities ROSAAgent) + diff --git a/examples/agent-modules/agent-modules.cpp b/examples/agent-functionalities/agent-functionalities.cpp similarity index 91% rename from examples/agent-modules/agent-modules.cpp rename to examples/agent-functionalities/agent-functionalities.cpp index c559136..7e4cf9b 100644 --- a/examples/agent-modules/agent-modules.cpp +++ b/examples/agent-functionalities/agent-functionalities.cpp @@ -1,108 +1,109 @@ -//===-- examples/agent-modules/agent-modules.cpp ----------------*- C++ -*-===// +//===-- examples/agent-functionalities/agent-functionalities.cpp *-- C++-*-===// // // The RoSA Framework // //===----------------------------------------------------------------------===// /// -/// \file examples/agent-modules/agent-modules.cpp +/// \file examples/agent-functionalities/agent-functionalities.cpp /// /// \author David Juhasz (david.juhasz@tuwien.ac.at) /// /// \date 2017 /// /// \brief A simple example on defining \c rosa::Agent instances using -/// \c rosa::agent::Module object as components. +/// \c rosa::agent::Functionality object as components. /// //===----------------------------------------------------------------------===// #include "rosa/agent/Abstraction.hpp" #include "rosa/agent/Confidence.hpp" #include "rosa/config/version.h" #include "rosa/core/Agent.hpp" #include "rosa/core/MessagingSystem.hpp" #include "rosa/support/log.h" #include "rosa/support/terminal_colors.h" #include using namespace rosa; using namespace rosa::agent; using namespace rosa::terminal; /// A dummy wrapper for testing \c rosa::MessagingSystem. /// /// \note Since we test \c rosa::MessagingSystem directly here, we need to get /// access to its protected members. That we do by imitating to be a decent /// subclass of \c rosa::MessagingSystem, while calling protected member /// functions on an object of a type from which we actually don't inherit. struct SystemTester : protected MessagingSystem { template static AgentHandle createMyAgent(MessagingSystem *S, const std::string &Name, Funs &&... Fs) { return ((SystemTester *)S)->createAgent(Name, std::move(Fs)...); } static void destroyMyAgent(MessagingSystem *S, const AgentHandle &H) { ((SystemTester *)S)->destroyUnit(unwrapAgent(H)); } }; /// A special \c rosa::Agent with its own state. class MyAgent : public Agent { public: using Tick = AtomConstant; private: enum class Categories { Bad, Normal, Good }; static const std::map CategoryNames; History H; Confidence C; RangeAbstraction A; public: void handler(Tick, uint8_t V) noexcept { // Record \p V to the \c rosa::agent::History, then print state info. H << V; ASSERT(H.entry() == V); // Sanity check. LOG_INFO_STREAM << "\nNext value: " << PRINTABLE(V) << ", confidence: " << C(H) << ", category: " << CategoryNames.at(A(H.entry())) << '\n'; } MyAgent(const AtomValue Kind, const rosa::id_t Id, const std::string &Name, MessagingSystem &S) : Agent(Kind, Id, Name, S, THISMEMBER(handler)), H(), C(5, 20, 1), A({{{(uint8_t)10, (uint8_t)14}, Categories::Normal}, {{(uint8_t)15, (uint8_t)17}, Categories::Good}, {{(uint8_t)18, (uint8_t)19}, Categories::Normal}}, Categories::Bad) {} }; const std::map MyAgent::CategoryNames{ {Categories::Bad, "Bad"}, {Categories::Normal, "Normal"}, {Categories::Good, "Good"}}; int main(void) { LOG_INFO_STREAM << library_string() << " -- " << Color::Red - << "agent-modules example" << Color::Default << '\n'; + << "agent-functionalities example" << Color::Default + << '\n'; std::unique_ptr S = MessagingSystem::createSystem("Sys"); MessagingSystem *SP = S.get(); AgentHandle A = SystemTester::createMyAgent(SP, "MyAgent"); std::vector Vs{4, 5, 6, 7, 9, 10, 11, 13, 15, 14, 15, 16, 19, 20, 21}; for (auto I = Vs.begin(); I != Vs.end(); ++I) { A.send(MyAgent::Tick::Value, *I); } SystemTester::destroyMyAgent(SP, A); return 0; } diff --git a/examples/agent-modules/CMakeLists.txt b/examples/agent-modules/CMakeLists.txt deleted file mode 100644 index 83c83ac..0000000 --- a/examples/agent-modules/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -add_executable(agent-modules agent-modules.cpp) -ROSA_add_library_dependencies(agent-modules ROSAConfig) -ROSA_add_library_dependencies(agent-modules ROSACore) -ROSA_add_library_dependencies(agent-modules ROSAAgent) -