1#ifndef UTOPIA_MODELS_GAMEOFLIFE_HH
2#define UTOPIA_MODELS_GAMEOFLIFE_HH
114 template<
class ParentModel>
141 this->
_log->debug(
"{} model fully set up.", this->
_name);
156 auto b =
static_cast<unsigned short>(
b_char -
'0');
176 auto b =
static_cast<unsigned short>(
b_char -
'0');
198 auto state =
cell->state;
203 if (
nb->state.living) {
214 state.living =
false;
252 this->
_monitor.set_entry(
"living_cell_density",
264 _dset_living->write(
_cm.
cells().begin(),
266 [](
const auto&
cell) {
267 return static_cast<char>(cell->state.living);
typename std::function< CellState(const std::shared_ptr< Cell > &)> RuleFunc
The type of a rule function acting on cells of this cell manager.
Definition cell_manager.hh:84
CellContainer< Cell > select_cells(Args &&... args) const
Select cells using the Utopia::select_entities interface.
Definition cell_manager.hh:342
CellContainer< Cell > neighbors_of(const Cell &cell) const
Retrieve the given cell's neighbors.
Definition cell_manager.hh:458
const CellContainer< Cell > & cells() const
Return const reference to the managed CA cells.
Definition cell_manager.hh:219
Base class interface for Models using the CRT Pattern.
Definition model.hh:112
std::shared_ptr< DataSet > create_cm_dset(const std::string name, const CellManager &cm, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={})
Create a dataset storing data from a CellManager.
Definition model.hh:849
Monitor _monitor
The monitor.
Definition model.hh:188
typename ModelTypes::DataSet DataSet
Data type that is used for storing data.
Definition model.hh:125
const Config _cfg
Config node belonging to this model instance.
Definition model.hh:158
const std::string _name
Name of the model instance.
Definition model.hh:149
typename ModelTypes::DataGroup DataGroup
Data type that is used for storing datasets.
Definition model.hh:122
const std::shared_ptr< spdlog::logger > _log
The (model) logger.
Definition model.hh:164
The GameOfLife Model.
Definition GameOfLife.hh:57
const NbLifeRule _birth
The number of neighbors required to get born.
Definition GameOfLife.hh:97
const NbLifeRule _survive
The number of neighbors required to survive.
Definition GameOfLife.hh:100
std::shared_ptr< DataSet > _dset_living
A dataset for storing all cells living or dead status.
Definition GameOfLife.hh:106
const std::string _rule
The rule in Mirek's Cellebration notation.
Definition GameOfLife.hh:94
double calculate_living_cell_density() const
Calculate the mean of all cells' some_state.
Definition GameOfLife.hh:185
typename Base::DataGroup DataGroup
Data type of the group to write model data to, holding datasets.
Definition GameOfLife.hh:63
typename Base::DataSet DataSet
Data type for a dataset.
Definition GameOfLife.hh:66
const RuleFunc _life_rule
Implement the general life-like rule.
Definition GameOfLife.hh:196
NbLifeRule extract_birth_from_rule()
Extract the number of neighbors required for birth from the rule.
Definition GameOfLife.hh:147
CellManager _cm
The cell manager.
Definition GameOfLife.hh:91
NbLifeRule extract_survive_from_rule()
Extract the number of neighbors required to survive from the rule.
Definition GameOfLife.hh:163
typename CellManager::RuleFunc RuleFunc
Extract the type of the rule function from the CellManager.
Definition GameOfLife.hh:83
void monitor()
Monitor model information.
Definition GameOfLife.hh:250
std::unordered_set< unsigned short > NbLifeRule
Type of container to store the number of neighbors for the life rule.
Definition GameOfLife.hh:73
void perform_step()
Iterate a single step.
Definition GameOfLife.hh:235
void write_data()
Write data.
Definition GameOfLife.hh:261
GameOfLife(const std::string name, ParentModel &parent)
Construct the GameOfLife model.
Definition GameOfLife.hh:115
ReturnType get_as(const std::string &key, const DataIO::Config &node)
This function is a wrapper around the yaml-cpp YAML::Node::as function.
Definition cfg_utils.hh:158
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
Definition GameOfLife.hh:19
Definition parallel.hh:235
The entity traits struct gathers types to be used for specializing an entity.
Definition entity.hh:49
Wrapper struct for defining model class data types.
Definition model.hh:92
The type of a cell's state.
Definition GameOfLife.hh:24
CellState()
Construct the cell state with all dead cells as default.
Definition GameOfLife.hh:36
bool living
Whether a cell lives or not.
Definition GameOfLife.hh:26