Empirical
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
emp::World< ORG > Class Template Reference

Setup a World with a population of organisms that can evolve or deal with ecological effects. More...

#include <World.h>

Public Types

using this_t = World< ORG >
 Resolved type of this templated class. More...
 
using org_t = ORG
 Type of organisms in this world. More...
 
using value_type = org_t
 Identical to org_t; vector compatibility. More...
 
using pop_t = emp::vector< Ptr< ORG >>
 Type for whole populations. More...
 
using iterator_t = World_iterator< this_t >
 Type for this world's iterators. More...
 
using fit_cache_t = emp::vector< double >
 Type for fitness caches for pops. More...
 
using genome_t = typename emp::find_genome_t< ORG >
 Type of underlying genomes. More...
 
using fun_calc_fitness_t = std::function< double(ORG &)>
 Function type for calculating fitness. More...
 
using fun_calc_dist_t = std::function< double(ORG &, ORG &)>
 Function type for calculating the distance between two organisms. More...
 
using fun_do_mutations_t = std::function< size_t(ORG &, Random &)>
 Function type for a mutation operator on an organism. More...
 
using fun_print_org_t = std::function< void(ORG &, std::ostream &)>
 Function type for printing an organism's info to an output stream. More...
 
using fun_get_genome_t = std::function< const genome_t &(ORG &)>
 Function type for retrieving a genome from an organism. More...
 
using fun_find_inject_pos_t = std::function< WorldPosition(Ptr< ORG >)>
 Function type for injecting organisms into a world (returns inject position) More...
 
using fun_find_birth_pos_t = std::function< WorldPosition(Ptr< ORG >, WorldPosition)>
 Function type for adding a newly born organism into a world (returns birth position) More...
 
using fun_kill_org_t = std::function< WorldPosition()>
 Function type for determining picking and killing an organism (returns newly empty position) More...
 
using fun_get_neighbor_t = std::function< WorldPosition(WorldPosition)>
 Function type for identifying an organism's random neighbor. More...
 

Public Member Functions

 World (std::string _name="", bool gen_random=true)
 
 World (Random &rnd, std::string _name="")
 
 ~World ()
 
size_t GetSize () const
 How many organisms can fit in the world? More...
 
size_t GetNumOrgs () const
 How many organisms are currently in the world? More...
 
size_t GetUpdate () const
 What update number is the world currently on? (assumes Update() is being used) More...
 
size_t GetWidth () const
 How many cells wide is the world? (assumes grids are active.) More...
 
size_t GetHeight () const
 How many cells tall is the world? (assumes grids are active.) More...
 
const pop_tGetFullPop () const
 Get the full population to analyze externally. More...
 
const emp::TraitSet< ORG > & GetPhenotypes () const
 What phenotypic traits is the population tracking? More...
 
DataFileAddDataFile (emp::Ptr< DataFile > file)
 Add an already-constructed datafile. More...
 
DataFileGetFile (const std::string &filename)
 Lookup a file by name. More...
 
bool IsOccupied (WorldPosition pos) const
 Does the specified cell ID have an organism in it? More...
 
bool IsCacheOn () const
 Are we currently caching fitness values? More...
 
bool IsSynchronous () const
 
bool IsSpaceStructured () const
 
bool IsPhenoStructured () const
 
this_tMarkSynchronous (bool in=true)
 
this_tMarkSpaceStructured (bool in=true)
 
this_tMarkPhenoStructured (bool in=true)
 
const ORG & operator[] (size_t id) const
 
ORG & GetOrg (size_t id)
 
ORG & GetOrg (size_t x, size_t y)
 
const Ptr< ORG > GetOrgPtr (size_t id) const
 
ORG & GetNextOrg (size_t id)
 
const genome_tGetGenome (ORG &org)
 Retrieve the genome corresponding to a specified organism. More...
 
const genome_tGetGenomeAt (size_t id)
 Retrive the genome corresponding to the organism at the specified position. More...
 
Ptr< SystematicsBase< ORG > > GetSystematics (int id=0)
 
Ptr< SystematicsBase< ORG > > GetSystematics (std::string label)
 
void RemoveSystematics (int id)
 
void RemoveSystematics (std::string label)
 
template<typename ORG_INFO , typename DATA_STRUCT >
void AddSystematics (Ptr< Systematics< ORG, ORG_INFO, DATA_STRUCT > > s, std::string label="systematics")
 
fun_calc_fitness_t GetFitFun ()
 Get the fitness function currently in use. More...
 
void SetPopStruct_Grow (bool synchronous_gen=false)
 
void SetPopStruct_Mixed (bool synchronous_gen=false)
 
void SetPopStruct_Grid (size_t width, size_t height, bool synchronous_gen=false)
 
void SetAutoMutate ()
 
void SetAutoMutate (std::function< bool(size_t pos)> test_fun)
 
void SetSynchronousSystematics (bool synchronous)
 Tell systematics managers that this world has synchronous generations. More...
 
template<typename... Ts>
void AddPhenotype (Ts &&...args)
 Add a new phenotype measuring function. More...
 
Ptr< DataMonitor< double > > GetFitnessDataNode ()
 
Ptr< DataMonitor< double > > AddDataNode (const std::string &name)
 
Ptr< DataMonitor< double > > GetDataNode (const std::string &name)
 
DataFileSetupFile (const std::string &filename)
 Setup an arbitrary file; no default filename available. More...
 
DataFileSetupFitnessFile (const std::string &filename="fitness.csv", const bool &print_header=true)
 Setup a file to be printed that collects fitness information over time. More...
 
DataFileSetupSystematicsFile (std::string label, const std::string &filename="systematics.csv", const bool &print_header=true)
 Setup a file (by label) to be printed that collects systematics information over time. More...
 
DataFileSetupSystematicsFile (size_t id=0, const std::string &filename="systematics.csv", const bool &print_header=true)
 Setup a file (by id) to be printed that collects systematics information over time. More...
 
DataFileSetupPopulationFile (const std::string &filename="population.csv", const bool &print_header=true)
 Setup a file to be printed that collects population information over time. More...
 
