Nano v1.0.0
Simulating Natural Selection
ss::bll::simulation::Simulation Class Reference

A class representing the simulation. More...

#include <simulation.h>

Public Member Functions

const std::vector< Food > & getFoods () const
 Getter for all the food particles. More...
 
const EntitygetEntityById (size_t id)
 Getter for entity by id. More...
 
void setEntityTraits (size_t id, const types::Trait &traits)
 Sets the traits of an entity. More...
 
 Simulation (types::SimulationInfo t_simInfo)
 Constructor for the Simulation class. More...
 
size_t getTotalAliveEntities () const
 Calculates the amount of the total alive entities. More...
 
size_t getTotalDiedEntities () const
 Calculates the amount of the total died entities. More...
 
types::Trait getAvgTraits () const
 Calculates the average traits of all entities for the whole simulation. More...
 
void saveSimulationInfo (std::optional< std::string > fileName) const
 Generates and attempts to save all of the information gathered throughout the simulation. More...
 
void update (float elapsedTime)
 Updates the simulation. More...
 
void setFoodChange (int foodChange)
 

Static Public Member Functions

static std::span< EntitygetActiveEntities (std::vector< Entity > &entities, std::vector< Entity >::iterator &iter)
 Returns only the alive entities in the current cycle. More...
 
static void repositionEntitiesIter (std::vector< Entity > &entities, std::vector< Entity >::iterator &iter)
 Sets an appropriate position for the iterator used to mark the point between the alive and dead entities in the entities' container. More...
 

Public Attributes

types::SimulationInfo m_simInfo
 
std::vector< Entitym_entities
 
std::vector< Entity >::iterator m_entitiesEndIt
 
std::vector< Foodm_foods
 
size_t m_lastEntityId = 1
 
size_t m_currentCycle_n = 1
 
Cycle m_currentCycle
 
bool isSimulationDone = false
 

Private Member Functions

void cleanEntities ()
 Cleans up unused entities after the simulation has finished. More...
 

Friends

class Cycle
 

Detailed Description

A class representing the simulation.

This class holds all the information and logic for the simulation to be able to manage all of it's subclasses (not in inheritance meaning).

Constructor & Destructor Documentation

◆ Simulation()

ss::bll::simulation::Simulation::Simulation ( types::SimulationInfo  t_simInfo)

Constructor for the Simulation class.

Constructs the Simulation class with approriate ss::types::SimulationInfo.

Parameters
t_simInfoobject of user defined type ss::types::SimulationInfo holding the data.

Member Function Documentation

◆ cleanEntities()

void ss::bll::simulation::Simulation::cleanEntities ( )
private

Cleans up unused entities after the simulation has finished.

◆ getActiveEntities()

std::span< ss::bll::simulation::Entity > ss::bll::simulation::Simulation::getActiveEntities ( std::vector< Entity > &  entities,
std::vector< Entity >::iterator &  iter 
)
static

Returns only the alive entities in the current cycle.

Returns
a span looking into only the alive entiites.

◆ getAvgTraits()

ss::types::Trait ss::bll::simulation::Simulation::getAvgTraits ( ) const

Calculates the average traits of all entities for the whole simulation.

Returns
a trait object with the average sense and speed values for the whole simulation.

◆ getEntityById()

const ss::bll::simulation::Entity * ss::bll::simulation::Simulation::getEntityById ( size_t  id)

Getter for entity by id.

Parameters
idThe id of the wanted entity.
Returns
nullptr if there is no entity with specified id. Else returns a constant pointer to the specified entity.

◆ getFoods()

const std::vector< ss::bll::simulation::Food > & ss::bll::simulation::Simulation::getFoods ( ) const

Getter for all the food particles.

Returns
a constant reference to the container of foods.

◆ getTotalAliveEntities()

size_t ss::bll::simulation::Simulation::getTotalAliveEntities ( ) const

Calculates the amount of the total alive entities.

Returns
the count of once alive entities.

◆ getTotalDiedEntities()

size_t ss::bll::simulation::Simulation::getTotalDiedEntities ( ) const

Calculates the amount of the total died entities.

Returns
the count of all died entities.

◆ repositionEntitiesIter()

void ss::bll::simulation::Simulation::repositionEntitiesIter ( std::vector< Entity > &  entities,
std::vector< Entity >::iterator &  iter 
)
static

Sets an appropriate position for the iterator used to mark the point between the alive and dead entities in the entities' container.

◆ saveSimulationInfo()

void ss::bll::simulation::Simulation::saveSimulationInfo ( std::optional< std::string >  fileName) const

Generates and attempts to save all of the information gathered throughout the simulation.

Note
Rethrows all exceptions caught from DAL so the must be handled by the caller.

◆ setEntityTraits()

void ss::bll::simulation::Simulation::setEntityTraits ( size_t  id,
const types::Trait traits 
)

Sets the traits of an entity.

Parameters
idThe id of the entity whose traits you want to edit.
traitsThe traits you want to be set on the entity.

◆ setFoodChange()

void ss::bll::simulation::Simulation::setFoodChange ( int  foodChange)

◆ update()

void ss::bll::simulation::Simulation::update ( float  elapsedTime)

Updates the simulation.

Checks if the simulation is over and updates the current cycle.

Friends And Related Function Documentation

◆ Cycle

friend class Cycle
friend

Member Data Documentation

◆ isSimulationDone

bool ss::bll::simulation::Simulation::isSimulationDone = false

◆ m_currentCycle

Cycle ss::bll::simulation::Simulation::m_currentCycle

◆ m_currentCycle_n

size_t ss::bll::simulation::Simulation::m_currentCycle_n = 1

◆ m_entities

std::vector<Entity> ss::bll::simulation::Simulation::m_entities

◆ m_entitiesEndIt

std::vector<Entity>::iterator ss::bll::simulation::Simulation::m_entitiesEndIt

◆ m_foods

std::vector<Food> ss::bll::simulation::Simulation::m_foods

◆ m_lastEntityId

size_t ss::bll::simulation::Simulation::m_lastEntityId = 1

◆ m_simInfo

types::SimulationInfo ss::bll::simulation::Simulation::m_simInfo

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