mirror of
https://github.com/JHUAPL/kami.git
synced 2026-01-09 14:58:02 -05:00
Remove void returns from scheduler-related classes
This commit is contained in:
@@ -97,6 +97,8 @@ kami::AgentID MoneyAgent1D::give_money() {
|
||||
other_agent->_agent_wealth += 1;
|
||||
_agent_wealth -= 1;
|
||||
}
|
||||
|
||||
return agent_id;
|
||||
}
|
||||
|
||||
BoltzmannWealthModel1D::BoltzmannWealthModel1D(unsigned int number_agents, unsigned int length_x, unsigned int new_seed) {
|
||||
|
||||
@@ -71,8 +71,10 @@ namespace kami {
|
||||
*
|
||||
* @param model a reference copy of the model
|
||||
* @param agent_list list of agents to execute the step
|
||||
*
|
||||
* @params returns vector of agents successfully stepped
|
||||
*/
|
||||
void step(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list) override;
|
||||
std::shared_ptr<std::vector<AgentID>> step(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list) override;
|
||||
|
||||
/**
|
||||
* @brief Set the RNG
|
||||
|
||||
@@ -54,8 +54,10 @@ namespace kami {
|
||||
* assigned.
|
||||
*
|
||||
* @param model a reference copy of the model
|
||||
*
|
||||
* @params returns vector of agents successfully stepped
|
||||
*/
|
||||
virtual void step(std::shared_ptr<Model> model) = 0;
|
||||
virtual std::shared_ptr<std::vector<AgentID>> step(std::shared_ptr<Model> model) = 0;
|
||||
|
||||
/**
|
||||
* @brief Execute a single time step.
|
||||
@@ -67,8 +69,10 @@ namespace kami {
|
||||
*
|
||||
* @param model a reference copy of the model
|
||||
* @param agent_list list of agents to execute the step
|
||||
*
|
||||
* @params returns vector of agents successfully stepped
|
||||
*/
|
||||
virtual void step(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list) = 0;
|
||||
virtual std::shared_ptr<std::vector<AgentID>> step(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list) = 0;
|
||||
};
|
||||
|
||||
} // namespace kami
|
||||
|
||||
@@ -55,8 +55,10 @@ namespace kami {
|
||||
* assigned.
|
||||
*
|
||||
* @param model a reference copy of the model
|
||||
*
|
||||
* @params returns vector of agents successfully stepped
|
||||
*/
|
||||
void step(std::shared_ptr<Model> model);
|
||||
std::shared_ptr<std::vector<AgentID>> step(std::shared_ptr<Model> model) override;
|
||||
|
||||
/**
|
||||
* @brief Execute a single time step.
|
||||
@@ -68,8 +70,10 @@ namespace kami {
|
||||
*
|
||||
* @param model a reference copy of the model
|
||||
* @param agent_list list of agents to execute the step
|
||||
*
|
||||
* @params returns vector of agents successfully stepped
|
||||
*/
|
||||
virtual void step(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list);
|
||||
std::shared_ptr<std::vector<AgentID>> step(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list) override;
|
||||
};
|
||||
|
||||
} // namespace kami
|
||||
|
||||
@@ -55,8 +55,10 @@ namespace kami {
|
||||
* assigned.
|
||||
*
|
||||
* @param model a reference copy of the model
|
||||
*
|
||||
* @params returns vector of agents successfully advanced
|
||||
*/
|
||||
void advance(std::shared_ptr<Model> model);
|
||||
std::shared_ptr<std::vector<AgentID>> advance(std::shared_ptr<Model> model);
|
||||
|
||||
/**
|
||||
* @brief Advance a single time step.
|
||||
@@ -68,8 +70,10 @@ namespace kami {
|
||||
*
|
||||
* @param model a reference copy of the model
|
||||
* @param agent_list list of agents to execute the step
|
||||
*
|
||||
* @params returns vector of agents successfully advanced
|
||||
*/
|
||||
void advance(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list);
|
||||
std::shared_ptr<std::vector<AgentID>> advance(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list);
|
||||
|
||||
public:
|
||||
/**
|
||||
@@ -82,8 +86,10 @@ namespace kami {
|
||||
*
|
||||
* @param model a reference copy of the model
|
||||
* @param agent_list list of agents to execute the step
|
||||
*
|
||||
* @params returns vector of agents successfully stepped
|
||||
*/
|
||||
void step(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list) override;
|
||||
std::shared_ptr<std::vector<AgentID>> step(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list) override;
|
||||
};
|
||||
|
||||
} // namespace kami
|
||||
|
||||
@@ -38,9 +38,9 @@ namespace kami {
|
||||
this->set_rng(std::move(rng));
|
||||
}
|
||||
|
||||
void RandomScheduler::step(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list) {
|
||||
std::shared_ptr<std::vector<AgentID>> RandomScheduler::step(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list) {
|
||||
shuffle(agent_list->begin(),agent_list->end(), *_rng);
|
||||
this->SequentialScheduler::step(model, agent_list);
|
||||
return std::move(this->SequentialScheduler::step(model, agent_list));
|
||||
}
|
||||
|
||||
void RandomScheduler::set_rng(std::shared_ptr<std::ranlux24> rng) {
|
||||
|
||||
@@ -28,17 +28,23 @@
|
||||
|
||||
namespace kami {
|
||||
|
||||
void SequentialScheduler::step(std::shared_ptr<Model> model) {
|
||||
this->step(model, model->get_population()->get_agent_list());
|
||||
std::shared_ptr<std::vector<AgentID>> SequentialScheduler::step(std::shared_ptr<Model> model) {
|
||||
return std::move(this->step(model, model->get_population()->get_agent_list()));
|
||||
}
|
||||
|
||||
void SequentialScheduler::step(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list) {
|
||||
std::shared_ptr<std::vector<AgentID>> SequentialScheduler::step(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list) {
|
||||
auto return_agent_list = std::make_shared<std::vector<AgentID>>();
|
||||
Scheduler::_step_counter++;
|
||||
|
||||
for(auto agent_id = agent_list->begin(); agent_id < agent_list->end(); agent_id++) {
|
||||
auto agent = model->get_population()->get_agent_by_id(*agent_id);
|
||||
if(agent != nullptr) agent->step(model);
|
||||
if(agent != nullptr) {
|
||||
agent->step(model);
|
||||
return_agent_list->push_back(*agent_id);
|
||||
}
|
||||
}
|
||||
|
||||
return std::move(return_agent_list);
|
||||
}
|
||||
|
||||
} // namespace kami
|
||||
|
||||
@@ -32,20 +32,27 @@
|
||||
|
||||
namespace kami {
|
||||
|
||||
void StagedScheduler::step(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list) {
|
||||
std::shared_ptr<std::vector<AgentID>> StagedScheduler::step(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list) {
|
||||
this->SequentialScheduler::step(model, agent_list);
|
||||
this->advance(model, agent_list);
|
||||
return std::move(this->advance(model, agent_list));
|
||||
}
|
||||
|
||||
void StagedScheduler::advance(std::shared_ptr<Model> model) {
|
||||
this->advance(model, model->get_population()->get_agent_list());
|
||||
std::shared_ptr<std::vector<AgentID>> StagedScheduler::advance(std::shared_ptr<Model> model) {
|
||||
return std::move(this->advance(model, model->get_population()->get_agent_list()));
|
||||
}
|
||||
|
||||
void StagedScheduler::advance(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list) {
|
||||
std::shared_ptr<std::vector<AgentID>> StagedScheduler::advance(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list) {
|
||||
auto return_agent_list = std::make_shared<std::vector<AgentID>>();
|
||||
|
||||
for(auto agent_id = agent_list->begin(); agent_id < agent_list->end(); agent_id++) {
|
||||
auto agent = std::dynamic_pointer_cast<StagedAgent>(model->get_population()->get_agent_by_id(*agent_id));
|
||||
if(agent != nullptr) agent->advance(model);
|
||||
if(agent != nullptr) {
|
||||
agent->step(model);
|
||||
return_agent_list->push_back(*agent_id);
|
||||
}
|
||||
}
|
||||
|
||||
return std::move(return_agent_list);
|
||||
}
|
||||
|
||||
} // namespace kami
|
||||
|
||||
Reference in New Issue
Block a user