void SetFitFun (const fun_calc_fitness_t &fit_fun)
 
void SetMutFun (const fun_do_mutations_t &mut_fun)
 
void SetPrintFun (const fun_print_org_t &print_fun)
 
void SetGetGenomeFun (const fun_get_genome_t &_fun)
 
void SetAddInjectFun (const fun_find_inject_pos_t &_fun)
 
void SetAddBirthFun (const fun_find_birth_pos_t &_fun)
 
void SetKillOrgFun (const fun_kill_org_t &_fun)
 
void SetGetNeighborFun (const fun_get_neighbor_t &_fun)
 
void SetSharedFitFun (const fun_calc_fitness_t &fit_fun, const fun_calc_dist_t &dist_fun, double sharing_threshold, double alpha)
 
SignalControlGetSignalControl ()
 Access signal controller used for this world directly. More...
 
SignalKey OnBeforeRepro (const std::function< void(size_t)> &fun)
 
SignalKey OnOffspringReady (const std::function< void(ORG &)> &fun)
 
SignalKey OnInjectReady (const std::function< void(ORG &)> &fun)
 
SignalKey OnBeforePlacement (const std::function< void(ORG &, size_t)> &fun)
 
SignalKey OnPlacement (const std::function< void(size_t)> &fun)
 
SignalKey OnUpdate (const std::function< void(size_t)> &fun)
 
SignalKey OnOrgDeath (const std::function< void(size_t)> &fun)
 
SignalKey OnSwapOrgs (const std::function< void(WorldPosition, WorldPosition)> &fun)
 
SignalKey OnWorldDestruct (const std::function< void()> &fun)
 
bool HasAttribute (const std::string &name) const
 
std::string GetAttribute (const std::string) const
 Get the value for an attribute that you know exists. More...
 
template<typename T >
void SetAttribute (const std::string &name, T &&val)
 
void Update ()
 
template<typename... ARGS>
void Process (ARGS &&...args)
 
template<typename... ARGS>
void ProcessID (size_t id, ARGS &&...args)
 
void ResetHardware ()
 Reset the hardware for all organisms. More...
 
double CalcFitnessOrg (ORG &org)
 Use the configured fitness function on the specified organism. More...
 
double CalcFitnessID (size_t id)
 Use the configured fitness function on the organism at the specified position. More...
 
void CalcFitnessAll () const
 Calculate the fitness of all organisms, storing the results in the cache. More...
 
void SetCache (bool _in=true)
 Turn on (or off) fitness caching for individual organisms. More...
 
void ClearCache ()
 Remove all currently cached fitness values (useful with changing environments, etc.) More...
 
void DoMutationsOrg (ORG &org)
 Use mutation function on a single, specified organism. More...
 
void DoMutationsID (size_t id)
 Use mutation function on the organism at the specified position in the population. More...
 
void DoMutations (size_t start_id=0)
 Use mutation function on ALL organisms in the population. More...
 
void Clear ()
 Remove all organisms from the world. More...
 
void Reset ()
 Clear all of the orgs and reset stats. More...
 
void Swap (WorldPosition pos1, WorldPosition pos2)
 Swap the positions of two organisms. More...
 
void Resize (size_t new_size)
 
void Resize (size_t new_width, size_t new_height)
 Change the size of the world based on width and height. More...
 
void Resize (const emp::vector< size_t > &dims)
 Change the size of the world based on a vector of dimensions. More...
 
void AddOrgAt (Ptr< ORG > new_org, WorldPosition pos, WorldPosition p_pos=WorldPosition())
 
void RemoveOrgAt (WorldPosition pos)
 
void Inject (const genome_t &mem, size_t copy_count=1)
 Inject an organism using the default injection scheme. More...
 
void InjectAt (const genome_t &mem, const WorldPosition pos)
 Inject an organism at a specific position. More...
 
template<typename... ARGS>
void InjectRandomOrg (ARGS &&...args)
 Inject a random organism (constructor must facilitate!) More...
 
WorldPosition DoBirth (const genome_t &mem, size_t parent_pos, size_t copy_count=1)
 Place one or more copies of an offspring into population; return position of last placed. More...
 
void DoDeath (const WorldPosition pos)
 
void DoDeath ()
 
RandomGetRandom ()
 Return a reference to the random number generator currently being used by world. More...
 
void SetRandom (Random &r)
 Setup a new random number generator created elsewhere. More...
 
void NewRandom (int seed=-1)
 Create a new random number generator (that World will manage) More...
 
size_t GetRandomCellID ()
 Get the position a cell, at random. More...
 
size_t GetRandomCellID (size_t min_id, size_t max_id)
 Get the position a cell in a range, at random. More...
 
WorldPosition GetRandomNeighborPos (WorldPosition pos)
 Use the specified function to get a neighbor (if not set, assume well mixed). More...
 
size_t GetRandomOrgID ()
 Get the id of a random occupied cell. More...
 
ORG & GetRandomOrg ()
 Get an organism from a random occupied cell. More...
 
emp::vector< size_t > FindCellIDs (const std::function< bool(ORG *)> &filter)
 Find ALL cell IDs that return true in the provided filter. More...
 
emp::vector< size_t > GetValidOrgIDs ()
 Return IDs of all occupied cells in the population. More...
 
emp::vector< size_t > GetEmptyPopIDs ()
 Return IDs of all empty cells in the population. More...
 
void DoBottleneck (const size_t new_size, bool choose_random=true)
 Run population through a bottleneck to (potentially) shrink it. More...
 
void SerialTransfer (const double keep_frac)
 Perform a Serial Transfer where a fixed percentage of current organisms are maintained. More...
 
void Print (std::ostream &os=std::cout, const std::string &empty="-", const std::string &spacer=" ")
 Print all organisms in the population using previously provided print function. More...
 
void PrintOrgCounts (std::ostream &os=std::cout)
 Print unique organisms and the number of copies of each that exist. More...
 
