pub struct Gemla<T>where
T: GeneticNode + Serialize + DeserializeOwned + Debug + Send + Clone,
T::Context: Send + Sync + Clone + Debug + Serialize + DeserializeOwned + 'static + Default,{
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 implementGeneticNode, 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>where
T: GeneticNode + Serialize + DeserializeOwned + Debug + Send + Sync + Clone + 'static,
T::Context: Send + Sync + Clone + Debug + Serialize + DeserializeOwned + 'static + Default,
impl<T> Gemla<T>where
T: GeneticNode + Serialize + DeserializeOwned + Debug + Send + Sync + Clone + 'static,
T::Context: Send + Sync + Clone + Debug + Serialize + DeserializeOwned + 'static + Default,
Sourcepub async fn new(
path: &Path,
config: GemlaConfig,
data_format: DataFormat,
) -> Result<Self, Error>
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 newGemlainstance.Err(Error): An error occurred during initialization or loading.
Sourcepub fn tree_ref(
&self,
) -> Arc<RwLock<(Option<Box<Tree<GeneticNodeWrapper<T>>>>, GemlaConfig, T::Context)>>
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.
Sourcepub async fn simulate(&mut self, steps: u64) -> Result<(), Error>
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>
impl<T> !RefUnwindSafe for Gemla<T>
impl<T> Send for Gemla<T>
impl<T> Sync for Gemla<T>
impl<T> Unpin for Gemla<T>
impl<T> !UnwindSafe for Gemla<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more