![]() |
fpmas 1.6
|
#include <grid_builder.h>
Public Member Functions | |
GridBuilder (api::model::GridCellFactory< CellType > &cell_factory, DiscreteCoordinate width, DiscreteCoordinate height) | |
GridBuilder (DiscreteCoordinate width, DiscreteCoordinate height) | |
DiscreteCoordinate | width () const |
DiscreteCoordinate | height () const |
std::vector< CellType * > | build (api::model::SpatialModel< CellType > &spatial_model) const override |
std::vector< CellType * > | build (api::model::SpatialModel< CellType > &spatial_model, api::model::GroupList groups) const override |
void | initSample (std::size_t n, std::function< void(CellType *)> init_function) const |
template<typename T > | |
void | initSequence (const std::vector< T > &items, std::function< void(CellType *, typename std::vector< T >::const_reference)> init_function) const |
virtual std::vector< CellType * > | build (SpatialModel< CellType > &spatial_model) const =0 |
virtual std::vector< CellType * > | build (SpatialModel< CellType > &spatial_model, GroupList groups) const =0 |
Static Public Attributes | |
static GridCellFactory< CellType > | default_cell_factory |
Protected Types | |
typedef std::vector< std::vector< CellType * > > | CellMatrix |
Protected Member Functions | |
virtual void | buildLocalGrid (api::model::SpatialModel< CellType > &model, GridDimensions local_dimensions, CellMatrix &cells) const =0 |
virtual void | linkFrontiers (api::model::SpatialModel< CellType > &model, GridDimensions local_dimensions, CellMatrix &local_cells, std::vector< CellType * > &frontier) const =0 |
Grid builder base class.
This class defines a generic algorithm that can be used to build VonNeumann or Moore grids.
|
protected |
Type used to describe a cell matrix.
By convention, the first index represent lines, the second represents columns.
|
inline |
GridBuilder constructor.
The cell_factory
parameter allows to build the grid using custom GridCell extensions (with extra user defined behaviors for example).
cell_factory | custom cell factory, that will be used instead of default_cell_factory |
width | width of the grid |
height | height of the grid |
|
inline |
GridBuilder constructor.
The grid will be built using the default_cell_factory.
width | width of the grid |
height | height of the grid |
|
protectedpure virtual |
Builds links between cells on the current process to build the required grid shape.
The specified CellMatrix shape is [local_dimensions.height()][local_dimensions.width()], and cells locations are initialized accordingly, i.e. the cell at cells[j][i]
is located at DiscretePoint(i, j). (j = line index = y coordinate, i = column index = x coordinate)
Links across processes should not be considered in this method.
model | model in which cells are built |
local_dimensions | dimension of the local grid, that is only a subpart of the global grid |
cells | matrix containing LOCAL cells built on the current process |
|
protectedpure virtual |
Links the DISTANT cells in frontier
to the appropriate local_cells
to build the required grid shape.
The order of cells in frontier
is not guaranteed, but it is ensured that the provided DISTANT cells complete, if required, the Moore neighborhood of all cells in local_cells
.
For example, if local_dimensions
and local_cells
provide the following LOCAL cells:
then the frontier corresponds to the following cells:
In this example, angles are provided even if the implementation is supposed to build the VonNeumann neighborhood of each cells. In other terms, it is safe to ignore cells provided in the frontier.
|
inline |
Grid width.
|
inline |
Grid height.
|
inlineoverridevirtual |
Builds a grid into the specified spatial_model
, according to the grid shape specified by the buildLocalGrid(), linkHorizontalFrontiers() and linkVerticalFrontiers() methods.
The process is distributed so that each available process instantiates a part of the global grid.
The size of the global grid is equal to width x height
, according to the parameters specified in the constructor. The origin of the grid is considered at (0, 0), and so the opposite corner is at (width-1, height-1).
Each GridCell is built using the cell_factory
specified in the constructor, the default_cell_factory
otherwise.
spatial_model | spatial model in which cells will be added |
Implements fpmas::api::model::CellNetworkBuilder< CellType >.
|
inlineoverridevirtual |
Same as build(spatial_model)
, but also adds built cells to groups
, in order to assign behaviors to cells.
spatial_model | spatial model in which cells will be added |
groups | groups to which built cells will be added |
Implements fpmas::api::model::CellNetworkBuilder< CellType >.
void fpmas::model::detail::GridBuilder< CellType >::initSample | ( | std::size_t | n, |
std::function< void(CellType *)> | init_function | ||
) | const |
Initializes a sample of n
cells selected from the previously built cells with the provided init_function
.
The sample of cells selected is deterministic: it is guaranteed that the same cells are initialized independently of the current distribution.
The selection process can be seeded with fpmas::seed().
Successive calls can be used to independently initialize several cell states.
n | sample size |
init_function | initialization function |
void fpmas::model::detail::GridBuilder< CellType >::initSequence | ( | const std::vector< T > & | items, |
std::function< void(CellType *, typename std::vector< T >::const_reference)> | init_function | ||
) | const |
Sequentially initializes built cells from the input items
.
Each item is assigned to a cell using the specified init_function
.
The item assignment is deterministic: it is guaranteed that each cell is always initialized with the same item independently of the current distribution.
items | Items to assign to built cells. The number of items must be greater or equal to the total number of built cells, N=width()*height() . Only the first N items are assigned, other are ignored. |
init_function | item assignment function |
|
static |
Default GridCellFactory.