void PrintGrid (std::ostream &os=std::cout, const std::string &empty="-", const std::string &spacer=" ")
 Print the organisms layed out in a grid structure (assumes a grid population.) More...
 
size_t size () const
 [std::vector compatibility] How big is the world? More...
 
void resize (size_t new_size)
 [std::vector compatibility] Update world size. More...
 
void clear ()
 [std::vector compatibility] Remove all organisms. More...
 
iterator_t begin ()
 [std::vector compatibility] Return iterator to first organism. More...
 
iterator_t end ()
 [std::vector compatibility] Return iterator just past last organism. More...
 

Protected Member Functions

double GetCache (size_t id) const
 Get the current cached value for the organism at the specified position. More...
 
void ClearCache (size_t id)
 Clear the cache value at the specified position. More...
 

Protected Attributes

size_t update
 How many times has Update() been called? More...
 
Ptr< Randomrandom_ptr
 Random object to use. More...
 
bool random_owner
 Did we create our own random number generator? More...
 
WorldVector< Ptr< ORG > > pops
 The set of active [0] and "next" [1] organisms in population. More...
 
pop_tpop
 A shortcut to pops[0]. More...
 
size_t num_orgs
 How many organisms are actually in the population. More...
 
fit_cache_t fit_cache
 vector size == 0 when not caching; uncached values == 0. More...
 
std::string name
 Name of this world (for use in configuration.) More...
 
bool cache_on
 Should we be caching fitness values? More...
 
std::vector< size_t > pop_sizes
 Sizes of population dimensions (eg, 2 vals for grid) More...
 
emp::TraitSet< ORG > phenotypes
 What phenotypes are we tracking? More...
 
emp::vector< emp::Ptr< DataFile > > files
 Output files. More...
 
bool is_synchronous
 Does this world have synchronous generations? More...
 
bool is_space_structured
 Do we have a spatially structured population? More...
 
bool is_pheno_structured
 Do we have a phenotypically structured population? More...
 
DataManager< double, data::Current, data::Info, data::Range, data::Statsdata_nodes
 Potential data nodes – these should be activated only if in use. More...
 
fun_calc_fitness_t fun_calc_fitness
 ...evaluate fitness for provided organism. More...
 
fun_do_mutations_t fun_do_mutations
 ...mutate an organism. More...
 
fun_print_org_t fun_print_org
 ...print an organism. More...
 
fun_get_genome_t fun_get_genome
 ...determine the genome object of an organism. More...
 
fun_find_inject_pos_t fun_find_inject_pos
 ...find where to inject a new, external organism. More...
 
fun_find_birth_pos_t fun_find_birth_pos
 ...find where to add a new offspring organism. More...
 
fun_kill_org_t fun_kill_org
 ...kill an organism. More...
 
fun_get_neighbor_t fun_get_neighbor
 ...choose a random neighbor "near" specified id. More...
 
std::map< std::string, std::string > attributes
 Attributes are a dynamic way to track extra characteristics about a world. More...
 
emp::vector< Ptr< SystematicsBase< ORG > > > systematics
 Phylogeny and line-of-descent data collection. More...
 
std::unordered_map< std::string, int > systematics_labels
 
SignalControl control
 
Signal< void(size_t)> before_repro_sig
 ...before organism gives birth w/parent position. More...
 
Signal< void(ORG &)> offspring_ready_sig
 ...when offspring organism is built. More...
 
Signal< void(ORG &)> inject_ready_sig
 ...when outside organism is ready to inject. More...
 
Signal< void(ORG &, size_t)> before_placement_sig
 ...before placing any organism into target cell. More...
 
Signal< void(size_t)> on_placement_sig
 ...after any organism is placed into world. More...
 
Signal< void(size_t)> on_update_sig
 ...at the beginning of Update() More...
 
Signal< void(size_t)> on_death_sig
 ...immediately before any organism dies. More...
 
Signal< void(WorldPosition, WorldPosition)> on_swap_sig
 ...after org positions are swapped More...
 
Signal< void()> world_destruct_sig
 ...in the World destructor. More...
 

Friends

class World_iterator< World< ORG > >
 

Detailed Description

template<typename ORG>
class emp::World< ORG >

Setup a World with a population of organisms that can evolve or deal with ecological effects.

There are three ways that organisms can enter the population:

If the population is in EA mode (with synchronous generations), DoBirth will place offspring in a "next generation" placeholder population. Update() will move orgs into primary population.

Organisms have a series of functions that are called on them that are chosen:

FITNESS: Most selection methods require a fitness function to help determine who should be replicated. Other systems merely use fitness as a measured output. 0. If you explicitly set the fitness function using SetFitFun(), it will have priority.

  1. If the organism type has a "GetFitness()" member function, use it!
  2. If the organism type can be cast to double, use it!
  3. Start with a fitness function that throws an assert indicating function must be set.

MUTATIONS: The mutation function deteramines a main source of variation for most evolving systems. 0. If you set the mutation function using SetMutFun(), it will have priority.

  1. Or DoMutations(random) member function.
  2. Empty, with assert.

PRINTING: How should organisms be printed to the command line? 0. Setting the print function with SetPrintFun() member function.

  1. Org Print() member function that takes an ostream & argument
  2. Proper operator<<
  3. Do not print, just Assert

GENOMES: Do organisms have a genome separate from their instantiation? By default, the full organism is returned when a genome is requested, but a GetGenome() member function in the organism type will override this behavior.

  1. GetGenome member function
  2. Return org AS genome.

Member Typedef Documentation

template<typename ORG>
using emp::World< ORG >::fit_cache_t = emp::vector<double>

Type for fitness caches for pops.

template<typename ORG>
using emp::World< ORG >::fun_calc_dist_t = std::function<double(ORG&,ORG&)>

Function type for calculating the distance between two organisms.

template<typename ORG>
using emp::World< ORG >::fun_calc_fitness_t = std::function<double(ORG&)>

Function type for calculating fitness.

template<typename ORG>
using emp::World< ORG >::fun_do_mutations_t = std::function<size_t(ORG&,Random&)>

Function type for a mutation operator on an organism.

