parallel-cellular-automata
Framework for building parallel cellular automata.
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ca::ffl::CellularAutomaton< T > Class Template Reference

Public Member Functions

 CellularAutomaton (ca::Grid< T > &grid, std::function< T(T, T, T, T, T, T, T, T, T)> update_function, unsigned workers=0)
 Construct a new Cellular Automaton object. More...
 
 CellularAutomaton (CellularAutomaton &&other)
 Construct a new Cellular Automaton object from another one using move semantic. More...
 
 CellularAutomaton (const CellularAutomaton &other)=delete
 Deleted copy constructor. More...
 
virtual void simulate (unsigned steps=1)
 Run the simulation for a given number of steps. More...
 
virtual size_t get_generation () const
 Get the generation of the simulation. More...
 

Protected Member Functions

virtual std::tuple< T, T, T, T, T, T, T, T > get_neighborhood (int row, int col) const
 Get the neighborhood of a cell. More...
 

Protected Attributes

Grid< T > & grid
 Grid of the C.A.
 
size_t generation
 Current generation of the grid.
 
std::function< T(T, T, T, T, T, T, T, T, T)> update_function
 Function used to compute the next state of the cell. More...
 
unsigned nw
 Number of worker threads.
 
ff::ParallelFor pf
 parallel for pattern run-time suppor
 

Friends

std::ostream & operator<< (std::ostream &os, const CellularAutomaton &ca)
 Overload of the << operator. More...
 

Constructor & Destructor Documentation

◆ CellularAutomaton() [1/3]

template<typename T >
ca::ffl::CellularAutomaton< T >::CellularAutomaton ( ca::Grid< T > &  grid,
std::function< T(T, T, T, T, T, T, T, T, T)>  update_function,
unsigned  workers = 0 
)
inline

Construct a new Cellular Automaton object.

Parameters
gridGrid of the simulation.
rowsNumber of rows of the grid.
columnsNumber of columns of the grid.
update_functionFunction used to update the state of the grid.
nwNumber of workers (0 == hadrwareconcurrency) (default 0).

◆ CellularAutomaton() [2/3]

template<typename T >
ca::ffl::CellularAutomaton< T >::CellularAutomaton ( CellularAutomaton< T > &&  other)
inline

Construct a new Cellular Automaton object from another one using move semantic.

Note
The old object will be left in a valid but unspecified state.
Parameters
otherCellularAutomaton to move.

◆ CellularAutomaton() [3/3]

template<typename T >
ca::ffl::CellularAutomaton< T >::CellularAutomaton ( const CellularAutomaton< T > &  other)
delete

Deleted copy constructor.

Note
The copy constructor has been deleted since the class uses a pointer to a user defined grid and the freeing of the grid is up to them.

Member Function Documentation

◆ get_generation()

template<typename T >
virtual size_t ca::ffl::CellularAutomaton< T >::get_generation ( ) const
inlinevirtual

Get the generation of the simulation.

Returns
size_t value of the generation member variable.

◆ get_neighborhood()

template<typename T >
virtual std::tuple<T, T, T, T, T, T, T, T> ca::ffl::CellularAutomaton< T >::get_neighborhood ( int  row,
int  col 
) const
inlineprotectedvirtual

Get the neighborhood of a cell.

+----+-----------+----+
| TL | T | TR |
+----+-----------+----+
| L | (row,col) | R |
+----+-----------+----+
| BL | B | BR |
+----+-----------+----+
Precondition
0 <= row < rows.
0 <= col < columns.
Parameters
rowrow of the center cell.
colcolumn of the center cell.
Returns
std::tuple<T, T, T, T, T, T, T, T> containing <TL, T, TR, L, R, BL, B, BR>

◆ simulate()

template<typename T >
virtual void ca::ffl::CellularAutomaton< T >::simulate ( unsigned  steps = 1)
inlinevirtual

Run the simulation for a given number of steps.

Parameters
stepsnumber of simulation steps to run (default 1).
Postcondition
grid contains the result of the simulation and generation = generation + steps.

Friends And Related Function Documentation

◆ operator<<

template<typename T >
std::ostream& operator<< ( std::ostream &  os,
const CellularAutomaton< T > &  ca 
)
friend

Overload of the << operator.

Print the grid on a output stream.

Parameters
osoutput stream
caCellularAutomaton
Returns
std::ostream& reference to the output stream

Member Data Documentation

◆ update_function

template<typename T >
std::function<T(T, T, T, T, T, T, T, T, T)> ca::ffl::CellularAutomaton< T >::update_function
protected

Function used to compute the next state of the cell.

The function takes nine arguments. It will be called by passing the central cell as first argument and its eight neighbors as the remaining arguments. Their order is the one returned by the get_neighborhood function.

See also
get_neighborhood

The documentation for this class was generated from the following file: