Jido.Evolve.Evolvable protocol (Jido Evolve v1.0.0)

Copy Markdown View Source

Protocol for making any data structure evolvable.

This protocol defines how entities can be converted to and from a normalized genome representation for evolutionary operations.

Summary

Types

t()

All the types that implement this protocol.

Functions

Convert a genome back to the original entity type.

Calculate similarity between two entities (0.0 = identical, 1.0 = completely different).

Convert an entity to its genome representation.

Types

entity()

@type entity() :: term()

genome()

@type genome() :: term()

t()

@type t() :: term()

All the types that implement this protocol.

Functions

from_genome(original_entity, genome)

@spec from_genome(entity(), genome()) :: entity()

Convert a genome back to the original entity type.

The original entity is provided for context and type information.

Examples

iex> Jido.Evolve.Evolvable.from_genome("original", ['h', 'i'])
"hi"

similarity(entity1, entity2)

@spec similarity(entity(), entity()) :: float()

Calculate similarity between two entities (0.0 = identical, 1.0 = completely different).

This is used for diversity maintenance and convergence detection.

Examples

iex> Jido.Evolve.Evolvable.similarity("hello", "hello")
0.0

iex> Jido.Evolve.Evolvable.similarity("hello", "world")
1.0

to_genome(entity)

@spec to_genome(entity()) :: genome()

Convert an entity to its genome representation.

The genome should be a structure that can be easily mutated and crossed over with other genomes of the same type.

Examples

iex> Jido.Evolve.Evolvable.to_genome("hello")
['h', 'e', 'l', 'l', 'o']