Gemla

Struct Gemla 

Source
pub struct Gemla<T>{
    pub data: FileLinked<(Option<Box<Tree<GeneticNodeWrapper<T>>>>, GemlaConfig, T::Context)>,
    /* private fields */
}
Expand description

Manages a tournament-style bracket for simulating and evaluating nodes of type T implementing GeneticNode.

Nodes are organized as an unbalanced binary tree, and the simulation proceeds by processing nodes, merging results, and evolving populations. The simulation is asynchronous and supports concurrent node processing.

§Type Parameters

  • T: The node type, which must implement GeneticNode, serialization, Debug, Send, and Clone traits.

§Fields

  • data: Stores the simulation tree, configuration, and context.
  • threads: Tracks asynchronous tasks for node processing.

§Example

let config = GemlaConfig { overwrite: true };
let mut gemla = Gemla::<MyNodeType>::new(path, config, DataFormat::Json).await?;
gemla.simulate(5).await?;

Fields§

§data: FileLinked<(Option<Box<Tree<GeneticNodeWrapper<T>>>>, GemlaConfig, T::Context)>

The simulation data, including the tree, configuration, and context.

Implementations§

Source§

impl<T> Gemla<T>

Source

pub async fn new( path: &Path, config: GemlaConfig, data_format: DataFormat, ) -> Result<Self, Error>

Creates a new Gemla instance, initializing or loading the simulation data from the specified path.

§Arguments
  • path: The file system path to load or create the simulation data.
  • config: Configuration options for the simulation.
  • data_format: The format of the data (e.g., JSON, binary).
§Returns
  • Ok(Self): A new Gemla instance.
  • Err(Error): An error occurred during initialization or loading.
Source

pub fn tree_ref( &self, ) -> Arc<RwLock<(Option<Box<Tree<GeneticNodeWrapper<T>>>>, GemlaConfig, T::Context)>>

Returns a read-only reference to the simulation tree, configuration, and context.

Source

pub async fn simulate(&mut self, steps: u64) -> Result<(), Error>

Simulates the genetic algorithm for the specified number of steps, processing and evolving the population.

§Arguments
  • steps: The number of simulation steps to perform. A simulation step increases the height of the tree by one and continues processing until all nodes are completed.
§Returns
  • Ok(()): Simulation completed successfully.
  • Err(Error): An error occurred during simulation.

Auto Trait Implementations§

§

impl<T> Freeze for Gemla<T>
where <T as GeneticNode>::Context: Sized,

§

impl<T> !RefUnwindSafe for Gemla<T>

§

impl<T> Send for Gemla<T>
where <T as GeneticNode>::Context: Sized, T: Sync,

§

impl<T> Sync for Gemla<T>
where <T as GeneticNode>::Context: Sized, T: Sync,

§

impl<T> Unpin for Gemla<T>
where <T as GeneticNode>::Context: Sized,

§

impl<T> !UnwindSafe for Gemla<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.