template<typename ORG>
using emp::World< ORG >::fun_find_birth_pos_t = std::function<WorldPosition(Ptr<ORG>, WorldPosition)>

Function type for adding a newly born organism into a world (returns birth position)

template<typename ORG>
using emp::World< ORG >::fun_find_inject_pos_t = std::function<WorldPosition(Ptr<ORG>)>

Function type for injecting organisms into a world (returns inject position)

template<typename ORG>
using emp::World< ORG >::fun_get_genome_t = std::function<const genome_t & (ORG &)>

Function type for retrieving a genome from an organism.

template<typename ORG>
using emp::World< ORG >::fun_get_neighbor_t = std::function<WorldPosition(WorldPosition)>

Function type for identifying an organism's random neighbor.

template<typename ORG>
using emp::World< ORG >::fun_kill_org_t = std::function<WorldPosition()>

Function type for determining picking and killing an organism (returns newly empty position)

template<typename ORG>
using emp::World< ORG >::fun_print_org_t = std::function<void(ORG&,std::ostream &)>

Function type for printing an organism's info to an output stream.

template<typename ORG>
using emp::World< ORG >::genome_t = typename emp::find_genome_t<ORG>

Type of underlying genomes.

template<typename ORG>
using emp::World< ORG >::iterator_t = World_iterator<this_t>

Type for this world's iterators.

template<typename ORG>
using emp::World< ORG >::org_t = ORG

Type of organisms in this world.

template<typename ORG>
using emp::World< ORG >::pop_t = emp::vector<Ptr<ORG>>

Type for whole populations.

template<typename ORG>
using emp::World< ORG >::this_t = World<ORG>

Resolved type of this templated class.

template<typename ORG>
using emp::World< ORG >::value_type = org_t

Identical to org_t; vector compatibility.

Constructor & Destructor Documentation

template<typename ORG>
emp::World< ORG >::World ( std::string  _name = "",
bool  gen_random = true 
)
inline

The World constructor can take two arguments, both optional:

  • a random number generator (either a pointer or reference)
  • a unique name for the world If no name is provided, the world remains nameless. If no random number generator is provided, gen_random determines if one shold be created.
template<typename ORG>
emp::World< ORG >::World ( Random rnd,
std::string  _name = "" 
)
inline
template<typename ORG>
emp::World< ORG >::~World ( )
inline

Member Function Documentation

template<typename ORG >
DataFile & emp::World< ORG >::AddDataFile ( emp::Ptr< DataFile file)

Add an already-constructed datafile.

template<typename ORG>
Ptr<DataMonitor<double> > emp::World< ORG >::AddDataNode ( const std::string &  name)
inline
template<typename ORG >
void emp::World< ORG >::AddOrgAt ( Ptr< ORG >  new_org,
WorldPosition  pos,
WorldPosition  p_pos = WorldPosition() 
)

AddOrgAt is the core function to add organisms to the population (others must go through here) Note: This function ignores population structure, so requires you to manage your own structure.

template<typename ORG>
template<typename... Ts>
void emp::World< ORG >::AddPhenotype ( Ts &&...  args)
inline

Add a new phenotype measuring function.

template<typename ORG>
template<typename ORG_INFO , typename DATA_STRUCT >
void emp::World< ORG >::AddSystematics ( Ptr< Systematics< ORG, ORG_INFO, DATA_STRUCT > >  s,
std::string  label = "systematics" 
)
inline
template<typename ORG>
iterator_t emp::World< ORG >::begin ( )
inline

[std::vector compatibility] Return iterator to first organism.

template<typename ORG>
void emp::World< ORG >::CalcFitnessAll ( ) const
inline

Calculate the fitness of all organisms, storing the results in the cache.

template<typename ORG >
double emp::World< ORG >::CalcFitnessID ( size_t  id)

Use the configured fitness function on the organism at the specified position.

template<typename ORG >
double emp::World< ORG >::CalcFitnessOrg ( ORG &  org)

Use the configured fitness function on the specified organism.

template<typename ORG >
void emp::World< ORG >::Clear ( )

Remove all organisms from the world.

template<typename ORG>
void emp::World< ORG >::clear ( )
inline

[std::vector compatibility] Remove all organisms.

template<typename ORG>
void emp::World< ORG >::ClearCache ( size_t  id)
inlineprotected

Clear the cache value at the specified position.

template<typename ORG>
void emp::World< ORG >::ClearCache ( )
inline

Remove all currently cached fitness values (useful with changing environments, etc.)

template<typename ORG >
WorldPosition emp::World< ORG >::DoBirth ( const genome_t mem,
size_t  parent_pos,
size_t  copy_count = 1 
)

Place one or more copies of an offspring into population; return position of last placed.

template<typename ORG >
void emp::World< ORG >::DoBottleneck ( const size_t  new_size,
bool  choose_random = true 
)

Run population through a bottleneck to (potentially) shrink it.

template<typename ORG>
void emp::World< ORG >::DoDeath ( const WorldPosition  pos)
inline
template<typename ORG>
void emp::World< ORG >::DoDeath ( )
inline
template<typename ORG>
void emp::World< ORG >::DoMutations ( size_t  start_id = 0)
inline

Use mutation function on ALL organisms in the population.

template<typename ORG>
void emp::World< ORG >::DoMutationsID ( size_t  id)
inline

Use mutation function on the organism at the specified position in the population.

template<typename ORG>
void emp::World< ORG >::DoMutationsOrg ( ORG &  org)
inline

Use mutation function on a single, specified organism.

template<typename ORG>
iterator_t emp::World< ORG >::end ( )
inline

[std::vector compatibility] Return iterator just past last organism.

template<typename ORG >
emp::vector< size_t > emp::World< ORG >::FindCellIDs ( const std::function< bool(ORG *)> &  filter)

Find ALL cell IDs that return true in the provided filter.

template<typename ORG>
std::string emp::World< ORG >::GetAttribute ( const std::string  ) const
inline

Get the value for an attribute that you know exists.

template<typename ORG>
double emp::World< ORG >::GetCache ( size_t  id) const
inlineprotected

