species_registry (faber_neuroevolution v1.2.4)
View SourceSpecies Registry - Manages multiple species for coevolution.
The registry maintains a collection of species that coevolve in a shared environment. Each species has its own population, topology, and fitness function.
Overview
┌─────────────────────────────────────────────────┐
│ Species Registry │
├─────────────────────────────────────────────────┤
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ Forager │ │ Predator│ │Scavenger│ │
│ │ Pop:100 │ │ Pop:30 │ │ Pop:20 │ │
│ └────┬────┘ └────┬────┘ └────┬────┘ │
│ │ │ │ │
│ ┌────┴────────────┴────────────┴────┐ │
│ │ Shared Environment │ │
│ └───────────────────────────────────┘ │
└─────────────────────────────────────────────────┘Usage
%% Create registry with multiple species
{ok, Registry} = species_registry:new(#{
species => [forager_species, predator_species],
population_sizes => #{forager => 100, predator => 30},
environment => hex_arena_env
}).
%% Get all species
Species = species_registry:list_species(Registry).
%% Create bridge for a specific species
{ok, Bridge} = species_registry:create_bridge(Registry, forager).See also: agent_species.
Summary
Functions
Creates a new bridge for a species.
Gets all populations keyed by species ID.
Gets or creates a bridge for a species.
Gets species configuration.
Gets the population for a species.
Gets population size for a species.
Gets a species entry by ID.
Gets subspecies assignments for a species.
Lists all registered species IDs.
Creates a new species registry.
Registers a new species in the registry.
Sets the population (network IDs) for a species.
Returns total population across all species.
Unregisters a species from the registry.
Updates subspecies assignments for a species.
Types
-type registry() :: #{species := #{agent_species:species_id() => species_entry()}, environment := module(), population_sizes := #{agent_species:species_id() => pos_integer()}, subspecies := #{agent_species:subspecies_id() => [term()]}}.
-type species_entry() :: #{module := module(), config := agent_species:species_config(), bridge := agent_bridge:validated_bridge() | undefined, population := [term()], subspecies_map := #{non_neg_integer() => [term()]}}.
Functions
-spec create_bridge(Registry, SpeciesId) -> {ok, Bridge} | {error, Reason} when Registry :: registry(), SpeciesId :: agent_species:species_id(), Bridge :: agent_bridge:validated_bridge(), Reason :: term().
Creates a new bridge for a species.
-spec get_all_populations(Registry) -> #{agent_species:species_id() => [term()]} when Registry :: registry().
Gets all populations keyed by species ID.
-spec get_bridge(Registry, SpeciesId) -> {ok, Bridge} | {error, Reason} when Registry :: registry(), SpeciesId :: agent_species:species_id(), Bridge :: agent_bridge:validated_bridge(), Reason :: term().
Gets or creates a bridge for a species.
-spec get_config(Registry, SpeciesId) -> {ok, Config} | {error, not_found} when Registry :: registry(), SpeciesId :: agent_species:species_id(), Config :: agent_species:species_config().
Gets species configuration.
-spec get_population(Registry, SpeciesId) -> [term()] when Registry :: registry(), SpeciesId :: agent_species:species_id().
Gets the population for a species.
-spec get_population_size(Registry, SpeciesId) -> pos_integer() when Registry :: registry(), SpeciesId :: agent_species:species_id().
Gets population size for a species.
-spec get_species(Registry, SpeciesId) -> {ok, Entry} | {error, not_found} when Registry :: registry(), SpeciesId :: agent_species:species_id(), Entry :: species_entry().
Gets a species entry by ID.
-spec get_subspecies(Registry, SpeciesId) -> #{non_neg_integer() => [term()]} when Registry :: registry(), SpeciesId :: agent_species:species_id().
Gets subspecies assignments for a species.
-spec list_species(Registry) -> [agent_species:species_id()] when Registry :: registry().
Lists all registered species IDs.
-spec new(Options) -> {ok, Registry} | {error, Reason} when Options :: #{species := [module()], environment := module(), population_sizes => #{atom() => pos_integer()}}, Registry :: registry(), Reason :: term().
Creates a new species registry.
Options:
species- List of species modules (required)environment- Shared environment module (required)population_sizes- Map of species_id => size (optional)
-spec register_species(Registry, Module) -> {ok, NewRegistry} | {error, Reason} when Registry :: registry(), Module :: module(), NewRegistry :: registry(), Reason :: term().
Registers a new species in the registry.
-spec set_population(Registry, SpeciesId, Population) -> registry() when Registry :: registry(), SpeciesId :: agent_species:species_id(), Population :: [term()].
Sets the population (network IDs) for a species.
-spec total_population(Registry) -> non_neg_integer() when Registry :: registry().
Returns total population across all species.
-spec unregister_species(Registry, SpeciesId) -> {ok, NewRegistry} | {error, not_found} when Registry :: registry(), SpeciesId :: agent_species:species_id(), NewRegistry :: registry().
Unregisters a species from the registry.
-spec update_subspecies(Registry, SpeciesId, SubspeciesMap) -> registry() when Registry :: registry(), SpeciesId :: agent_species:species_id(), SubspeciesMap :: #{non_neg_integer() => [term()]}.
Updates subspecies assignments for a species.