mirror of
https://github.com/JHUAPL/kami.git
synced 2026-01-08 14:33:53 -05:00
Remove model from agent, add it to step() and advance() methods
This commit is contained in:
@@ -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++;
|
||||
|
||||
console->trace("Agent {} is moving", this->get_agent_id());
|
||||
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -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++;
|
||||
|
||||
console->trace("Agent {} is moving", this->get_agent_id());
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -147,7 +147,7 @@ namespace kami {
|
||||
* 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.
|
||||
*/
|
||||
virtual void step() = 0;
|
||||
virtual void step(std::shared_ptr<Model> model) = 0;
|
||||
|
||||
/**
|
||||
* Compare if two `Agent`s are the same `Agent`.
|
||||
@@ -180,19 +180,6 @@ namespace kami {
|
||||
* the restrictions on the comparison.
|
||||
*/
|
||||
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
|
||||
* happen here.
|
||||
*/
|
||||
virtual void advance() = 0;
|
||||
virtual void advance(std::shared_ptr<Model> model) = 0;
|
||||
};
|
||||
|
||||
} // namespace kami
|
||||
|
||||
@@ -54,12 +54,4 @@ namespace kami {
|
||||
|
||||
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
|
||||
|
||||
@@ -40,7 +40,6 @@ namespace kami {
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace kami {
|
||||
|
||||
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);
|
||||
if(agent != nullptr) agent->step();
|
||||
if(agent != nullptr) agent->step(_model);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace kami {
|
||||
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++) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user