From c8655541e6043b18a472bff23f61b54cb00b3323 Mon Sep 17 00:00:00 2001 From: FyS Date: Mon, 20 Nov 2023 20:13:44 +0100 Subject: [PATCH] change code positin --- fabko/CMakeLists.txt | 36 ++++---- fabko/agent/agent.hh | 20 ++--- fabko/{core => agent}/blackboard.cpp | 7 +- fabko/{core => agent}/blackboard.hh | 0 fabko/{core => agent/protocol}/acl.hh | 0 fabko/agent/protocol/boardcom.hh | 82 +++++++++++++++++++ fabko/agent/protocol/boardcom_local.cpp | 38 +++++++++ .../protocol/boardcom_p2p.cpp} | 14 +--- fabko/{core => agent}/protocol/fap_request.hh | 0 fabko/core/boardcom.hh | 80 ------------------ fabko/core/logic/formula.cpp | 10 +-- fabko/core/protocol/boardcom.cpp | 33 -------- fabko/core/protocol/boardcom.hh | 70 ---------------- fabko/peerboard/peerboard.hh | 2 +- tests/CMakeLists.txt | 21 ++++- tests/{core => agent}/test_acl.cpp | 4 +- 16 files changed, 177 insertions(+), 240 deletions(-) rename fabko/{core => agent}/blackboard.cpp (81%) rename fabko/{core => agent}/blackboard.hh (100%) rename fabko/{core => agent/protocol}/acl.hh (100%) create mode 100755 fabko/agent/protocol/boardcom.hh create mode 100644 fabko/agent/protocol/boardcom_local.cpp rename fabko/{core/boardcom.cpp => agent/protocol/boardcom_p2p.cpp} (59%) mode change 100644 => 100755 rename fabko/{core => agent}/protocol/fap_request.hh (100%) delete mode 100644 fabko/core/boardcom.hh delete mode 100755 fabko/core/protocol/boardcom.cpp delete mode 100755 fabko/core/protocol/boardcom.hh rename tests/{core => agent}/test_acl.cpp (98%) diff --git a/fabko/CMakeLists.txt b/fabko/CMakeLists.txt index 4404b77..a686786 100644 --- a/fabko/CMakeLists.txt +++ b/fabko/CMakeLists.txt @@ -6,18 +6,13 @@ cmake_minimum_required(VERSION 3.22) add_library(core STATIC) target_sources(core PUBLIC - core/blackboard.cpp - core/blackboard.hh - core/acl.hh - core/protocol/fap_request.hh - core/protocol/boardcom.cpp - core/protocol/boardcom.hh core/common/logging.cpp core/common/logging.hh core/common/exception.hh core/common/ranges_to.hh core/common/visitor_utils.hh core/common/string_utils.hh + # SAT solving logic (not sure its ever going to be useful) core/logic/formula.cpp core/logic/formula.hh core/logic/sat/dimacs_compiler.cpp @@ -27,20 +22,21 @@ target_sources(core PRIVATE core/logic/sat/helpers.hh core/logic/sat/helpers.cpp - ) +) target_include_directories(core PRIVATE ${RocksDB_INCLUDE_DIR} PUBLIC core - ) +) target_compile_definitions(core PUBLIC cxx_std_23) target_link_libraries(core PUBLIC RocksDB::rocksdb fmt::fmt PRIVATE spdlog::spdlog - nlohmann_json::nlohmann_json) + nlohmann_json::nlohmann_json +) add_library(fabko::core ALIAS core) # @@ -48,14 +44,20 @@ add_library(fabko::core ALIAS core) # add_library(agent OBJECT) target_sources(agent + PUBLIC + agent/agent.hh + agent/action.hh + agent/protocol/acl.hh + agent/protocol/fap_request.hh + agent/protocol/boardcom.hh PRIVATE agent/agent.cpp - agent/action.hh - PUBLIC - agent/agent.hh) -target_include_directories(agent PUBLIC - agent - ) + agent/blackboard.cpp + agent/blackboard.hh + agent/protocol/boardcom_local.cpp + agent/protocol/boardcom_p2p.cpp +) +target_include_directories(agent PUBLIC agent) target_compile_definitions(agent PUBLIC cxx_std_23) target_link_libraries(agent PRIVATE fabko::core) add_library(fabko::agent ALIAS agent) @@ -77,7 +79,7 @@ target_include_directories(peerboard PUBLIC peerboard datastore core - ) +) target_link_libraries(peerboard PRIVATE fabko::agent fabko::core) target_compile_definitions(peerboard PUBLIC cxx_std_23) add_library(fabko::peerboard ALIAS peerboard) @@ -91,7 +93,7 @@ add_executable(fabko) target_sources(fabko PRIVATE fabko.cpp - ) +) target_include_directories(fabko PUBLIC include) target_link_libraries(fabko PRIVATE fabko::peerboard) target_compile_definitions(fabko PUBLIC cxx_std_23) diff --git a/fabko/agent/agent.hh b/fabko/agent/agent.hh index 2475912..3d18b30 100644 --- a/fabko/agent/agent.hh +++ b/fabko/agent/agent.hh @@ -13,36 +13,32 @@ #pragma once #include -#include #include +#include +#include namespace fabko { -template class agent { struct impl; public: - ~agent() = default; - - // extract requirement of the type on a static assertion as agent symbol is not available to the compiler at the - // template declaration level. - static_assert( - std::is_invocable_v, - "The action function provided to the agent has to be with the following signature: void(agent&)"); + template + requires std::is_invocable_v + explicit agent(action func) : _callback_on_action(std::move(func)) {} + ~agent() = default; - [[nodiscard]] std::expected<> + // [[nodiscard]] std::expected<>; private: void execute_action() { _callback_on_action(*this); } - action _callback_on_action; + std::function _callback_on_action; std::unique_ptr _pimpl; - }; } // namespace fabko \ No newline at end of file diff --git a/fabko/core/blackboard.cpp b/fabko/agent/blackboard.cpp similarity index 81% rename from fabko/core/blackboard.cpp rename to fabko/agent/blackboard.cpp index 42a6f41..8116f35 100644 --- a/fabko/core/blackboard.cpp +++ b/fabko/agent/blackboard.cpp @@ -12,15 +12,12 @@ #include #include "blackboard.hh" -#include +#include "common/visitor_utils.hh" namespace fabko { struct blackboard::blackboard_impl { - explicit blackboard_impl(agent_protocol::c_board_com auto&& bc, blackboard_data data) - : bc(std::forward(bc)), data(std::move(data)) {} - blackboard_data instantiate_black_board(const std::string& request) { std::visit( overloaded{[&request](auto& b) -> std::string { return b.instantiate_black_board(request); }}, bc); @@ -35,7 +32,7 @@ blackboard::~blackboard() = default; template blackboard::blackboard(BoardCommunication&& bc, agent_protocol::request initial_request) - : _pimpl(std::forward(bc), {.initial_request = std::move(initial_request)}) { + : _pimpl{std::forward(bc), {.initial_request = std::move(initial_request)}} { } agent_protocol::propositions blackboard::request_propositions(const agent_protocol::request& request) { diff --git a/fabko/core/blackboard.hh b/fabko/agent/blackboard.hh similarity index 100% rename from fabko/core/blackboard.hh rename to fabko/agent/blackboard.hh diff --git a/fabko/core/acl.hh b/fabko/agent/protocol/acl.hh similarity index 100% rename from fabko/core/acl.hh rename to fabko/agent/protocol/acl.hh diff --git a/fabko/agent/protocol/boardcom.hh b/fabko/agent/protocol/boardcom.hh new file mode 100755 index 0000000..ecb5fb9 --- /dev/null +++ b/fabko/agent/protocol/boardcom.hh @@ -0,0 +1,82 @@ +// Dual Licensing Either : +// - AGPL +// or +// - Subscription license for commercial usage (without requirement of licensing propagation). +// please contact ballandfys@protonmail.com for additional information about this subscription commercial licensing. +// +// Created by FyS on 23/04/23. License 2022-2023 +// +// In the case no license has been purchased for the use (modification or distribution in any way) of the software stack +// the APGL license is applying. +// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include "fap_request.hh" + +namespace fabko::agent_protocol { + +struct proposition { + std::string id; +}; + +struct propositions { + std::optional> props; + status st{status::awaiting}; +}; + +enum class decision_status { + SUCCESS, + RETRY, + CANCELLED, +}; + +/** + * + * @tparam T + */ +template +concept c_board_com = + requires(T a) { + { T::make_board(request{}) } -> std::convertible_to; + { a.propositions(std::string{}) } -> std::convertible_to>; + { a.commit_decision(std::string{}) } -> std::convertible_to; + } && std::movable; + +namespace p2p { +class board_protocol { + public: + static std::string instantiate_black_board(const std::string&); + std::future request_propositions(const std::string&); + decision_status commit_decision(const std::string&); +}; +} // namespace p2p + +namespace local { +class board_protocol { + struct impl; + + public: + ~board_protocol(); + board_protocol(); + + static std::string instantiate_black_board(const std::string&); + std::future request_propositions(const std::string&); + decision_status commit_decision(const std::string&); + + private: + std::unique_ptr _impl; + }; +} // namespace local + +using board_protocol = std::variant; + +} // namespace fabko::agent_protocol diff --git a/fabko/agent/protocol/boardcom_local.cpp b/fabko/agent/protocol/boardcom_local.cpp new file mode 100644 index 0000000..107c855 --- /dev/null +++ b/fabko/agent/protocol/boardcom_local.cpp @@ -0,0 +1,38 @@ +// - AGPL +// or +// - Subscription license for commercial usage (without requirement of licensing propagation). +// please contact ballandfys@protonmail.com for additional information about this subscription commercial licensing. +// +// Created by FyS on 23/04/23. License 2022-2023 +// +// In the case no license has been purchased for the use (modification or distribution in any way) of the software stack +// the APGL license is applying. + +#include + +#include "boardcom.hh" + +namespace fabko::agent_protocol::local { + +struct board_protocol::impl { + std::vector> _agent_ring; +}; + +board_protocol::~board_protocol() = default; + +std::string board_protocol::instantiate_black_board(const std::string&) { + return {}; +} + +std::future board_protocol::request_propositions(const std::string&) { + return std::future(); +} + +agent_protocol::decision_status board_protocol::commit_decision(const std::string&) { + return agent_protocol::decision_status::RETRY; +} + +board_protocol::board_protocol(): _impl(std::make_unique()) { +} + +} \ No newline at end of file diff --git a/fabko/core/boardcom.cpp b/fabko/agent/protocol/boardcom_p2p.cpp old mode 100644 new mode 100755 similarity index 59% rename from fabko/core/boardcom.cpp rename to fabko/agent/protocol/boardcom_p2p.cpp index a779d7f..dd2b372 --- a/fabko/core/boardcom.cpp +++ b/fabko/agent/protocol/boardcom_p2p.cpp @@ -12,22 +12,14 @@ #include "boardcom.hh" -namespace fabko { +namespace fabko::agent_protocol::p2p { -std::string com::p2p::instantiate_black_board(const std::string&) { +std::string board_protocol::instantiate_black_board(const std::string&) { return {}; } -std::string com::online::instantiate_black_board(const std::string&) { +std::future board_protocol::request_propositions(const std::string&) { return {}; } -std::future com::online::request_propositions(const std::string&) { - return {}; -} - -com::decision_status com::online::commit_decision(const std::string&) { - return com::decision_status::RETRY; -} - } // namespace fabko diff --git a/fabko/core/protocol/fap_request.hh b/fabko/agent/protocol/fap_request.hh similarity index 100% rename from fabko/core/protocol/fap_request.hh rename to fabko/agent/protocol/fap_request.hh diff --git a/fabko/core/boardcom.hh b/fabko/core/boardcom.hh deleted file mode 100644 index c12ec0f..0000000 --- a/fabko/core/boardcom.hh +++ /dev/null @@ -1,80 +0,0 @@ -// Dual Licensing Either : -// - AGPL -// or -// - Subscription license for commercial usage (without requirement of licensing propagation). -// please contact ballandfys@protonmail.com for additional information about this subscription commercial licensing. -// -// Created by FyS on 23/04/23. License 2022-2023 -// -// In the case no license has been purchased for the use (modification or distribution in any way) of the software stack -// the APGL license is applying. -// - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace fabko::com { - -struct proposition { - std::string id; -}; - -enum class request_process : int { - INIT = 0, - IN_PROGRESS = 1, - DONE = 2, - WONT_DO = 3, -}; - -struct propositions { - std::optional> props; - request_process status{request_process::INIT}; -}; - -enum class decision_status { - SUCCESS, - RETRY, - CANCELLED, -}; - -struct request { - std::string emitter; - std::string request; - std::uint16_t result_requested{1}; -}; - -/** - * - * @tparam T - */ -template -concept c_board_com = - requires(T a) { - { T::make_board(request{}) } -> std::same_as; - { a.propositions(std::string{}) } -> std::same_as>; - { a.commit_decision(std::string{}) } -> std::same_as; - } && std::movable; - -class p2p { -public: - static std::string instantiate_black_board(const std::string&); - std::future request_propositions(const std::string&); - decision_status commit_decision(const std::string&); -}; - -class online { -public: - static std::string instantiate_black_board(const std::string&); - std::future request_propositions(const std::string&); - decision_status commit_decision(const std::string&); -}; - -using board_protocol = std::variant; - -} // namespace fabko::com diff --git a/fabko/core/logic/formula.cpp b/fabko/core/logic/formula.cpp index e7c78cf..712a571 100644 --- a/fabko/core/logic/formula.cpp +++ b/fabko/core/logic/formula.cpp @@ -15,8 +15,8 @@ #include #include -#include #include +#include #include "common/exception.hh" #include "common/visitor_utils.hh" @@ -128,19 +128,19 @@ std::span set::operator[](unsigned index_begin, unsigned index_end) { _set_var.begin() + static_cast(index_end)}; } -variable& conj(variable& var, std::vector token) { +variable& conj(variable& var, std::vector) { return var; } -variable& disj(variable& var, std::vector token) { +variable& disj(variable& var, std::vector) { return var; } -std::span conj(std::span vars, std::vector token) { +std::span conj(std::span vars, std::vector) { return vars; } -std::span disj(std::span vars, std::vector token) { +std::span disj(std::span vars, std::vector) { return vars; } } // namespace fabko::logic \ No newline at end of file diff --git a/fabko/core/protocol/boardcom.cpp b/fabko/core/protocol/boardcom.cpp deleted file mode 100755 index 6a9b26e..0000000 --- a/fabko/core/protocol/boardcom.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Dual Licensing Either : -// - AGPL -// or -// - Subscription license for commercial usage (without requirement of licensing propagation). -// please contact ballandfys@protonmail.com for additional information about this subscription commercial licensing. -// -// Created by FyS on 23/04/23. License 2022-2023 -// -// In the case no license has been purchased for the use (modification or distribution in any way) of the software stack -// the APGL license is applying. -// - -#include "boardcom.hh" - -namespace fabko { - -std::string agent_protocol::p2p::instantiate_black_board(const std::string&) { - return {}; -} - -std::string agent_protocol::online::instantiate_black_board(const std::string&) { - return {}; -} - -std::future agent_protocol::online::request_propositions(const std::string&) { - return {}; -} - -agent_protocol::decision_status agent_protocol::online::commit_decision(const std::string&) { - return agent_protocol::decision_status::RETRY; -} - -} // namespace fabko diff --git a/fabko/core/protocol/boardcom.hh b/fabko/core/protocol/boardcom.hh deleted file mode 100755 index 98672c8..0000000 --- a/fabko/core/protocol/boardcom.hh +++ /dev/null @@ -1,70 +0,0 @@ -// Dual Licensing Either : -// - AGPL -// or -// - Subscription license for commercial usage (without requirement of licensing propagation). -// please contact ballandfys@protonmail.com for additional information about this subscription commercial licensing. -// -// Created by FyS on 23/04/23. License 2022-2023 -// -// In the case no license has been purchased for the use (modification or distribution in any way) of the software stack -// the APGL license is applying. -// - -#pragma once - -#include -#include -#include -#include -#include -#include - -#include "fap_request.hh" - -namespace fabko::agent_protocol { - -struct proposition { - std::string id; -}; - -struct propositions { - std::optional> props; - status status{status::awaiting}; -}; - -enum class decision_status { - SUCCESS, - RETRY, - CANCELLED, -}; - - -/** - * - * @tparam T - */ -template -concept c_board_com = - requires(T a) { - { T::make_board(request{}) } -> std::convertible_to; - { a.propositions(std::string{}) } -> std::convertible_to>; - { a.commit_decision(std::string{}) } -> std::convertible_to; - } && std::movable; - -class p2p { -public: - static std::string instantiate_black_board(const std::string&); - std::future request_propositions(const std::string&); - decision_status commit_decision(const std::string&); -}; - -class online { -public: - static std::string instantiate_black_board(const std::string&); - std::future request_propositions(const std::string&); - decision_status commit_decision(const std::string&); -}; - -using board_protocol = std::variant; - -} // namespace fabko::com diff --git a/fabko/peerboard/peerboard.hh b/fabko/peerboard/peerboard.hh index 018dc44..60939aa 100644 --- a/fabko/peerboard/peerboard.hh +++ b/fabko/peerboard/peerboard.hh @@ -17,7 +17,7 @@ #include #include -#include +#include "blackboard.hh" namespace fabko { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 62dfbc1..b8266fa 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,20 +13,33 @@ add_executable(test_datastore) target_sources(test_datastore PRIVATE peerboard/test_kv_rocksdb.cpp - ) +) target_compile_definitions(test_datastore PUBLIC cxx_std_23) target_link_libraries(test_datastore PRIVATE Catch2::Catch2WithMain fabko::peerboard) catch_discover_tests(test_datastore) +# Test of the Agent +# +# +add_executable(test_agent) +target_sources(test_agent + PRIVATE + agent/test_acl.cpp +) +target_compile_definitions(test_agent PUBLIC cxx_std_23) +target_link_libraries(test_agent + PRIVATE Catch2::Catch2WithMain fabko::agent) + +catch_discover_tests(test_agent) + # Test of the core # add_executable(test_core) target_sources(test_core PRIVATE - core/test_acl.cpp core/common/test_assignment_bitset.cpp core/common/test_algo_utils.cpp core/sat/test_formula.cpp @@ -34,8 +47,8 @@ target_sources(test_core core/sat/test_dimacs_compiler.cpp core/sat/test_basic_sat.cpp core/sat/test_sat_coloring.cpp - ) -target_compile_definitions(test_core PUBLIC cxx_std_2b) +) +target_compile_definitions(test_core PUBLIC cxx_std_23) target_compile_definitions(test_core PRIVATE -DTEST_ASSETS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/_assets") target_link_libraries(test_core diff --git a/tests/core/test_acl.cpp b/tests/agent/test_acl.cpp similarity index 98% rename from tests/core/test_acl.cpp rename to tests/agent/test_acl.cpp index dee6375..05d79b6 100644 --- a/tests/core/test_acl.cpp +++ b/tests/agent/test_acl.cpp @@ -12,11 +12,11 @@ #include -#include +#include struct fake_content { - unsigned id; + unsigned id{}; std::string name; friend void to_json(nlohmann::json& serializer, const fake_content& obj) {