style(source): automatic reformatting

This commit is contained in:
James P. Howard, II
2023-01-22 20:46:34 -05:00
parent 431a4ac8cf
commit adec433bce
13 changed files with 281 additions and 95 deletions

View File

@@ -30,32 +30,58 @@
namespace kami {
AgentID::AgentID() : _id(_id_next++) {}
AgentID::AgentID()
:_id(_id_next++) {
}
std::string AgentID::to_string() const { return std::to_string(_id); }
std::string AgentID::to_string() const {
return std::to_string(_id);
}
bool operator==(const AgentID &lhs, const AgentID &rhs) {
bool operator==(
const AgentID& lhs,
const AgentID& rhs
) {
return lhs._id == rhs._id;
}
bool operator!=(const AgentID &lhs, const AgentID &rhs) {
bool operator!=(
const AgentID& lhs,
const AgentID& rhs
) {
return !(lhs == rhs);
}
bool operator<(const AgentID &lhs, const AgentID &rhs) {
bool operator<(
const AgentID& lhs,
const AgentID& rhs
) {
return lhs._id < rhs._id;
}
std::ostream &operator<<(std::ostream &lhs, const AgentID &rhs) {
std::ostream& operator<<(
std::ostream& lhs,
const AgentID& rhs
) {
return lhs << rhs.to_string();
}
AgentID Agent::get_agent_id() const { return this->_agent_id; }
AgentID Agent::get_agent_id() const {
return this->_agent_id;
}
bool operator==(const Agent &lhs, const Agent &rhs) {
bool operator==(
const Agent& lhs,
const Agent& rhs
) {
return lhs._agent_id == rhs._agent_id;
}
bool operator!=(const Agent &lhs, const Agent &rhs) { return !(lhs == rhs); }
bool operator!=(
const Agent& lhs,
const Agent& rhs
) {
return !(lhs == rhs);
}
} // namespace kami

View File

@@ -30,7 +30,10 @@
namespace kami {
std::ostream &operator<<(std::ostream &lhs, const Coord &rhs) {
std::ostream& operator<<(
std::ostream& lhs,
const Coord& rhs
) {
return lhs << rhs.to_string();
}

View File

@@ -39,7 +39,9 @@
namespace kami {
GridCoord1D::GridCoord1D(int x_coord) : _x_coord(x_coord) {}
GridCoord1D::GridCoord1D(int x_coord)
:_x_coord(x_coord) {
}
int GridCoord1D::x() const {
return _x_coord;
@@ -49,41 +51,65 @@ namespace kami {
return std::string("(" + std::to_string(_x_coord) + ")");
}
double GridCoord1D::distance(std::shared_ptr<Coord> &p) const {
double GridCoord1D::distance(std::shared_ptr<Coord>& p) const {
auto p1d = std::static_pointer_cast<GridCoord1D>(p);
return static_cast<double>(abs(_x_coord - p1d->_x_coord));
}
bool operator==(const GridCoord1D &lhs, const GridCoord1D &rhs) {
bool operator==(
const GridCoord1D& lhs,
const GridCoord1D& rhs
) {
return (lhs._x_coord == rhs._x_coord);
}
bool operator!=(const GridCoord1D &lhs, const GridCoord1D &rhs) {
bool operator!=(
const GridCoord1D& lhs,
const GridCoord1D& rhs
) {
return !(lhs == rhs);
}
std::ostream &operator<<(std::ostream &lhs, const GridCoord1D &rhs) {
std::ostream& operator<<(
std::ostream& lhs,
const GridCoord1D& rhs
) {
return lhs << rhs.to_string();
}
GridCoord1D operator+(const GridCoord1D &lhs, const GridCoord1D &rhs) {
GridCoord1D operator+(
const GridCoord1D& lhs,
const GridCoord1D& rhs
) {
return GridCoord1D(lhs._x_coord + rhs._x_coord);
}
GridCoord1D operator-(const GridCoord1D &lhs, const GridCoord1D &rhs) {
GridCoord1D operator-(
const GridCoord1D& lhs,
const GridCoord1D& rhs
) {
return GridCoord1D(lhs._x_coord - rhs._x_coord);
}
GridCoord1D operator*(const GridCoord1D &lhs, const double rhs) {
GridCoord1D operator*(
const GridCoord1D& lhs,
const double rhs
) {
return GridCoord1D(static_cast<int>(lhs._x_coord * rhs));
}
GridCoord1D operator*(const double lhs, const GridCoord1D &rhs) {
GridCoord1D operator*(
const double lhs,
const GridCoord1D& rhs
) {
return GridCoord1D(static_cast<int>(rhs._x_coord * lhs));
}
Grid1D::Grid1D(unsigned int maximum_x, bool wrap_x) {
Grid1D::Grid1D(
unsigned int maximum_x,
bool wrap_x
) {
_maximum_x = maximum_x;
_wrap_x = wrap_x;
@@ -95,7 +121,10 @@ namespace kami {
return delete_agent(agent_id, get_location_by_agent(agent_id));
}
AgentID Grid1D::delete_agent(AgentID agent_id, const GridCoord1D &coord) {
AgentID Grid1D::delete_agent(
AgentID agent_id,
const GridCoord1D& coord
) {
for (auto test_agent_id = _agent_grid->find(coord); test_agent_id != _agent_grid->end(); test_agent_id++)
if (test_agent_id->second == agent_id) {
_agent_grid->erase(test_agent_id);
@@ -107,35 +136,44 @@ namespace kami {
fmt::format("Agent {} not found at location {}", agent_id.to_string(), coord.to_string()));
}
bool Grid1D::is_location_valid(const GridCoord1D &coord) const {
bool Grid1D::is_location_valid(const GridCoord1D& coord) const {
auto x = coord.x();
return (x >= 0 && x < static_cast<int>(_maximum_x));
}
bool Grid1D::is_location_empty(const GridCoord1D &coord) const {
bool Grid1D::is_location_empty(const GridCoord1D& coord) const {
auto grid_location = _agent_grid->equal_range(coord);
return grid_location.first == grid_location.second;
}
AgentID Grid1D::move_agent(const AgentID agent_id, const GridCoord1D &coord) {
AgentID Grid1D::move_agent(
const AgentID agent_id,
const GridCoord1D& coord
) {
return add_agent(delete_agent(agent_id, get_location_by_agent(agent_id)), coord);
}
std::shared_ptr<std::unordered_set<GridCoord1D>>
Grid1D::get_neighborhood(const AgentID agent_id, const bool include_center) const {
Grid1D::get_neighborhood(
const AgentID agent_id,
const bool include_center
) const {
return std::move(get_neighborhood(get_location_by_agent(agent_id), include_center));
}
std::shared_ptr<std::unordered_set<GridCoord1D>>
Grid1D::get_neighborhood(const GridCoord1D &coord, const bool include_center) const {
Grid1D::get_neighborhood(
const GridCoord1D& coord,
const bool include_center
) const {
auto neighborhood = std::make_shared<std::unordered_set<GridCoord1D>>();
// We assume our starting position is valid
if (include_center)
neighborhood->insert(coord);
for (auto &direction: directions) {
for (auto& direction : directions) {
auto new_location = coord_wrap(coord + direction);
if (is_location_valid(new_location))
@@ -145,7 +183,7 @@ namespace kami {
return std::move(neighborhood);
}
std::shared_ptr<std::set<AgentID>> Grid1D::get_location_contents(const GridCoord1D &coord) const {
std::shared_ptr<std::set<AgentID>> Grid1D::get_location_contents(const GridCoord1D& coord) const {
auto agent_ids = std::make_shared<std::set<AgentID>>();
if (!is_location_valid(coord))
@@ -162,18 +200,22 @@ namespace kami {
return agent_ids;
}
bool Grid1D::get_wrap_x() const { return _wrap_x; }
bool Grid1D::get_wrap_x() const {
return _wrap_x;
}
unsigned int Grid1D::get_maximum_x() const { return _maximum_x; }
unsigned int Grid1D::get_maximum_x() const {
return _maximum_x;
}
GridCoord1D Grid1D::get_location_by_agent(const AgentID &agent_id) const {
GridCoord1D Grid1D::get_location_by_agent(const AgentID& agent_id) const {
auto coord = _agent_index->find(agent_id);
if (coord == _agent_index->end())
throw error::AgentNotFound(fmt::format("Agent {} not found on grid", agent_id.to_string()));
return coord->second;
}
GridCoord1D Grid1D::coord_wrap(const GridCoord1D &coord) const {
GridCoord1D Grid1D::coord_wrap(const GridCoord1D& coord) const {
auto x = coord.x();
if (_wrap_x)

View File

@@ -50,12 +50,15 @@ namespace kami {
return std::string("(" + std::to_string(_x_coord) + ", " + std::to_string(_y_coord) + ")");
}
double GridCoord2D::distance(std::shared_ptr<Coord> &p) const {
double GridCoord2D::distance(std::shared_ptr<Coord>& p) const {
auto p2d = std::static_pointer_cast<GridCoord2D>(p);
return distance(p2d);
}
double GridCoord2D::distance(std::shared_ptr<GridCoord2D> &p, GridDistanceType distance_type) const {
double GridCoord2D::distance(
std::shared_ptr<GridCoord2D>& p,
GridDistanceType distance_type
) const {
switch (distance_type) {
case GridDistanceType::Chebyshev:
return distance_chebyshev(p);
@@ -68,51 +71,80 @@ namespace kami {
}
}
bool operator==(const GridCoord2D &lhs, const GridCoord2D &rhs) {
bool operator==(
const GridCoord2D& lhs,
const GridCoord2D& rhs
) {
return (lhs._x_coord == rhs._x_coord && lhs._y_coord == rhs._y_coord);
}
bool operator!=(const GridCoord2D &lhs, const GridCoord2D &rhs) {
bool operator!=(
const GridCoord2D& lhs,
const GridCoord2D& rhs
) {
return !(lhs == rhs);
}
std::ostream &operator<<(std::ostream &lhs, const GridCoord2D &rhs) {
std::ostream& operator<<(
std::ostream& lhs,
const GridCoord2D& rhs
) {
return lhs << rhs.to_string();
}
GridCoord2D::GridCoord2D(int x_coord, int y_coord)
: _x_coord(x_coord), _y_coord(y_coord) {}
GridCoord2D::GridCoord2D(
int x_coord,
int y_coord
)
:_x_coord(x_coord), _y_coord(y_coord) {
}
double GridCoord2D::distance_chebyshev(std::shared_ptr<GridCoord2D> &p) const {
double GridCoord2D::distance_chebyshev(std::shared_ptr<GridCoord2D>& p) const {
return static_cast<double>(fmax(abs(_x_coord - p->_x_coord), abs(_x_coord - p->_x_coord)));
}
double GridCoord2D::distance_euclidean(std::shared_ptr<GridCoord2D> &p) const {
double GridCoord2D::distance_euclidean(std::shared_ptr<GridCoord2D>& p) const {
return sqrt(pow(_x_coord - p->_x_coord, 2) + pow(_x_coord - p->_x_coord, 2));
}
double GridCoord2D::distance_manhattan(std::shared_ptr<GridCoord2D> &p) const {
double GridCoord2D::distance_manhattan(std::shared_ptr<GridCoord2D>& p) const {
return static_cast<double>(abs(_x_coord - p->_x_coord) + abs(_x_coord - p->_x_coord));
}
GridCoord2D operator+(const GridCoord2D &lhs, const GridCoord2D &rhs) {
GridCoord2D operator+(
const GridCoord2D& lhs,
const GridCoord2D& rhs
) {
return {lhs._x_coord + rhs._x_coord, lhs._y_coord + rhs._y_coord};
}
GridCoord2D operator-(const GridCoord2D &lhs, const GridCoord2D &rhs) {
GridCoord2D operator-(
const GridCoord2D& lhs,
const GridCoord2D& rhs
) {
return {lhs._x_coord - rhs._x_coord, lhs._y_coord - rhs._y_coord};
}
GridCoord2D operator*(const GridCoord2D &lhs, const double rhs) {
GridCoord2D operator*(
const GridCoord2D& lhs,
const double rhs
) {
return {static_cast<int>(lhs._x_coord * rhs), static_cast<int>(lhs._y_coord * rhs)};
}
GridCoord2D operator*(const double lhs, const GridCoord2D &rhs) {
GridCoord2D operator*(
const double lhs,
const GridCoord2D& rhs
) {
return {static_cast<int>(rhs._x_coord * lhs), static_cast<int>(rhs._y_coord * lhs)};
}
Grid2D::Grid2D(unsigned int maximum_x, unsigned int maximum_y, bool wrap_x,
bool wrap_y) {
Grid2D::Grid2D(
unsigned int maximum_x,
unsigned int maximum_y,
bool wrap_x,
bool wrap_y
) {
_maximum_x = maximum_x;
_maximum_y = maximum_y;
_wrap_x = wrap_x;
@@ -126,7 +158,10 @@ namespace kami {
return delete_agent(agent_id, get_location_by_agent(agent_id));
}
AgentID Grid2D::delete_agent(const AgentID agent_id, const GridCoord2D &coord) {
AgentID Grid2D::delete_agent(
const AgentID agent_id,
const GridCoord2D& coord
) {
for (auto test_agent_id = _agent_grid->find(coord); test_agent_id != _agent_grid->end(); test_agent_id++)
if (test_agent_id->second == agent_id) {
_agent_grid->erase(test_agent_id);
@@ -137,7 +172,7 @@ namespace kami {
throw error::AgentNotFound("Agent not found on grid");
}
bool Grid2D::is_location_valid(const GridCoord2D &coord) const {
bool Grid2D::is_location_valid(const GridCoord2D& coord) const {
auto x = coord.x();
auto y = coord.y();
@@ -145,24 +180,33 @@ namespace kami {
y >= 0 && y < static_cast<int>(_maximum_y));
}
bool Grid2D::is_location_empty(const GridCoord2D &coord) const {
bool Grid2D::is_location_empty(const GridCoord2D& coord) const {
auto grid_location = _agent_grid->equal_range(coord);
return grid_location.first == grid_location.second;
}
AgentID Grid2D::move_agent(const AgentID agent_id, const GridCoord2D &coord) {
AgentID Grid2D::move_agent(
const AgentID agent_id,
const GridCoord2D& coord
) {
return add_agent(delete_agent(agent_id, get_location_by_agent(agent_id)), coord);
}
std::shared_ptr<std::unordered_set<GridCoord2D>>
Grid2D::get_neighborhood(const AgentID agent_id, const bool include_center,
const GridNeighborhoodType neighborhood_type) const {
Grid2D::get_neighborhood(
const AgentID agent_id,
const bool include_center,
const GridNeighborhoodType neighborhood_type
) const {
return std::move(get_neighborhood(get_location_by_agent(agent_id), include_center, neighborhood_type));
}
std::shared_ptr<std::unordered_set<GridCoord2D>>
Grid2D::get_neighborhood(const GridCoord2D &coord, const bool include_center,
const GridNeighborhoodType neighborhood_type) const {
Grid2D::get_neighborhood(
const GridCoord2D& coord,
const bool include_center,
const GridNeighborhoodType neighborhood_type
) const {
auto neighborhood = std::make_unique<std::unordered_set<GridCoord2D>>();
std::vector<GridCoord2D> directions;
@@ -181,7 +225,7 @@ namespace kami {
if (include_center and is_location_valid(coord))
neighborhood->insert(coord);
for (auto &direction: directions) {
for (auto& direction : directions) {
auto new_location = coord_wrap(coord + direction);
if (is_location_valid(new_location))
@@ -191,7 +235,7 @@ namespace kami {
return std::move(neighborhood);
}
std::shared_ptr<std::set<AgentID>> Grid2D::get_location_contents(const GridCoord2D &coord) const {
std::shared_ptr<std::set<AgentID>> Grid2D::get_location_contents(const GridCoord2D& coord) const {
auto agent_ids = std::make_shared<std::set<AgentID>>();
if (!is_location_valid(coord))
@@ -208,22 +252,30 @@ namespace kami {
return agent_ids;
}
bool Grid2D::get_wrap_x() const { return _wrap_x; }
bool Grid2D::get_wrap_x() const {
return _wrap_x;
}
bool Grid2D::get_wrap_y() const { return _wrap_y; }
bool Grid2D::get_wrap_y() const {
return _wrap_y;
}
unsigned int Grid2D::get_maximum_x() const { return _maximum_x; }
unsigned int Grid2D::get_maximum_x() const {
return _maximum_x;
}
unsigned int Grid2D::get_maximum_y() const { return _maximum_y; }
unsigned int Grid2D::get_maximum_y() const {
return _maximum_y;
}
GridCoord2D Grid2D::get_location_by_agent(const AgentID &agent_id) const {
GridCoord2D Grid2D::get_location_by_agent(const AgentID& agent_id) const {
auto coord = _agent_index->find(agent_id);
if (coord == _agent_index->end())
throw error::AgentNotFound(fmt::format("Agent {} not found on grid", agent_id.to_string()));
return coord->second;
}
GridCoord2D Grid2D::coord_wrap(const GridCoord2D &coord) const {
GridCoord2D Grid2D::coord_wrap(const GridCoord2D& coord) const {
auto x = coord.x();
auto y = coord.y();

View File

@@ -33,10 +33,17 @@
namespace kami {
MultiGrid1D::MultiGrid1D(unsigned int maximum_x, bool wrap_x)
: Grid1D(maximum_x, wrap_x) {}
MultiGrid1D::MultiGrid1D(
unsigned int maximum_x,
bool wrap_x
)
:Grid1D(maximum_x, wrap_x) {
}
AgentID MultiGrid1D::add_agent(const AgentID agent_id, const GridCoord1D &coord) {
AgentID MultiGrid1D::add_agent(
const AgentID agent_id,
const GridCoord1D& coord
) {
if (!is_location_valid(coord))
throw error::LocationInvalid(fmt::format("Coordinates {} are invalid", coord.to_string()));

View File

@@ -33,10 +33,19 @@
namespace kami {
MultiGrid2D::MultiGrid2D(unsigned int maximum_x, unsigned int maximum_y, bool wrap_x, bool wrap_y)
: Grid2D(maximum_x, maximum_y, wrap_x, wrap_y) {}
MultiGrid2D::MultiGrid2D(
unsigned int maximum_x,
unsigned int maximum_y,
bool wrap_x,
bool wrap_y
)
:Grid2D(maximum_x, maximum_y, wrap_x, wrap_y) {
}
AgentID MultiGrid2D::add_agent(const AgentID agent_id, const GridCoord2D &coord) {
AgentID MultiGrid2D::add_agent(
const AgentID agent_id,
const GridCoord2D& coord
) {
if (!is_location_valid(coord))
throw error::LocationInvalid(fmt::format("Coordinates {} are invalid", coord.to_string()));

View File

@@ -33,7 +33,7 @@
namespace kami {
AgentID Population::add_agent(const std::shared_ptr<Agent> &agent) noexcept {
AgentID Population::add_agent(const std::shared_ptr<Agent>& agent) noexcept {
auto agent_id = agent->get_agent_id();
_agent_map.insert(std::pair<AgentID, std::shared_ptr<Agent>>(agent_id, agent));
return agent->get_agent_id();
@@ -60,7 +60,10 @@ namespace kami {
}
std::unique_ptr<std::vector<AgentID>> Population::get_agent_list() const {
auto key_selector = [](auto pair) { return pair.first; };
auto key_selector = [](auto pair)
{
return pair.first;
};
auto agent_ids = std::make_unique<std::vector<AgentID>>(_agent_map.size());
transform(_agent_map.begin(), _agent_map.end(), agent_ids->begin(), key_selector);

View File

@@ -41,7 +41,10 @@ namespace kami {
}
std::unique_ptr<std::vector<AgentID>>
RandomScheduler::step(std::shared_ptr<Model> model, std::unique_ptr<std::vector<AgentID>> agent_list) {
RandomScheduler::step(
std::shared_ptr<Model> model,
std::unique_ptr<std::vector<AgentID>> agent_list
) {
if (_rng == nullptr)
throw error::ResourceNotAvailable("No random number generator available");
@@ -50,7 +53,10 @@ namespace kami {
}
std::unique_ptr<std::vector<AgentID>>
RandomScheduler::step(std::shared_ptr<ReporterModel> model, std::unique_ptr<std::vector<AgentID>> agent_list) {
RandomScheduler::step(
std::shared_ptr<ReporterModel> model,
std::unique_ptr<std::vector<AgentID>> agent_list
) {
if (_rng == nullptr)
throw error::ResourceNotAvailable("No random number generator available");
@@ -63,6 +69,8 @@ namespace kami {
return _rng;
}
std::shared_ptr<std::mt19937> RandomScheduler::get_rng() { return (this->_rng); }
std::shared_ptr<std::mt19937> RandomScheduler::get_rng() {
return (this->_rng);
}
} // namespace kami

View File

@@ -70,23 +70,28 @@ namespace kami {
}
std::unique_ptr<nlohmann::json>
Reporter::collect(const std::shared_ptr<ReporterModel> &model) {
Reporter::collect(const std::shared_ptr<ReporterModel>& model) {
auto pop = model->get_population();
return collect(model, pop);
}
std::unique_ptr<nlohmann::json>
Reporter::collect(const std::shared_ptr<ReporterModel> &model, const std::shared_ptr<Population> &pop) {
Reporter::collect(
const std::shared_ptr<ReporterModel>& model,
const std::shared_ptr<Population>& pop
) {
auto agent_list = pop->get_agent_list();
return collect(model, agent_list);
}
std::unique_ptr<nlohmann::json>
Reporter::collect(const std::shared_ptr<ReporterModel> &model,
const std::unique_ptr<std::vector<AgentID>> &agent_list) {
Reporter::collect(
const std::shared_ptr<ReporterModel>& model,
const std::unique_ptr<std::vector<AgentID>>& agent_list
) {
auto collection_array = std::vector<nlohmann::json>();
for (auto &agent_id: *agent_list) {
for (auto& agent_id : *agent_list) {
auto agent_data = nlohmann::json();
auto agent = std::static_pointer_cast<ReporterAgent>(model->get_population()->get_agent_by_id(agent_id));
@@ -112,7 +117,7 @@ namespace kami {
return std::move(collection);
}
std::unique_ptr<nlohmann::json> Reporter::report(const std::shared_ptr<ReporterModel> &model) {
std::unique_ptr<nlohmann::json> Reporter::report(const std::shared_ptr<ReporterModel>& model) {
auto json_data = std::make_unique<nlohmann::json>(*_report_data);
return std::move(json_data);
}

View File

@@ -43,12 +43,15 @@ namespace kami {
}
std::unique_ptr<std::vector<AgentID>>
SequentialScheduler::step(std::shared_ptr<Model> model, std::unique_ptr<std::vector<AgentID>> agent_list) {
SequentialScheduler::step(
std::shared_ptr<Model> model,
std::unique_ptr<std::vector<AgentID>> agent_list
) {
auto return_agent_list = std::make_unique<std::vector<AgentID>>();
auto population = model->get_population();
Scheduler::_step_counter++;
for (auto &agent_id: *agent_list) {
for (auto& agent_id : *agent_list) {
auto agent = population->get_agent_by_id(agent_id);
agent->step(model);
@@ -59,12 +62,15 @@ namespace kami {
}
std::unique_ptr<std::vector<AgentID>>
SequentialScheduler::step(std::shared_ptr<ReporterModel> model, std::unique_ptr<std::vector<AgentID>> agent_list) {
SequentialScheduler::step(
std::shared_ptr<ReporterModel> model,
std::unique_ptr<std::vector<AgentID>> agent_list
) {
auto return_agent_list = std::make_unique<std::vector<AgentID>>();
auto population = model->get_population();
Scheduler::_step_counter++;
for (auto &agent_id: *agent_list) {
for (auto& agent_id : *agent_list) {
auto agent = population->get_agent_by_id(agent_id);
agent->step(model);

View File

@@ -31,10 +31,17 @@
namespace kami {
SoloGrid1D::SoloGrid1D(unsigned int maximum_x, bool wrap_x)
: Grid1D(maximum_x, wrap_x) {}
SoloGrid1D::SoloGrid1D(
unsigned int maximum_x,
bool wrap_x
)
:Grid1D(maximum_x, wrap_x) {
}
AgentID SoloGrid1D::add_agent(const AgentID agent_id, const GridCoord1D &coord) {
AgentID SoloGrid1D::add_agent(
const AgentID agent_id,
const GridCoord1D& coord
) {
if (!is_location_valid(coord))
throw error::LocationInvalid(fmt::format("Coordinates {} are invalid", coord.to_string()));
if (!is_location_empty(coord))

View File

@@ -33,10 +33,19 @@
namespace kami {
SoloGrid2D::SoloGrid2D(unsigned int maximum_x, unsigned int maximum_y, bool wrap_x, bool wrap_y)
: Grid2D(maximum_x, maximum_y, wrap_x, wrap_y) {}
SoloGrid2D::SoloGrid2D(
unsigned int maximum_x,
unsigned int maximum_y,
bool wrap_x,
bool wrap_y
)
:Grid2D(maximum_x, maximum_y, wrap_x, wrap_y) {
}
AgentID SoloGrid2D::add_agent(const AgentID agent_id, const GridCoord2D &coord) {
AgentID SoloGrid2D::add_agent(
const AgentID agent_id,
const GridCoord2D& coord
) {
if (!is_location_valid(coord))
throw error::LocationInvalid(fmt::format("Coordinates {} are invalid", coord.to_string()));
if (!is_location_empty(coord))

View File

@@ -35,13 +35,19 @@
namespace kami {
std::unique_ptr<std::vector<AgentID>>
StagedScheduler::step(std::shared_ptr<Model> model, std::unique_ptr<std::vector<AgentID>> agent_list) {
StagedScheduler::step(
std::shared_ptr<Model> model,
std::unique_ptr<std::vector<AgentID>> agent_list
) {
auto stepped_agent_list = this->SequentialScheduler::step(model, std::move(agent_list));
return std::move(this->advance(model, std::move(stepped_agent_list)));
}
std::unique_ptr<std::vector<AgentID>>
StagedScheduler::step(std::shared_ptr<ReporterModel> model, std::unique_ptr<std::vector<AgentID>> agent_list) {
StagedScheduler::step(
std::shared_ptr<ReporterModel> model,
std::unique_ptr<std::vector<AgentID>> agent_list
) {
auto stepped_agent_list = this->SequentialScheduler::step(model, std::move(agent_list));
return std::move(this->advance(model, std::move(stepped_agent_list)));
}
@@ -57,11 +63,14 @@ namespace kami {
}
std::unique_ptr<std::vector<AgentID>>
StagedScheduler::advance(std::shared_ptr<Model> model, std::unique_ptr<std::vector<AgentID>> agent_list) {
StagedScheduler::advance(
std::shared_ptr<Model> model,
std::unique_ptr<std::vector<AgentID>> agent_list
) {
auto return_agent_list = std::make_unique<std::vector<AgentID>>();
auto population = model->get_population();
for (auto &agent_id: *agent_list) {
for (auto& agent_id : *agent_list) {
auto agent = std::static_pointer_cast<StagedAgent>(population->get_agent_by_id(agent_id));
agent->advance(model);