style(examples): automatic reformatting

This commit is contained in:
James P. Howard, II
2023-01-22 20:44:55 -05:00
parent 8cf2193f7c
commit e56c257707
10 changed files with 162 additions and 65 deletions

View File

@@ -53,7 +53,10 @@ std::shared_ptr<std::mt19937> rng = nullptr;
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma ide diagnostic ignored "EmptyDeclOrStmt" #pragma ide diagnostic ignored "EmptyDeclOrStmt"
int main(int argc, char **argv) { int main(
int argc,
char** argv
) {
std::string ident = "bankreserves"; std::string ident = "bankreserves";
std::string log_level_option = "info"; std::string log_level_option = "info";
std::string output_file_name = ident + ".json"; std::string output_file_name = ident + ".json";

View File

@@ -48,15 +48,23 @@ extern std::shared_ptr<spdlog::logger> console;
extern std::shared_ptr<std::mt19937> rng; extern std::shared_ptr<std::mt19937> rng;
template<> template<>
struct fmt::formatter<kami::AgentID> : fmt::formatter<std::string> { struct fmt::formatter<kami::AgentID>
static auto format(kami::AgentID agent_id, format_context &ctx) { : fmt::formatter<std::string> {
static auto format(
kami::AgentID agent_id,
format_context& ctx
) {
return format_to(ctx.out(), "{}", agent_id.to_string()); return format_to(ctx.out(), "{}", agent_id.to_string());
} }
}; };
template<> template<>
struct fmt::formatter<kami::GridCoord2D> : fmt::formatter<std::string> { struct fmt::formatter<kami::GridCoord2D>
static auto format(const kami::GridCoord2D &coord, format_context &ctx) { : fmt::formatter<std::string> {
static auto format(
const kami::GridCoord2D& coord,
format_context& ctx
) {
return format_to(ctx.out(), "{}", coord.to_string()); return format_to(ctx.out(), "{}", coord.to_string());
} }
}; };
@@ -64,12 +72,15 @@ struct fmt::formatter<kami::GridCoord2D> : fmt::formatter<std::string> {
/** /**
* A starter agent for a starter model * A starter agent for a starter model
*/ */
class BankAgent : public kami::ReporterAgent { class BankAgent
: public kami::ReporterAgent {
public: public:
/** /**
* Constructor * Constructor
*/ */
explicit BankAgent(int reserve_percent) : _reserve_percent(reserve_percent) {}; explicit BankAgent(int reserve_percent)
:_reserve_percent(reserve_percent) {
};
inline std::unique_ptr<nlohmann::json> collect() override { inline std::unique_ptr<nlohmann::json> collect() override {
auto ret = std::make_unique<nlohmann::json>(); auto ret = std::make_unique<nlohmann::json>();
@@ -99,13 +110,19 @@ private:
friend class PersonAgent; friend class PersonAgent;
}; };
class PersonAgent : public kami::ReporterAgent { class PersonAgent
: public kami::ReporterAgent {
public: public:
/** /**
* Constructor * Constructor
*/ */
explicit PersonAgent(int wallet, std::shared_ptr<BankAgent> &bank) : explicit PersonAgent(
_wallet(wallet), _bank(bank) {}; int wallet,
std::shared_ptr<BankAgent>& bank
)
:
_wallet(wallet), _bank(bank) {
};
inline std::unique_ptr<nlohmann::json> collect() override { inline std::unique_ptr<nlohmann::json> collect() override {
auto ret = std::make_unique<nlohmann::json>(); auto ret = std::make_unique<nlohmann::json>();
@@ -152,7 +169,8 @@ private:
/** /**
* The one-dimensional Boltzmann wealth model * The one-dimensional Boltzmann wealth model
*/ */
class BankReservesModel : public kami::ReporterModel { class BankReservesModel
: public kami::ReporterModel {
public: public:
/** /**
* Create an instance of the one-dimensional Boltzmann wealth model. * Create an instance of the one-dimensional Boltzmann wealth model.
@@ -161,8 +179,13 @@ public:
* @param[in] length_x the length of the one-dimensional world the agents * @param[in] length_x the length of the one-dimensional world the agents
* occupy. * occupy.
*/ */
explicit BankReservesModel(unsigned int agent_count, unsigned int x_size, unsigned int y_size, explicit BankReservesModel(
unsigned int initial_seed, unsigned int max_initial_wealth); 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<nlohmann::json> collect() override { inline std::unique_ptr<nlohmann::json> collect() override {
return nullptr; return nullptr;

View File

@@ -37,8 +37,13 @@
#include <kami/random.h> #include <kami/random.h>
#include <kami/reporter.h> #include <kami/reporter.h>
BankReservesModel::BankReservesModel(unsigned int agent_count, unsigned int x_size, unsigned int y_size, BankReservesModel::BankReservesModel(
unsigned int initial_seed, unsigned int max_initial_wealth) { 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<std::mt19937>(); rng = std::make_shared<std::mt19937>();
rng->seed(initial_seed); rng->seed(initial_seed);

View File

@@ -111,7 +111,8 @@ std::optional<kami::AgentID> PersonAgent::do_business(std::shared_ptr<kami::Repo
} }
std::optional<int> PersonAgent::balance_books(std::shared_ptr<kami::ReporterModel>& model) { std::optional<int> PersonAgent::balance_books(std::shared_ptr<kami::ReporterModel>& model) {
console->debug("balance_books() called for agent {} with wallet {}, savings {}, loans {}", get_agent_id(), _wallet, console->debug(
"balance_books() called for agent {} with wallet {}, savings {}, loans {}", get_agent_id(), _wallet,
_savings, _loans); _savings, _loans);
if (_wallet < 0) { if (_wallet < 0) {

View File

@@ -47,15 +47,23 @@ std::shared_ptr<spdlog::logger> console = nullptr;
std::shared_ptr<std::mt19937> rng = nullptr; std::shared_ptr<std::mt19937> rng = nullptr;
template<> template<>
struct fmt::formatter<kami::AgentID> : fmt::formatter<std::string> { struct fmt::formatter<kami::AgentID>
static auto format(kami::AgentID agent_id, format_context &ctx) { : fmt::formatter<std::string> {
static auto format(
kami::AgentID agent_id,
format_context& ctx
) {
return format_to(ctx.out(), "{}", agent_id.to_string()); return format_to(ctx.out(), "{}", agent_id.to_string());
} }
}; };
template<> template<>
struct fmt::formatter<kami::GridCoord1D> : fmt::formatter<std::string> { struct fmt::formatter<kami::GridCoord1D>
static auto format(const kami::GridCoord1D &coord, format_context &ctx) { : fmt::formatter<std::string> {
static auto format(
const kami::GridCoord1D& coord,
format_context& ctx
) {
return format_to(ctx.out(), "{}", coord.to_string()); return format_to(ctx.out(), "{}", coord.to_string());
} }
}; };
@@ -134,7 +142,11 @@ std::optional<kami::AgentID> MoneyAgent1D::give_money(std::shared_ptr<kami::Mode
return other_agent_id; return other_agent_id;
} }
BoltzmannWealthModel1D::BoltzmannWealthModel1D(unsigned int number_agents, unsigned int length_x, unsigned int new_seed) { BoltzmannWealthModel1D::BoltzmannWealthModel1D(
unsigned int number_agents,
unsigned int length_x,
unsigned int new_seed
) {
rng = std::make_shared<std::mt19937>(); rng = std::make_shared<std::mt19937>();
rng->seed(new_seed); rng->seed(new_seed);
@@ -170,7 +182,10 @@ std::shared_ptr<kami::Model> BoltzmannWealthModel1D::step() {
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma ide diagnostic ignored "EmptyDeclOrStmt" #pragma ide diagnostic ignored "EmptyDeclOrStmt"
int main(int argc, char **argv) { int main(
int argc,
char** argv
) {
std::string ident = "boltzmann1d"; std::string ident = "boltzmann1d";
std::string log_level_option = "info"; std::string log_level_option = "info";
CLI::App app{ident}; CLI::App app{ident};
@@ -192,7 +207,8 @@ int main(int argc, char **argv) {
console = spdlog::stdout_color_st(ident); console = spdlog::stdout_color_st(ident);
console->set_level(spdlog::level::from_str(log_level_option)); 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("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, console->info(
"Starting Boltzmann Wealth Model with {} agents on a {}-unit grid for {} steps", agent_count, x_size,
max_steps); max_steps);
spdlog::stopwatch sw; spdlog::stopwatch sw;

View File

@@ -44,13 +44,16 @@
/** /**
* A sample agent for a one-dimensional Boltzmann wealth model * A sample agent for a one-dimensional Boltzmann wealth model
*/ */
class MoneyAgent1D : public kami::Agent { class MoneyAgent1D
: public kami::Agent {
public: public:
/** /**
* Create the agent * Create the agent
*/ */
MoneyAgent1D() : _step_counter(0), _agent_wealth(1) {} MoneyAgent1D()
:_step_counter(0), _agent_wealth(1) {
}
/** /**
* Deconstruct the agent * Deconstruct the agent
@@ -81,7 +84,8 @@ private:
/** /**
* The one-dimensional Boltzmann wealth model * The one-dimensional Boltzmann wealth model
*/ */
class BoltzmannWealthModel1D : public kami::Model { class BoltzmannWealthModel1D
: public kami::Model {
public: public:
/** /**
@@ -91,7 +95,11 @@ public:
* @param[in] length_x the length of the one-dimensional world the agents * @param[in] length_x the length of the one-dimensional world the agents
* occupy. * 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. * Execute a single time-step for the model.

View File

@@ -47,15 +47,23 @@ std::shared_ptr<spdlog::logger> console = nullptr;
std::shared_ptr<std::mt19937> rng = nullptr; std::shared_ptr<std::mt19937> rng = nullptr;
template<> template<>
struct fmt::formatter<kami::AgentID> : fmt::formatter<std::string> { struct fmt::formatter<kami::AgentID>
static auto format(kami::AgentID agent_id, format_context &ctx) { : fmt::formatter<std::string> {
static auto format(
kami::AgentID agent_id,
format_context& ctx
) {
return format_to(ctx.out(), "{}", agent_id.to_string()); return format_to(ctx.out(), "{}", agent_id.to_string());
} }
}; };
template<> template<>
struct fmt::formatter<kami::GridCoord2D> : fmt::formatter<std::string> { struct fmt::formatter<kami::GridCoord2D>
static auto format(const kami::GridCoord2D &coord, format_context &ctx) { : fmt::formatter<std::string> {
static auto format(
const kami::GridCoord2D& coord,
format_context& ctx
) {
return format_to(ctx.out(), "{}", coord.to_string()); return format_to(ctx.out(), "{}", coord.to_string());
} }
}; };
@@ -134,7 +142,12 @@ std::optional<kami::AgentID> MoneyAgent2D::give_money(const std::shared_ptr<kami
return other_agent_id; return other_agent_id;
} }
BoltzmannWealthModel2D::BoltzmannWealthModel2D(unsigned int number_agents, unsigned int length_x, unsigned int length_y, unsigned int new_seed) { BoltzmannWealthModel2D::BoltzmannWealthModel2D(
unsigned int number_agents,
unsigned int length_x,
unsigned int length_y,
unsigned int new_seed
) {
rng = std::make_shared<std::mt19937>(); rng = std::make_shared<std::mt19937>();
rng->seed(new_seed); rng->seed(new_seed);
@@ -171,7 +184,10 @@ std::shared_ptr<kami::Model> BoltzmannWealthModel2D::step() {
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma ide diagnostic ignored "EmptyDeclOrStmt" #pragma ide diagnostic ignored "EmptyDeclOrStmt"
int main(int argc, char **argv) { int main(
int argc,
char** argv
) {
std::string ident = "boltzmann2d"; std::string ident = "boltzmann2d";
std::string log_level_option = "info"; std::string log_level_option = "info";
CLI::App app{ident}; CLI::App app{ident};
@@ -194,7 +210,8 @@ int main(int argc, char **argv) {
console = spdlog::stdout_color_st(ident); console = spdlog::stdout_color_st(ident);
console->set_level(spdlog::level::from_str(log_level_option)); 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("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, console->info(
"Starting Boltzmann Wealth Model with {} agents on a {}x{}-unit grid for {} steps", agent_count,
x_size, y_size, max_steps); x_size, y_size, max_steps);
spdlog::stopwatch sw; spdlog::stopwatch sw;

View File

@@ -43,13 +43,16 @@
/** /**
* A sample agent for a two-dimensional Boltzmann wealth model * A sample agent for a two-dimensional Boltzmann wealth model
*/ */
class MoneyAgent2D : public kami::Agent { class MoneyAgent2D
: public kami::Agent {
public: public:
/** /**
* Create the agent * Create the agent
*/ */
MoneyAgent2D() : _step_counter(0), _agent_wealth(1) {} MoneyAgent2D()
:_step_counter(0), _agent_wealth(1) {
}
/** /**
* Deconstruct the agent * Deconstruct the agent
@@ -79,7 +82,8 @@ private:
/** /**
* The two-dimensional Boltzmann wealth model * The two-dimensional Boltzmann wealth model
*/ */
class BoltzmannWealthModel2D : public kami::Model { class BoltzmannWealthModel2D
: public kami::Model {
public: public:
/** /**
@@ -93,7 +97,12 @@ public:
* @param[in] new_seed the initial seed used for the random number * @param[in] new_seed the initial seed used for the random number
* generator. * 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. * Execute a single time-step for the model.

View File

@@ -46,8 +46,12 @@ std::shared_ptr<spdlog::logger> console = nullptr;
std::shared_ptr<std::mt19937> rng = nullptr; std::shared_ptr<std::mt19937> rng = nullptr;
template<> template<>
struct fmt::formatter<kami::AgentID> : fmt::formatter<std::string> { struct fmt::formatter<kami::AgentID>
static auto format(kami::AgentID agent_id, format_context &ctx) { : fmt::formatter<std::string> {
static auto format(
kami::AgentID agent_id,
format_context& ctx
) {
return format_to(ctx.out(), "{}", agent_id.to_string()); return format_to(ctx.out(), "{}", agent_id.to_string());
} }
}; };
@@ -65,7 +69,10 @@ kami::AgentID StarterAgent::step(std::shared_ptr<kami::Model> model) {
return this->get_agent_id(); 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<std::mt19937>(); rng = std::make_shared<std::mt19937>();
rng->seed(new_seed); rng->seed(new_seed);
@@ -93,7 +100,10 @@ std::shared_ptr<kami::Model> StarterModel::step() {
return shared_from_this(); return shared_from_this();
} }
int main(int argc, char **argv) { int main(
int argc,
char** argv
) {
std::string ident = "starter"; std::string ident = "starter";
std::string log_level_option = "info"; std::string log_level_option = "info";
CLI::App app{ident}; CLI::App app{ident};

View File

@@ -39,7 +39,8 @@
/** /**
* A starter agent for a starter model * A starter agent for a starter model
*/ */
class StarterAgent : public kami::Agent { class StarterAgent
: public kami::Agent {
private: private:
int _step_counter = 0; int _step_counter = 0;
@@ -65,7 +66,8 @@ public:
/** /**
* The one-dimensional Boltzmann wealth model * The one-dimensional Boltzmann wealth model
*/ */
class StarterModel : public kami::Model { class StarterModel
: public kami::Model {
private: private:
unsigned int _step_count; unsigned int _step_count;
@@ -77,7 +79,10 @@ public:
* @param[in] length_x the length of the one-dimensional world the agents * @param[in] length_x the length of the one-dimensional world the agents
* occupy. * 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. * Execute a single time-step for the model.