Remove model from agent, add it to step() and advance() methods

This commit is contained in:
James P. Howard, II
2022-08-02 14:26:10 -04:00
parent 084eda63f3
commit 10c42ec2fe
9 changed files with 8 additions and 30 deletions

View File

@@ -61,7 +61,7 @@ struct fmt::formatter<kami::GridCoord1D> : fmt::formatter<std::string> {
} }
}; };
void MoneyAgent1D::step() { void MoneyAgent1D::step(std::shared_ptr<kami::Model> model) {
this->_step_counter++; this->_step_counter++;
console->trace("Agent {} is moving", this->get_agent_id()); console->trace("Agent {} is moving", this->get_agent_id());

View File

@@ -55,7 +55,7 @@ public:
/** /**
* Execute a single time-step for the agent * Execute a single time-step for the agent
*/ */
void step() override; void step(std::shared_ptr<kami::Model> model) override;
/** /**
* Move the agent to a random location on the world * Move the agent to a random location on the world

View File

@@ -62,7 +62,7 @@ struct fmt::formatter<kami::GridCoord2D> : fmt::formatter<std::string> {
} }
}; };
void MoneyAgent2D::step() { void MoneyAgent2D::step(std::shared_ptr<kami::Model> model) {
this->_step_counter++; this->_step_counter++;
console->trace("Agent {} is moving", this->get_agent_id()); console->trace("Agent {} is moving", this->get_agent_id());

View File

@@ -57,7 +57,7 @@ public:
/** /**
* Execute a single time-step for the agent * Execute a single time-step for the agent
*/ */
void step() override; void step(std::shared_ptr<kami::Model> model) override;
/** /**
* Move the agent to a random location on the world * Move the agent to a random location on the world

View File

@@ -147,7 +147,7 @@ namespace kami {
* This function should step the agent instance. Any activities that the * This function should step the agent instance. Any activities that the
* agent should perform as part of its time step should be in this function. * agent should perform as part of its time step should be in this function.
*/ */
virtual void step() = 0; virtual void step(std::shared_ptr<Model> model) = 0;
/** /**
* Compare if two `Agent`s are the same `Agent`. * Compare if two `Agent`s are the same `Agent`.
@@ -180,19 +180,6 @@ namespace kami {
* the restrictions on the comparison. * the restrictions on the comparison.
*/ */
friend bool operator!=(const Agent &lhs, const Agent &rhs); friend bool operator!=(const Agent &lhs, const Agent &rhs);
/**
* @brief Get the `Model` associated with this agent
*/
[[maybe_unused]] std::shared_ptr<Model> get_model();
/**
* @brief Add a `Model` to this agent
*
* @details This method will associate a model with the
* agent.
*/
[[maybe_unused]] void set_model(std::shared_ptr<Model> model);
}; };
/** /**
@@ -216,7 +203,7 @@ namespace kami {
* the agent that must happen for the `StagedAgent` to complete its step must * the agent that must happen for the `StagedAgent` to complete its step must
* happen here. * happen here.
*/ */
virtual void advance() = 0; virtual void advance(std::shared_ptr<Model> model) = 0;
}; };
} // namespace kami } // namespace kami

View File

@@ -54,12 +54,4 @@ namespace kami {
bool operator!=(const Agent &lhs, const Agent &rhs) { return !(lhs == rhs); } bool operator!=(const Agent &lhs, const Agent &rhs) { return !(lhs == rhs); }
[[maybe_unused]] std::shared_ptr<Model> Agent::get_model() {
return(_model);
}
[[maybe_unused]] void Agent::set_model(std::shared_ptr<Model> model) {
_model = std::move(model);
}
} // namespace kami } // namespace kami

View File

@@ -40,7 +40,6 @@ namespace kami {
} }
void Population::add_agent(const std::shared_ptr<Agent> &agent) { void Population::add_agent(const std::shared_ptr<Agent> &agent) {
agent->set_model(_model);
_agent_map.insert(std::pair<AgentID, std::shared_ptr<Agent>>(agent->get_agent_id(), agent)); _agent_map.insert(std::pair<AgentID, std::shared_ptr<Agent>>(agent->get_agent_id(), agent));
} }

View File

@@ -37,7 +37,7 @@ namespace kami {
for(auto agent_id = agent_list->begin(); agent_id < agent_list->end(); agent_id++) { for(auto agent_id = agent_list->begin(); agent_id < agent_list->end(); agent_id++) {
auto agent = Scheduler::get_model()->get_population()->get_agent_by_id(*agent_id); auto agent = Scheduler::get_model()->get_population()->get_agent_by_id(*agent_id);
if(agent != nullptr) agent->step(); if(agent != nullptr) agent->step(_model);
} }
} }

View File

@@ -45,7 +45,7 @@ namespace kami {
void StagedScheduler::advance(const std::shared_ptr<std::vector<AgentID>>& agent_list) { void StagedScheduler::advance(const std::shared_ptr<std::vector<AgentID>>& agent_list) {
for(auto agent_id = agent_list->begin(); agent_id < agent_list->end(); agent_id++) { for(auto agent_id = agent_list->begin(); agent_id < agent_list->end(); agent_id++) {
auto agent = std::dynamic_pointer_cast<StagedAgent>(this->Scheduler::get_model()->get_population()->get_agent_by_id(*agent_id)); auto agent = std::dynamic_pointer_cast<StagedAgent>(this->Scheduler::get_model()->get_population()->get_agent_by_id(*agent_id));
if(agent != nullptr) agent->advance(); if(agent != nullptr) agent->advance(_model);
} }
} }