diff --git a/examples/bankreserves/bankreserves.cc b/examples/bankreserves/bankreserves.cc index 490af6f..1da813a 100644 --- a/examples/bankreserves/bankreserves.cc +++ b/examples/bankreserves/bankreserves.cc @@ -53,7 +53,10 @@ std::shared_ptr rng = nullptr; #pragma clang diagnostic push #pragma ide diagnostic ignored "EmptyDeclOrStmt" -int main(int argc, char **argv) { +int main( + int argc, + char** argv +) { std::string ident = "bankreserves"; std::string log_level_option = "info"; std::string output_file_name = ident + ".json"; @@ -68,7 +71,7 @@ int main(int argc, char **argv) { // This exercise is really stupid. auto levels_list = std::make_unique>(); - for (auto &level_name: SPDLOG_LEVEL_NAMES) + for (auto& level_name : SPDLOG_LEVEL_NAMES) levels_list->push_back(std::string(level_name.data(), level_name.size())); app.add_option("-c", agent_count, "Set the number of agents")->check(CLI::PositiveNumber); diff --git a/examples/bankreserves/bankreserves.h b/examples/bankreserves/bankreserves.h index d1dea5e..7ceb283 100644 --- a/examples/bankreserves/bankreserves.h +++ b/examples/bankreserves/bankreserves.h @@ -48,15 +48,23 @@ extern std::shared_ptr console; extern std::shared_ptr rng; template<> -struct fmt::formatter : fmt::formatter { - static auto format(kami::AgentID agent_id, format_context &ctx) { +struct fmt::formatter + : fmt::formatter { + static auto format( + kami::AgentID agent_id, + format_context& ctx + ) { return format_to(ctx.out(), "{}", agent_id.to_string()); } }; template<> -struct fmt::formatter : fmt::formatter { - static auto format(const kami::GridCoord2D &coord, format_context &ctx) { +struct fmt::formatter + : fmt::formatter { + static auto format( + const kami::GridCoord2D& coord, + format_context& ctx + ) { return format_to(ctx.out(), "{}", coord.to_string()); } }; @@ -64,12 +72,15 @@ struct fmt::formatter : fmt::formatter { /** * A starter agent for a starter model */ -class BankAgent : public kami::ReporterAgent { +class BankAgent + : public kami::ReporterAgent { public: /** * Constructor */ - explicit BankAgent(int reserve_percent) : _reserve_percent(reserve_percent) {}; + explicit BankAgent(int reserve_percent) + :_reserve_percent(reserve_percent) { + }; inline std::unique_ptr collect() override { auto ret = std::make_unique(); @@ -99,13 +110,19 @@ class BankAgent : public kami::ReporterAgent { friend class PersonAgent; }; -class PersonAgent : public kami::ReporterAgent { +class PersonAgent + : public kami::ReporterAgent { public: /** * Constructor */ - explicit PersonAgent(int wallet, std::shared_ptr &bank) : - _wallet(wallet), _bank(bank) {}; + explicit PersonAgent( + int wallet, + std::shared_ptr& bank + ) + : + _wallet(wallet), _bank(bank) { + }; inline std::unique_ptr collect() override { auto ret = std::make_unique(); @@ -134,11 +151,11 @@ class PersonAgent : public kami::ReporterAgent { /** * Move the agent to a random location on the world */ - std::optional move_agent(std::shared_ptr &model); + std::optional move_agent(std::shared_ptr& model); - std::optional do_business(std::shared_ptr &model); + std::optional do_business(std::shared_ptr& model); - std::optional balance_books(std::shared_ptr &model); + std::optional balance_books(std::shared_ptr& model); kami::AgentID deposit_to_savings(double amount); @@ -152,7 +169,8 @@ class PersonAgent : public kami::ReporterAgent { /** * The one-dimensional Boltzmann wealth model */ -class BankReservesModel : public kami::ReporterModel { +class BankReservesModel + : public kami::ReporterModel { public: /** * Create an instance of the one-dimensional Boltzmann wealth model. @@ -161,8 +179,13 @@ class BankReservesModel : public kami::ReporterModel { * @param[in] length_x the length of the one-dimensional world the agents * occupy. */ - explicit BankReservesModel(unsigned int agent_count, unsigned int x_size, unsigned int y_size, - unsigned int initial_seed, unsigned int max_initial_wealth); + explicit BankReservesModel( + unsigned int agent_count, + unsigned int x_size, + unsigned int y_size, + unsigned int initial_seed, + unsigned int max_initial_wealth + ); inline std::unique_ptr collect() override { return nullptr; diff --git a/examples/bankreserves/brmodel.cc b/examples/bankreserves/brmodel.cc index 521f7ab..68c023b 100644 --- a/examples/bankreserves/brmodel.cc +++ b/examples/bankreserves/brmodel.cc @@ -37,8 +37,13 @@ #include #include -BankReservesModel::BankReservesModel(unsigned int agent_count, unsigned int x_size, unsigned int y_size, - unsigned int initial_seed, unsigned int max_initial_wealth) { +BankReservesModel::BankReservesModel( + unsigned int agent_count, + unsigned int x_size, + unsigned int y_size, + unsigned int initial_seed, + unsigned int max_initial_wealth +) { rng = std::make_shared(); rng->seed(initial_seed); diff --git a/examples/bankreserves/person.cc b/examples/bankreserves/person.cc index f9926c4..34ddd4a 100644 --- a/examples/bankreserves/person.cc +++ b/examples/bankreserves/person.cc @@ -47,7 +47,7 @@ kami::AgentID PersonAgent::step(std::shared_ptr model) { return get_agent_id(); } -std::optional PersonAgent::move_agent(std::shared_ptr &model) { +std::optional PersonAgent::move_agent(std::shared_ptr& model) { console->trace("move_agent() called for agent {}", get_agent_id()); auto agent_id = get_agent_id(); @@ -64,7 +64,7 @@ std::optional PersonAgent::move_agent(std::shared_ptr PersonAgent::do_business(std::shared_ptr &model) { +std::optional PersonAgent::do_business(std::shared_ptr& model) { console->trace("do_business() called for agent {}", get_agent_id()); auto agent_id = get_agent_id(); @@ -110,9 +110,10 @@ std::optional PersonAgent::do_business(std::shared_ptr PersonAgent::balance_books(std::shared_ptr &model) { - console->debug("balance_books() called for agent {} with wallet {}, savings {}, loans {}", get_agent_id(), _wallet, - _savings, _loans); +std::optional PersonAgent::balance_books(std::shared_ptr& model) { + console->debug( + "balance_books() called for agent {} with wallet {}, savings {}, loans {}", get_agent_id(), _wallet, + _savings, _loans); if (_wallet < 0) { if (_savings >= -_wallet) { diff --git a/examples/boltzmann1d/boltzmann1d.cc b/examples/boltzmann1d/boltzmann1d.cc index 560619d..649e554 100644 --- a/examples/boltzmann1d/boltzmann1d.cc +++ b/examples/boltzmann1d/boltzmann1d.cc @@ -46,16 +46,24 @@ std::shared_ptr console = nullptr; std::shared_ptr rng = nullptr; -template <> -struct fmt::formatter : fmt::formatter { - static auto format(kami::AgentID agent_id, format_context &ctx) { +template<> +struct fmt::formatter + : fmt::formatter { + static auto format( + kami::AgentID agent_id, + format_context& ctx + ) { return format_to(ctx.out(), "{}", agent_id.to_string()); } }; template<> -struct fmt::formatter : fmt::formatter { - static auto format(const kami::GridCoord1D &coord, format_context &ctx) { +struct fmt::formatter + : fmt::formatter { + static auto format( + const kami::GridCoord1D& coord, + format_context& ctx + ) { return format_to(ctx.out(), "{}", coord.to_string()); } }; @@ -134,7 +142,11 @@ std::optional MoneyAgent1D::give_money(std::shared_ptr(); rng->seed(new_seed); @@ -170,7 +182,10 @@ std::shared_ptr BoltzmannWealthModel1D::step() { #pragma clang diagnostic push #pragma ide diagnostic ignored "EmptyDeclOrStmt" -int main(int argc, char **argv) { +int main( + int argc, + char** argv +) { std::string ident = "boltzmann1d"; std::string log_level_option = "info"; CLI::App app{ident}; @@ -178,7 +193,7 @@ int main(int argc, char **argv) { // This exercise is really stupid. auto levels_list = std::make_unique>(); - for (auto &level_name: SPDLOG_LEVEL_NAMES) + for (auto& level_name : SPDLOG_LEVEL_NAMES) levels_list->push_back(std::string(level_name.data(), level_name.size())); app.add_option("-c", agent_count, "Set the number of agents")->check(CLI::PositiveNumber); @@ -192,8 +207,9 @@ int main(int argc, char **argv) { console = spdlog::stdout_color_st(ident); console->set_level(spdlog::level::from_str(log_level_option)); console->info("Compiled with Kami/{}, log level {}", kami::version.to_string(), log_level_option); - console->info("Starting Boltzmann Wealth Model with {} agents on a {}-unit grid for {} steps", agent_count, x_size, - max_steps); + console->info( + "Starting Boltzmann Wealth Model with {} agents on a {}-unit grid for {} steps", agent_count, x_size, + max_steps); spdlog::stopwatch sw; diff --git a/examples/boltzmann1d/boltzmann1d.h b/examples/boltzmann1d/boltzmann1d.h index b5f479e..b6844af 100644 --- a/examples/boltzmann1d/boltzmann1d.h +++ b/examples/boltzmann1d/boltzmann1d.h @@ -44,13 +44,16 @@ /** * A sample agent for a one-dimensional Boltzmann wealth model */ -class MoneyAgent1D : public kami::Agent { +class MoneyAgent1D + : public kami::Agent { public: /** * Create the agent */ - MoneyAgent1D() : _step_counter(0), _agent_wealth(1) {} + MoneyAgent1D() + :_step_counter(0), _agent_wealth(1) { + } /** * Deconstruct the agent @@ -81,7 +84,8 @@ class MoneyAgent1D : public kami::Agent { /** * The one-dimensional Boltzmann wealth model */ -class BoltzmannWealthModel1D : public kami::Model { +class BoltzmannWealthModel1D + : public kami::Model { public: /** @@ -91,7 +95,11 @@ class BoltzmannWealthModel1D : public kami::Model { * @param[in] length_x the length of the one-dimensional world the agents * occupy. */ - explicit BoltzmannWealthModel1D(unsigned int number_agents = 10, unsigned int length_x = 10, unsigned int new_seed = 42); + explicit BoltzmannWealthModel1D( + unsigned int number_agents = 10, + unsigned int length_x = 10, + unsigned int new_seed = 42 + ); /** * Execute a single time-step for the model. diff --git a/examples/boltzmann2d/boltzmann2d.cc b/examples/boltzmann2d/boltzmann2d.cc index fead8e7..0c0a423 100644 --- a/examples/boltzmann2d/boltzmann2d.cc +++ b/examples/boltzmann2d/boltzmann2d.cc @@ -46,16 +46,24 @@ std::shared_ptr console = nullptr; std::shared_ptr rng = nullptr; -template <> -struct fmt::formatter : fmt::formatter { - static auto format(kami::AgentID agent_id, format_context &ctx) { +template<> +struct fmt::formatter + : fmt::formatter { + static auto format( + kami::AgentID agent_id, + format_context& ctx + ) { return format_to(ctx.out(), "{}", agent_id.to_string()); } }; template<> -struct fmt::formatter : fmt::formatter { - static auto format(const kami::GridCoord2D &coord, format_context &ctx) { +struct fmt::formatter + : fmt::formatter { + static auto format( + const kami::GridCoord2D& coord, + format_context& ctx + ) { return format_to(ctx.out(), "{}", coord.to_string()); } }; @@ -75,7 +83,7 @@ kami::AgentID MoneyAgent2D::step(std::shared_ptr model) { return this->get_agent_id(); } -std::optional MoneyAgent2D::move_agent(const std::shared_ptr &model) { +std::optional MoneyAgent2D::move_agent(const std::shared_ptr& model) { console->trace("Entering move_agent"); auto agent_id = get_agent_id(); @@ -98,7 +106,7 @@ std::optional MoneyAgent2D::move_agent(const std::shared_ptr< return new_location; } -std::optional MoneyAgent2D::give_money(const std::shared_ptr &model) { +std::optional MoneyAgent2D::give_money(const std::shared_ptr& model) { console->trace("Entering give_money"); auto agent_id = get_agent_id(); @@ -134,7 +142,12 @@ std::optional MoneyAgent2D::give_money(const std::shared_ptr(); rng->seed(new_seed); @@ -171,7 +184,10 @@ std::shared_ptr BoltzmannWealthModel2D::step() { #pragma clang diagnostic push #pragma ide diagnostic ignored "EmptyDeclOrStmt" -int main(int argc, char **argv) { +int main( + int argc, + char** argv +) { std::string ident = "boltzmann2d"; std::string log_level_option = "info"; CLI::App app{ident}; @@ -179,7 +195,7 @@ int main(int argc, char **argv) { // This exercise is really stupid. auto levels_list = std::make_unique>(); - for (auto &level_name: SPDLOG_LEVEL_NAMES) + for (auto& level_name : SPDLOG_LEVEL_NAMES) levels_list->push_back(std::string(level_name.data(), level_name.size())); app.add_option("-c", agent_count, "Set the number of agents")->check(CLI::PositiveNumber); @@ -194,8 +210,9 @@ int main(int argc, char **argv) { console = spdlog::stdout_color_st(ident); console->set_level(spdlog::level::from_str(log_level_option)); console->info("Compiled with Kami/{}, log level {}", kami::version.to_string(), log_level_option); - console->info("Starting Boltzmann Wealth Model with {} agents on a {}x{}-unit grid for {} steps", agent_count, - x_size, y_size, max_steps); + console->info( + "Starting Boltzmann Wealth Model with {} agents on a {}x{}-unit grid for {} steps", agent_count, + x_size, y_size, max_steps); spdlog::stopwatch sw; diff --git a/examples/boltzmann2d/boltzmann2d.h b/examples/boltzmann2d/boltzmann2d.h index 07bffed..4641a95 100644 --- a/examples/boltzmann2d/boltzmann2d.h +++ b/examples/boltzmann2d/boltzmann2d.h @@ -43,13 +43,16 @@ /** * A sample agent for a two-dimensional Boltzmann wealth model */ -class MoneyAgent2D : public kami::Agent { +class MoneyAgent2D + : public kami::Agent { public: /** * Create the agent */ - MoneyAgent2D() : _step_counter(0), _agent_wealth(1) {} + MoneyAgent2D() + :_step_counter(0), _agent_wealth(1) { + } /** * Deconstruct the agent @@ -64,12 +67,12 @@ class MoneyAgent2D : public kami::Agent { /** * Move the agent to a random location on the world */ - std::optional move_agent(const std::shared_ptr &model); + std::optional move_agent(const std::shared_ptr& model); /** * Give money to a random agent */ - std::optional give_money(const std::shared_ptr &model); + std::optional give_money(const std::shared_ptr& model); private: int _step_counter; @@ -79,7 +82,8 @@ class MoneyAgent2D : public kami::Agent { /** * The two-dimensional Boltzmann wealth model */ -class BoltzmannWealthModel2D : public kami::Model { +class BoltzmannWealthModel2D + : public kami::Model { public: /** @@ -93,7 +97,12 @@ class BoltzmannWealthModel2D : public kami::Model { * @param[in] new_seed the initial seed used for the random number * generator. */ - explicit BoltzmannWealthModel2D(unsigned int number_agents = 10, unsigned int length_x = 10, unsigned int length_y = 10, unsigned int new_seed = 42); + explicit BoltzmannWealthModel2D( + unsigned int number_agents = 10, + unsigned int length_x = 10, + unsigned int length_y = 10, + unsigned int new_seed = 42 + ); /** * Execute a single time-step for the model. diff --git a/examples/starter/starter.cc b/examples/starter/starter.cc index b177b66..0225651 100644 --- a/examples/starter/starter.cc +++ b/examples/starter/starter.cc @@ -45,9 +45,13 @@ std::shared_ptr console = nullptr; std::shared_ptr rng = nullptr; -template <> -struct fmt::formatter : fmt::formatter { - static auto format(kami::AgentID agent_id, format_context &ctx) { +template<> +struct fmt::formatter + : fmt::formatter { + static auto format( + kami::AgentID agent_id, + format_context& ctx + ) { return format_to(ctx.out(), "{}", agent_id.to_string()); } }; @@ -65,7 +69,10 @@ kami::AgentID StarterAgent::step(std::shared_ptr model) { return this->get_agent_id(); } -StarterModel::StarterModel(unsigned int number_agents, unsigned int new_seed) { +StarterModel::StarterModel( + unsigned int number_agents, + unsigned int new_seed +) { rng = std::make_shared(); rng->seed(new_seed); @@ -93,7 +100,10 @@ std::shared_ptr StarterModel::step() { return shared_from_this(); } -int main(int argc, char **argv) { +int main( + int argc, + char** argv +) { std::string ident = "starter"; std::string log_level_option = "info"; CLI::App app{ident}; @@ -101,7 +111,7 @@ int main(int argc, char **argv) { // This exercise is really stupid. auto levels_list = std::make_unique>(); - for (auto &level_name: SPDLOG_LEVEL_NAMES) + for (auto& level_name : SPDLOG_LEVEL_NAMES) levels_list->push_back(std::string(level_name.data(), level_name.size())); app.add_option("-c", agent_count, "Set the number of agents")->check(CLI::PositiveNumber); diff --git a/examples/starter/starter.h b/examples/starter/starter.h index 5f337ff..d156623 100644 --- a/examples/starter/starter.h +++ b/examples/starter/starter.h @@ -39,7 +39,8 @@ /** * A starter agent for a starter model */ -class StarterAgent : public kami::Agent { +class StarterAgent + : public kami::Agent { private: int _step_counter = 0; @@ -65,7 +66,8 @@ class StarterAgent : public kami::Agent { /** * The one-dimensional Boltzmann wealth model */ -class StarterModel : public kami::Model { +class StarterModel + : public kami::Model { private: unsigned int _step_count; @@ -77,7 +79,10 @@ class StarterModel : public kami::Model { * @param[in] length_x the length of the one-dimensional world the agents * occupy. */ - explicit StarterModel(unsigned int number_agents = 10, unsigned int new_seed = 42); + explicit StarterModel( + unsigned int number_agents = 10, + unsigned int new_seed = 42 + ); /** * Execute a single time-step for the model.