Get the current cached value for the organism at the specified position.

template<typename ORG>
Ptr<DataMonitor<double> > emp::World< ORG >::GetDataNode ( const std::string &  name)
inline
template<typename ORG>
emp::vector<size_t> emp::World< ORG >::GetEmptyPopIDs ( )
inline

Return IDs of all empty cells in the population.

template<typename ORG>
DataFile& emp::World< ORG >::GetFile ( const std::string &  filename)
inline

Lookup a file by name.

template<typename ORG>
fun_calc_fitness_t emp::World< ORG >::GetFitFun ( )
inline

Get the fitness function currently in use.

template<typename ORG>
Ptr<DataMonitor<double> > emp::World< ORG >::GetFitnessDataNode ( )
inline

Access a data node that tracks fitness information in the population. The fitness will not be collected until the first Update() after this function is initially called, signaling the need for this information.

template<typename ORG>
const pop_t& emp::World< ORG >::GetFullPop ( ) const
inline

Get the full population to analyze externally.

template<typename ORG>
const genome_t& emp::World< ORG >::GetGenome ( ORG &  org)
inline

Retrieve the genome corresponding to a specified organism.

template<typename ORG>
const genome_t& emp::World< ORG >::GetGenomeAt ( size_t  id)
inline

Retrive the genome corresponding to the organism at the specified position.

template<typename ORG>
size_t emp::World< ORG >::GetHeight ( ) const
inline

How many cells tall is the world? (assumes grids are active.)

template<typename ORG>
ORG& emp::World< ORG >::GetNextOrg ( size_t  id)
inline

Retrieve a reference to the organsim as the specified position in the NEXT population. Will trip assert if cell is not occupied.

template<typename ORG>
size_t emp::World< ORG >::GetNumOrgs ( ) const
inline

How many organisms are currently in the world?

template<typename ORG>
ORG& emp::World< ORG >::GetOrg ( size_t  id)
inline

Retrieve a reference to the organsim as the specified position. Same as operator[]; will trip assert if cell is not occupied.

template<typename ORG>
ORG& emp::World< ORG >::GetOrg ( size_t  x,
size_t  y 
)
inline

Retrieve a const reference to the organsim as the specified x,y coordinates. : Technically, we should set this up with any number of coordinates.

template<typename ORG>
const Ptr<ORG> emp::World< ORG >::GetOrgPtr ( size_t  id) const
inline

Retrive a pointer to the contents of a speciefied cell; will be nullptr if the cell is not occupied.

template<typename ORG>
const emp::TraitSet<ORG>& emp::World< ORG >::GetPhenotypes ( ) const
inline

What phenotypic traits is the population tracking?

template<typename ORG>
Random& emp::World< ORG >::GetRandom ( )
inline

Return a reference to the random number generator currently being used by world.

template<typename ORG>
size_t emp::World< ORG >::GetRandomCellID ( )
inline

Get the position a cell, at random.

template<typename ORG>
size_t emp::World< ORG >::GetRandomCellID ( size_t  min_id,
size_t  max_id 
)
inline

Get the position a cell in a range, at random.

template<typename ORG>
WorldPosition emp::World< ORG >::GetRandomNeighborPos ( WorldPosition  pos)
inline

Use the specified function to get a neighbor (if not set, assume well mixed).

template<typename ORG>
ORG& emp::World< ORG >::GetRandomOrg ( )
inline

Get an organism from a random occupied cell.

template<typename ORG >
size_t emp::World< ORG >::GetRandomOrgID ( )

Get the id of a random occupied cell.

template<typename ORG>
SignalControl& emp::World< ORG >::GetSignalControl ( )
inline

Access signal controller used for this world directly.

template<typename ORG>
size_t emp::World< ORG >::GetSize ( ) const
inline

How many organisms can fit in the world?

template<typename ORG>
Ptr<SystematicsBase<ORG> > emp::World< ORG >::GetSystematics ( int  id = 0)
inline

Get a systematics manager (which is tracking lineages in the population.)

Parameters
id- which systematics manager to return? Systematics managers are stored in the order they are added to the world.
template<typename ORG>
Ptr<SystematicsBase<ORG> > emp::World< ORG >::GetSystematics ( std::string  label)
inline

Get a systematics manager (which is tracking lineages in the population.)

Parameters
id- which systematics manager to return? Systematics managers are stored in the order they are added to the world.
template<typename ORG>
size_t emp::World< ORG >::GetUpdate ( ) const
inline

What update number is the world currently on? (assumes Update() is being used)

template<typename ORG>
emp::vector<size_t> emp::World< ORG >::GetValidOrgIDs ( )
inline

Return IDs of all occupied cells in the population.

template<typename ORG>
size_t emp::World< ORG >::GetWidth ( ) const
inline

How many cells wide is the world? (assumes grids are active.)

template<typename ORG>
bool emp::World< ORG >::HasAttribute ( const std::string &  name) const
inline

Worlds can have arbitrary attributes that can be set and changed dynamically. This function determines if an attribute exists, regardless of its value.

template<typename ORG >
void emp::World< ORG >::Inject ( const genome_t mem,
size_t  copy_count = 1 
)

Inject an organism using the default injection scheme.

template<typename ORG >
void emp::World< ORG >::InjectAt ( const genome_t mem,
const WorldPosition  pos 
)

Inject an organism at a specific position.

template<typename ORG >
template<typename... ARGS>
void emp::World< ORG >::InjectRandomOrg ( ARGS &&...  args)

Inject a random organism (constructor must facilitate!)

template<typename ORG>
bool emp::World< ORG >::IsCacheOn ( ) const
inline

Are we currently caching fitness values?

template<typename ORG>
bool emp::World< ORG >::IsOccupied ( WorldPosition  pos) const
inline

Does the specified cell ID have an organism in it?

template<typename ORG>
bool emp::World< ORG >::IsPhenoStructured ( ) const
inline

Is there some sort of structure to the population based on phenotype? (i.e., are phenotypically-similar organisms forced to be closer together?)

