World_structure.hpp

Functions for popular world structure methods.

Functions

template<typename ORG>
void SetPools(World<ORG> &world, size_t num_pools, size_t pool_size, bool synchronous_gen = false)

Set the population to be a set of pools that are individually well mixed, but with limited migration. Arguments are the number of pools, the size of each pool, and whether the generations should be synchronous (true) or not (false, default).

template<typename ORG>
void SetMapElites(World<ORG> &world, TraitSet<ORG> traits, const vector<size_t> &trait_counts)

Set the population to use a MapElites structure. This means that organism placement has two key components: 1: Organism position is based on their phenotypic traits. 2: Organisms must have a higher fitness than the current resident of a position to steal it.

Note: Since organisms compete with their predecessors for space in the populations, synchronous generations do not make sense.

This for version will setup a MAP-Elites world; traits to use an how many bins for each (trait counts) must be provided.

template<typename ORG>
void SetMapElites(World<ORG> &world, TraitSet<ORG> traits)

Setup a MAP-Elites world, given the provided set of traits. Requires world to already have a size; that size is respected when deciding trait bins.

template<typename ORG>
void SetMapElites(World<ORG> &world, const vector<size_t> &trait_counts)

Setup a MAP-Elites world, given the provided trait counts (number of bins). Requires world to already have a phenotypes that those counts are applied to.

template<typename ORG>
void SetMapElites(World<ORG> &world)

Setup a MAP-Elites world, given the provided worlds already has size AND set of phenotypes. Requires world to already have a size; that size is respected when deciding trait bins.

template<typename ORG>
void SetDiverseElites(World<ORG> &world, TraitSet<ORG> traits, size_t world_size)

This first version will setup a Diverse-Elites world and specify traits to use.

template<typename ORG>
void SetDiverseElites(World<ORG> &world, size_t world_size)

Setup a Diverse-Elites world, given the provided world already has set of phenotypes.

class WorldPosition
#include <World_structure.hpp>

A class to track positions in World. For the moment, the only informaiton beyond index is active (vs. next) population when using synchronous generations.

Public Functions

inline WorldPosition()
inline WorldPosition(size_t _id, size_t _pop_id = 0)
WorldPosition(const WorldPosition&) = default
WorldPosition &operator=(const WorldPosition&) = default
inline uint32_t GetIndex() const
inline uint32_t GetPopID() const
inline bool IsActive() const
inline bool IsValid() const
inline WorldPosition &SetActive(bool = true)
inline WorldPosition &SetPopID(size_t _id)
inline WorldPosition &SetIndex(size_t _id)
inline WorldPosition &MarkInvalid()

Public Static Attributes

static constexpr size_t invalid_id = (uint32_t)-1

Private Members

uint32_t index

Position of this organism in the population.

uint32_t pop_id

ID of the population we are in; 0 is always the active population.

template<typename T>
class WorldVector : public array<vector<T>, 2>
#include <World_structure.hpp>

A vector that can be indexed with a WorldPosition.

Public Types

using base_t = array<vector<T>, 2>

Public Functions

inline bool IsValid(WorldPosition pos) const

Test if a position is currently valid.

inline void MakeValid(WorldPosition pos)

Make sure position is valid; if not expand relevant vector.

inline T &operator()(WorldPosition pos)
inline const T &operator()(WorldPosition pos) const
template<typename ORG>
struct World_MinDistInfo
#include <World_structure.hpp>

Build a class to track distances between organisms.

DiverseElites is similar to MAP-Elites, but rather than merely keep the elites on a pre-defined grid, it merely tries to maintain maximal distance between elites in trait space. The main advantages to this technique are (1) It’s easy to build up an inital population that grows in diversity over time, and (2) You don’t need to predefine box sizes or even limits to trait values. Set the population to use a DiverseElites structure. This means that organism placement has two key components: 1: Organism position is in continuous space based on phenotypic traits. 2: When the population is full, nearby organisms must battle to keep their position.

Note: Since organisms compete with their predecessors for space in the populations, synchronous generations do not make sense.

Public Functions

inline World_MinDistInfo(World<ORG> &in_world, const TraitSet<ORG> &in_traits)
inline double CalcDist(size_t id1, size_t id2)
inline void Refresh_AgainstBin(size_t refresh_id, size_t target_bin)
inline void Refresh(size_t refresh_id, size_t start_id = 0)
inline size_t CalcBin(size_t id)

Calculate which bin an organism should be in.

inline void ResetBins()

Reset all of the bins in the multidimensional grid for nearest-neighbor analysis.

inline void Setup()
inline void Clear()
inline size_t FindKill()

Find the best organism to kill in the population. In this case, find the two closest organisms and kill the one with the lower fitness.

inline size_t GetBirthPos(size_t world_size)

Return an empty world position. If none are available, return the position of an org to be killed.

inline void Update(size_t pos)

Assume a position has changed; refresh it AND everything that had it as a closest connection.

inline bool OK()

A debug function to make sure the internal state is all valid.

Public Members

vector<size_t> nearest_id

For each individual, whom are they closest to?

vector<double> distance

And what is their distance?

World<ORG> &world

World object being tracked.

TraitSet<ORG> traits

Traits we are trying to spread.

vector<double> min_vals

Smallest value found for each trait.

vector<double> max_vals

Largest value found for each trait.

vector<double> bin_width

Largest value found for each trait.

bool is_setup

Have we initialized the internal data stucture?

size_t num_trait_bins

How many bins should we use for each trait?

size_t num_total_bins

How many bins are there overall?

vector<std::set<size_t>> bin_ids

Which org ids fall into each bin?

vector<size_t> org_bins

Which bin is each org currently in?

Public Static Attributes

static constexpr size_t ID_NONE = (size_t)-1

ID for organism does not exist.