Utopia 2
Framework for studying models of complex & adaptive systems.
|
An interface to select a subset of entities from a manager. More...
Modules | |
SelectionModes | |
Namespaces | |
namespace | Utopia |
Classes | |
struct | Utopia::is_cell_manager< M > |
Metafunction to determine whether a Manager is a CellManager. More... | |
struct | Utopia::is_agent_manager< M > |
Metafunction to determine whether a Manager is an AgentManager. More... | |
Functions | |
template<class Manager , class Container = EntityContainer<typename Manager::Entity>> | |
Container | Utopia::select_entities (const Manager &mngr, const DataIO::Config &sel_cfg) |
Select entities according to parameters specified in a configuration. | |
template<SelectionMode mode, class Manager , class Container = EntityContainer<typename Manager::Entity>, class Condition = std::function<bool(const std::shared_ptr<typename Manager::Entity>&)>, typename std::enable_if_t< mode==SelectionMode::condition, int > = 0> | |
Container | Utopia::select_entities (const Manager &mngr, const Condition &condition) |
Return a container with entities that match the given condition. | |
template<SelectionMode mode, class Manager , class Container = EntityContainer<typename Manager::Entity>, typename std::enable_if_t< mode==SelectionMode::sample, int > = 0> | |
Container | Utopia::select_entities (const Manager &mngr, const int num_entities) |
Select a sample of entities randomly. | |
template<SelectionMode mode, class Manager , class Container = EntityContainer<typename Manager::Entity>, typename std::enable_if_t< mode==SelectionMode::probability, int > = 0> | |
Container | Utopia::select_entities (const Manager &mngr, const double probability) |
Select entities with a certain probability. | |
template<SelectionMode mode, class Manager , class Container = EntityContainer<typename Manager::Entity>, typename std::enable_if_t< mode==SelectionMode::position, int > = 0> | |
Container | Utopia::select_entities (const Manager &mngr, const std::vector< typename Manager::SpaceVec > &positions) |
Selects cells at given positions in space. | |
template<SelectionMode mode, class Manager , class Container = EntityContainer<typename Manager::Entity>, typename std::enable_if_t< mode==SelectionMode::boundary, int > = 0> | |
Container | Utopia::select_entities (const Manager &mngr, const std::string &boundary) |
Selects cells on a boundary. | |
template<SelectionMode mode, class Manager , class Container = EntityContainer<typename Manager::Entity>, typename std::enable_if_t< mode==SelectionMode::lanes, int > = 0> | |
Container | Utopia::select_entities (const Manager &mngr, const unsigned int num_vertical, const unsigned int num_horizontal, const std::pair< double, double > permeability={0., 0.}, const std::pair< unsigned int, unsigned int > gate_width={0, 0}) |
Selects horizontal or vertical lanes of cells. | |
template<SelectionMode mode, class Manager , class Container = EntityContainer<typename Manager::Entity>, typename std::enable_if_t< mode==SelectionMode::clustered_simple, int > = 0> | |
Container | Utopia::select_entities (const Manager &mngr, const double p_seed, const double p_attach, const unsigned int num_passes) |
Selects cells that are clustered using a simple clustering algorithm. | |
An interface to select a subset of entities from a manager.
The Utopia constructs Utopia::Cell and Utopia::Agent both have a common parent type: Utopia::Entity. Additionally, there are corresponding manager types that provide an interface to work with these entities: Utopia::CellManager and Utopia::AgentManager.
Given this structure, Utopia is able to provide a common interface with which a subset of entities can be selected in a consistent and configurable fashion. This allows to re-use the selection algorithms and while also allowing specializations for certain entity types.
The interface requires managers of Utopia::Entity -derived types; let's call them EntityManagers
for now. (Side note: The interface is currently only assumed; the CellManager and AgentManager are yet to be based on a common base class). These managers provide the embedding of a container of entities, which is required as soon as more complicated selections are to be performed, e.g. selecting cells that are distributed in a certain pattern in space.
For the mode of selection, the Utopia::SelectionMode is used. For each mode value, a Utopia::select_entities method is specialized. That method defines the parameters required for the selection. The whole interface is made accessible via configuration by the specialization that accepts a Utopia::DataIO::Config as argument. Furthermore, the entity managers can implement a method that makes use of the free functions defined here, for example Utopia::CellManager::select_entities .
This selection interface has a similar motivation as the Utopia::apply_rule interface; in fact, it cooperates nicely with that interface, as you can first select some entities and then apply an operation to them...
Container Utopia::select_entities | ( | const Manager & | mngr, |
const Condition & | condition | ||
) |
Return a container with entities that match the given condition.
mngr | The manager to select the entities from |
condition | A unary function working on a single entity and returning a boolean. |
Container Utopia::select_entities | ( | const Manager & | mngr, |
const DataIO::Config & | sel_cfg | ||
) |
Select entities according to parameters specified in a configuration.
Via the mode
key, one of the modes (see Utopia::SelectionMode) can be selected. Depending on that mode, the other parameters are extracted from the configuration.
Available keys for each mode:
sample
mode: num_cells
probability
mode: probability
positions
mode: positions
(a list of coordinate pairs)boundary
mode: boundary
(a string, e.g. left
, right
, top
, bottom
)lanes
mode: num_horizontal
, num_vertical
, permeability
(optional; can be given as scalar, pair, or mapping w/ keys horizontal
and vertical
), gate_width
(optional, same as permeability
)clustered_simple
mode: p_seed
, p_attach
, num_passes
mngr | The manager to select the entities from |
sel_cfg | The configuration node containing the expected key-value pairs specifying the selection. |
Container Utopia::select_entities | ( | const Manager & | mngr, |
const double | p_seed, | ||
const double | p_attach, | ||
const unsigned int | num_passes | ||
) |
Selects cells that are clustered using a simple clustering algorithm.
This is done by first determining some "seed" cells and then attaching their neighbors to them with a certain probability.
mngr | The manager to select the entities from. Needs to be a Utopia::CellManager for this function. |
p_seed | The probability with which a cell becomes a seed for a cluster |
p_attach | The probability with which a neighbor of a cluster cell is also added to the cluster |
num_passes | How often to invoke the attachment iteration |
Container Utopia::select_entities | ( | const Manager & | mngr, |
const double | probability | ||
) |
Select entities with a certain probability.
Iterates over all entities and selects each entity with the given probability.
mngr | The manager to select the entities from |
probability | The probablity with which a single entity is selected |
Container Utopia::select_entities | ( | const Manager & | mngr, |
const int | num_entities | ||
) |
Select a sample of entities randomly.
Uses std::sample to select num_entities
randomly.
mngr | The manager to select the entities from |
num_entities | The number of entities to sample from the given container. Need be a value in [0, container size] |
Container Utopia::select_entities | ( | const Manager & | mngr, |
const std::string & | boundary | ||
) |
Selects cells on a boundary.
Invokes CellManager::boundary_cells
mngr | The manager to select the entities from. Needs to be a Utopia::CellManager for this work. |
boundary | Which boundary to select. |
Container Utopia::select_entities | ( | const Manager & | mngr, |
const std::vector< typename Manager::SpaceVec > & | positions | ||
) |
Selects cells at given positions in space.
Invokes CellManager::cell_at to populate a container of cells that are at the given absolute positions. Which cells are selected depends on the chosen discretization, see Utopia::Grid and the derived classes.
mngr | The manager to select the entities from. Needs to be a Utopia::CellManager for this work. |
positions | Absolute positions; the cells under these positions are then selected. |
Container Utopia::select_entities | ( | const Manager & | mngr, |
const unsigned int | num_vertical, | ||
const unsigned int | num_horizontal, | ||
const std::pair< double, double > | permeability = {0., 0.} , |
||
const std::pair< unsigned int, unsigned int > | gate_width = {0, 0} |
||
) |
Selects horizontal or vertical lanes of cells.
The lanes are spaced such that the domain is divided into N equally large parts for periodic space and N+1 parts for non-periodic space in each dimension.
For example:
Calculation occurs by first determining the relative position along the corresponding dimension at which a lane is to occur. From that, the multi- multi-index is computed, and then all cells that match the desired multi index component are selected to become part of the lane. This is done on the grid level, i.e.: on the level of multi indices. As all grid discretizations can operate on multi-indices, this approach is valid among all types of grid discretizations.
mngr | The manager to select the entities from. Needs to be a Utopia::CellManager . |
num_vertical | Number of vertical lanes |
num_horizontal | Number of horizontal lanes |
permeability | The permeability of the horizontal and vertical lanes, respectively. The probability that a cell is spared out. Optional. |
gate_width | The width of gates in the horizontal and vertical lanes, respectively. Given in number of cells per compartment, i.e. between two lanes. Optional. |