template<typename ORG>
bool emp::World< ORG >::IsSpaceStructured ( ) const
inline

Is there some sort of spatial structure to the population? (i.e., are some organisms closer together than others.)

template<typename ORG>
bool emp::World< ORG >::IsSynchronous ( ) const
inline

Are generations being evaluated synchronously? (i.e., Update() places all births into the population after removing all current organisms.)

template<typename ORG>
this_t& emp::World< ORG >::MarkPhenoStructured ( bool  in = true)
inline

Denote that the World will have organisms structured based on phenotype. (Note: this function does not change functionality, just indicates what's happening!)

template<typename ORG>
this_t& emp::World< ORG >::MarkSpaceStructured ( bool  in = true)
inline

Denote that the World will have a spatial structure to the organisms. (Note: this function does not change functionality, just indicates what's happening!)

template<typename ORG>
this_t& emp::World< ORG >::MarkSynchronous ( bool  in = true)
inline

Denote that this World will be treated as having synchronous generations. (Note: this function does not change functionality, just indicates what's happening!)

template<typename ORG >
void emp::World< ORG >::NewRandom ( int  seed = -1)

Create a new random number generator (that World will manage)

template<typename ORG>
SignalKey emp::World< ORG >::OnBeforePlacement ( const std::function< void(ORG &, size_t)> &  fun)
inline

Provide a function for World to call before an organism is added to the active population, but after position is found. With synchonous generations, this occurs during Update(). Trigger: Organism is about to be added to population; position is known (either born or injected) Args: (1) Reference to organism about to be placed; (2) Position organism will be placed. Return: Key value needed to make future modifications.

template<typename ORG>
SignalKey emp::World< ORG >::OnBeforeRepro ( const std::function< void(size_t)> &  fun)
inline

Provide a function for World to call each time an organism is about to give birth. Trigger: Immediately prior to parent producing offspring Argument: World ID for the parent-to-be Return: Key value needed to make future modifications.

template<typename ORG>
SignalKey emp::World< ORG >::OnInjectReady ( const std::function< void(ORG &)> &  fun)
inline

Provide a function for World to call before an external organim is injected into the World. Trigger: New organism about to be added to population from outside Argument: Reference to organism about to be placed in population. Return: Key value needed to make future modifications.

template<typename ORG>
SignalKey emp::World< ORG >::OnOffspringReady ( const std::function< void(ORG &)> &  fun)
inline

Provide a function for World to call after an offspring organism has been created, but before it is inserted into the World. Trigger: Offspring about to enter population Argument: Reference to organism about to be placed in population. Return: Key value needed to make future modifications.

template<typename ORG>
SignalKey emp::World< ORG >::OnOrgDeath ( const std::function< void(size_t)> &  fun)
inline

Provide a function for World to call each time an organism is about to die. Trigger: Organism is about to be killed Argument: Position of organism about to die Return: Key value needed to make future modifications.

template<typename ORG>
SignalKey emp::World< ORG >::OnPlacement ( const std::function< void(size_t)> &  fun)
inline

Provide a function for World to call immediately after any organism has been added to the active population. With synchonous generations, this occurs during Update(). Trigger: Organism has been added to population (either born or injected) Argument: Position of organism placed in the population. Return: Key value needed to make future modifications.

template<typename ORG>
SignalKey emp::World< ORG >::OnSwapOrgs ( const std::function< void(WorldPosition, WorldPosition)> &  fun)
inline

Provide a function for World to call each time two organisms swap positions in world. Trigger: Organisms have just swapped positions. Arguments: Positions of the two organisms. Return: Key value needed to make future modifications.

template<typename ORG>
SignalKey emp::World< ORG >::OnUpdate ( const std::function< void(size_t)> &  fun)
inline

Provide a function for World to call each time Update() is run. Trigger: New update is starting Argument: Update number (sequentially increasing) Return: Key value needed to make future modifications.

template<typename ORG>
SignalKey emp::World< ORG >::OnWorldDestruct ( const std::function< void()> &  fun)
inline

Provide a function for World to call at the start of its destructor (for additional cleanup). Trigger: Destructor has begun to execture Argument: None Return: Key value needed to make future modifications.

template<typename ORG>
const ORG& emp::World< ORG >::operator[] ( size_t  id) const
inline

Index into a world to obtain a const reference to an organism. Any manipulations to organisms should go through other functions to be tracked appropriately. Will trip assert if cell is not occupied.

template<typename ORG >
void emp::World< ORG >::Print ( std::ostream &  os = std::cout,
const std::string &  empty = "-",
const std::string &  spacer = " " 
)

Print all organisms in the population using previously provided print function.

template<typename ORG >
void emp::World< ORG >::PrintGrid ( std::ostream &  os = std::cout,
const std::string &  empty = "-",
const std::string &  spacer = " " 
)

Print the organisms layed out in a grid structure (assumes a grid population.)

template<typename ORG >
void emp::World< ORG >::PrintOrgCounts ( std::ostream &  os = std::cout)

Print unique organisms and the number of copies of each that exist.

template<typename ORG>
template<typename... ARGS>
void emp::World< ORG >::Process ( ARGS &&...  args)
inline

Run the Process member function on all organisms in the population; forward any args passed into this function.

template<typename ORG>
template<typename... ARGS>
void emp::World< ORG >::ProcessID ( size_t  id,
ARGS &&...  args 
)
inline

Run the Process member function on a single, specified organism in the population; forward any args passed into this function.

template<typename ORG >
void emp::World< ORG >::RemoveOrgAt ( WorldPosition  pos)

RemoveOrgAt is the core function to remove organisms from the population. Note: This function ignores population structure, so requires you to manage your own structure.

template<typename ORG>
void emp::World< ORG >::RemoveSystematics ( int  id)
inline
template<typename ORG>
void emp::World< ORG >::RemoveSystematics ( std::string  label)
inline
template<typename ORG>
void emp::World< ORG >::Reset ( )
inline

Clear all of the orgs and reset stats.

template<typename ORG>
void emp::World< ORG >::ResetHardware ( )
inline

Reset the hardware for all organisms.

template<typename ORG>
void emp::World< ORG >::Resize ( size_t  new_size)
inline

Change the size of the world. If the new size is smaller than the old, remove any organisms outside the new range. If larger, new positions are empty.

template<typename ORG>
void emp::World< ORG >::Resize ( size_t  new_width,
size_t  new_height 
)
inline

Change the size of the world based on width and height.

template<typename ORG>
void emp::World< ORG >::Resize ( const emp::vector< size_t > &  dims)
inline

Change the size of the world based on a vector of dimensions.

template<typename ORG>
void emp::World< ORG >::resize ( size_t  new_size)
inline

[std::vector compatibility] Update world size.

template<typename ORG >
void emp::World< ORG >::SerialTransfer ( const double  keep_frac)

Perform a Serial Transfer where a fixed percentage of current organisms are maintained.

template<typename ORG>
void emp::World< ORG >::SetAddBirthFun ( const fun_find_birth_pos_t _fun)
inline

Setup the function to place a newly born organism into the population. It should take a pointer to the new organism and the position of the parent, returning a WorldPosition indicating where it was placed.

template<typename ORG>
void emp::World< ORG >::SetAddInjectFun ( const fun_find_inject_pos_t _fun)
inline

Setup the function to inject an organism into the population. It should take a pointer to the organism to be injected and return a WorldPosition indicating where it was placed.

template<typename ORG>
template<typename T >
void emp::World< ORG >::SetAttribute ( const std::string &  name,
T &&  val 
)
inline

Set the value of a new attribute on this world. If the attribute already exists, it will be updated. If it doesn't exist, it will be added.

template<typename ORG>
void emp::World< ORG >::SetAutoMutate ( )
inline

Setup the population to automatically test for and trigger mutations. By default, this occurs before deciding where an offspring should be placed. Note that this pre-placement timing may be needed if fitness or other phenotypic traits are required to determine placement.

template<typename ORG>
void emp::World< ORG >::SetAutoMutate ( std::function< bool(size_t pos)>  test_fun)
inline

Setup the population to automatically test for and trigger mutations based on a provided test function that takes the position where the offspring will be placed and indicates (true/false) whether mutations should be processed. This timing allows position to influence mutations.

template<typename ORG>
void emp::World< ORG >::SetCache ( bool  _in = true)
inline

Turn on (or off) fitness caching for individual organisms.

template<typename ORG>
void emp::World< ORG >::SetFitFun ( const fun_calc_fitness_t fit_fun)
inline

Setup the function to be used when fitness needs to be calculated. The provided function should take a reference to an organism and return a fitness value of type double.

template<typename ORG>
void emp::World< ORG >::SetGetGenomeFun ( const fun_get_genome_t _fun)
inline

Setup the function to extract or convert an organism to a genome. It should take an organism reference and return a const genome reference.

template<typename ORG>
void emp::World< ORG >::SetGetNeighborFun ( const fun_get_neighbor_t _fun)
inline

Setup the function to take an organism position id and return a random neighbor id from the population.

template<typename ORG>
void emp::World< ORG >::SetKillOrgFun ( const fun_kill_org_t _fun)
inline

Setup the function to kill an organism. It should return a WorldPosition indicating the newly empty cell, which is not necessarily where the kill occurred.

template<typename ORG>
void emp::World< ORG >::SetMutFun ( const fun_do_mutations_t mut_fun)
inline

Setup the function to be used to mutate an organism. It should take a reference to an organism and return the number of mutations that occurred.

template<typename ORG >
void emp::World< ORG >::SetPopStruct_Grid ( size_t  width,
size_t  height,
bool  synchronous_gen = false 
)

Set the population to be a grid of cells using the specified dimensions. The third argument determines if the generations should be synchronous (true) or not (false, default)

template<typename ORG >
void emp::World< ORG >::SetPopStruct_Grow ( bool  synchronous_gen = false)

Set the population to always append new organisms on the end. Argument determines if the generations should be synchronous (true) or not (false, default)

template<typename ORG >
void emp::World< ORG >::SetPopStruct_Mixed ( bool  synchronous_gen = false)

Set the population to be well-mixed (with all organisms counting as neighbors.) Argument determines if the generations should be synchronous (true) or not (false, default)

template<typename ORG>
void emp::World< ORG >::SetPrintFun ( const fun_print_org_t print_fun)
inline

Setup the function to be used to print an organism. It should take a reference to an organism and an std::ostream, with a void return. The organism should get printed to the provided ostream.

template<typename ORG >
void emp::World< ORG >::SetRandom ( Random r)

Setup a new random number generator created elsewhere.

template<typename ORG >
void emp::World< ORG >::SetSharedFitFun ( const fun_calc_fitness_t fit_fun,
const fun_calc_dist_t dist_fun,
double  sharing_threshold,
double  alpha 
)

Same as setting a fitness function, but uses Goldberg and Richardson's fitness sharing function (1987) to make similar organisms detract from each other's fitness and prevent the population from clustering around a single peak. In addition to the base fitness function, a shared fitness function also requires:

  • a distance function that takes references to two organisms and returns a double indicating the distance between those organisms,
  • a sharing threshold (sigma share) that defines the maximum distance at which members should be consdered in the same niche,
  • and a value of alpha, which controls the shape of the fitness sharing curve.
template<typename ORG>
void emp::World< ORG >::SetSynchronousSystematics ( bool  synchronous)
inline

Tell systematics managers that this world has synchronous generations.

template<typename ORG >
DataFile & emp::World< ORG >::SetupFile ( const std::string &  filename)

Setup an arbitrary file; no default filename available.

template<typename ORG >
DataFile & emp::World< ORG >::SetupFitnessFile ( const std::string &  filename = "fitness.csv",
const bool &  print_header = true 
)

Setup a file to be printed that collects fitness information over time.

template<typename ORG >
DataFile & emp::World< ORG >::SetupPopulationFile ( const std::string &  filename = "population.csv",
const bool &  print_header = true 
)

Setup a file to be printed that collects population information over time.

template<typename ORG >
DataFile & emp::World< ORG >::SetupSystematicsFile ( std::string  label,
const std::string &  filename = "systematics.csv",
const bool &  print_header = true 
)

Setup a file (by label) to be printed that collects systematics information over time.

template<typename ORG >
DataFile & emp::World< ORG >::SetupSystematicsFile ( size_t  id = 0,
const std::string &  filename = "systematics.csv",
const bool &  print_header = true 
)

Setup a file (by id) to be printed that collects systematics information over time.

template<typename ORG>
size_t emp::World< ORG >::size ( ) const
inline

[std::vector compatibility] How big is the world?

template<typename ORG>
void emp::World< ORG >::Swap ( WorldPosition  pos1,
WorldPosition  pos2 
)
inline

Swap the positions of two organisms.

template<typename ORG >
void emp::World< ORG >::Update ( )

Update the world:

  1. Send out an update signal for any external functions to trigger.
  2. If synchronous generations, move next population into place as the current popoulation.
  3. Handle any data-related updates including systematics and files that need to be printed.
  4. Increment the current update number.

Friends And Related Function Documentation

template<typename ORG>
friend class World_iterator< World< ORG > >
friend

Member Data Documentation

template<typename ORG>
std::map<std::string, std::string> emp::World< ORG >::attributes
protected

Attributes are a dynamic way to track extra characteristics about a world.

template<typename ORG>
Signal<void(ORG &,size_t)> emp::World< ORG >::before_placement_sig
protected

...before placing any organism into target cell.

template<typename ORG>
Signal<void(size_t)> emp::World< ORG >::before_repro_sig
protected

...before organism gives birth w/parent position.

template<typename ORG>
bool emp::World< ORG >::cache_on
protected

Should we be caching fitness values?

template<typename ORG>
SignalControl emp::World< ORG >::control
protected
template<typename ORG>
DataManager<double, data::Current, data::Info, data::Range, data::Stats> emp::World< ORG >::data_nodes
protected

Potential data nodes – these should be activated only if in use.

template<typename ORG>
emp::vector<emp::Ptr<DataFile> > emp::World< ORG >::files
protected

Output files.

template<typename ORG>
fit_cache_t emp::World< ORG >::fit_cache
protected

vector size == 0 when not caching; uncached values == 0.

template<typename ORG>
fun_calc_fitness_t emp::World< ORG >::fun_calc_fitness
protected

...evaluate fitness for provided organism.

template<typename ORG>
fun_do_mutations_t emp::World< ORG >::fun_do_mutations
protected

...mutate an organism.

template<typename ORG>
fun_find_birth_pos_t emp::World< ORG >::fun_find_birth_pos
protected

...find where to add a new offspring organism.

template<typename ORG>
fun_find_inject_pos_t emp::World< ORG >::fun_find_inject_pos
protected

...find where to inject a new, external organism.

template<typename ORG>
fun_get_genome_t emp::World< ORG >::fun_get_genome
protected

...determine the genome object of an organism.

template<typename ORG>
fun_get_neighbor_t emp::World< ORG >::fun_get_neighbor
protected

...choose a random neighbor "near" specified id.

template<typename ORG>
fun_kill_org_t emp::World< ORG >::fun_kill_org
protected

...kill an organism.

template<typename ORG>
fun_print_org_t emp::World< ORG >::fun_print_org
protected

...print an organism.

template<typename ORG>
Signal<void(ORG &)> emp::World< ORG >::inject_ready_sig
protected

...when outside organism is ready to inject.

template<typename ORG>
bool emp::World< ORG >::is_pheno_structured
protected

Do we have a phenotypically structured population?

template<typename ORG>
bool emp::World< ORG >::is_space_structured
protected

Do we have a spatially structured population?

template<typename ORG>
bool emp::World< ORG >::is_synchronous
protected

Does this world have synchronous generations?

template<typename ORG>
std::string emp::World< ORG >::name
protected

Name of this world (for use in configuration.)

template<typename ORG>
size_t emp::World< ORG >::num_orgs
protected

How many organisms are actually in the population.

template<typename ORG>
Signal<void(ORG &)> emp::World< ORG >::offspring_ready_sig
protected

...when offspring organism is built.

template<typename ORG>
Signal<void(size_t)> emp::World< ORG >::on_death_sig
protected

...immediately before any organism dies.

template<typename ORG>
Signal<void(size_t)> emp::World< ORG >::on_placement_sig
protected

...after any organism is placed into world.

template<typename ORG>
Signal<void(WorldPosition,WorldPosition)> emp::World< ORG >::on_swap_sig
protected

...after org positions are swapped

template<typename ORG>
Signal<void(size_t)> emp::World< ORG >::on_update_sig
protected

...at the beginning of Update()

template<typename ORG>
emp::TraitSet<ORG> emp::World< ORG >::phenotypes
protected

What phenotypes are we tracking?

template<typename ORG>
pop_t& emp::World< ORG >::pop
protected

A shortcut to pops[0].

template<typename ORG>
std::vector<size_t> emp::World< ORG >::pop_sizes
protected

Sizes of population dimensions (eg, 2 vals for grid)

template<typename ORG>
WorldVector<Ptr<ORG> > emp::World< ORG >::pops
protected

The set of active [0] and "next" [1] organisms in population.

template<typename ORG>
bool emp::World< ORG >::random_owner
protected

Did we create our own random number generator?

template<typename ORG>
Ptr<Random> emp::World< ORG >::random_ptr
protected

Random object to use.

template<typename ORG>
emp::vector<Ptr<SystematicsBase<ORG> > > emp::World< ORG >::systematics
protected

Phylogeny and line-of-descent data collection.

template<typename ORG>
std::unordered_map<std::string, int> emp::World< ORG >::systematics_labels
protected
template<typename ORG>
size_t emp::World< ORG >::update
protected

How many times has Update() been called?

template<typename ORG>
Signal<void()> emp::World< ORG >::world_destruct_sig
protected

...in the World destructor.


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