Skip to content

Commit

Permalink
Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pkalivas committed Jan 20, 2025
1 parent 96d5d82 commit 66372ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions radiate-gp/src/collections/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/// This is a quality of life trait to help with the builder pattern or
/// with things that can be 'built'. There are a multitude of things in
/// the `radiate_gp` crate that rely on being 'built', and this trait is
/// meant to abstract that out. For example, the `Tree`, `Graph', `TreeChromosome`,
/// `GraphChromosome` can all be 'built' and thus implement this trait.
/// meant to abstract that out. For example, the `Tree` and `Graph',
/// can all be 'built' and thus implement this trait.
///
/// # Example building a `Tree<Op<f32>>`:
/// ```rust
Expand All @@ -22,6 +22,18 @@
/// assert!(tree.height() == 3);
/// assert!(tree.size() == 15);
/// ```
///
/// The above will result in a tree that looks something like:
/// ```text
/// +
/// / \
/// + *
/// / \ / \
/// 1 2 1 2
/// ```
/// **Note**: The above is not guaranteed, but is a good example of what
/// the tree will look like. It isn't guaranteed because the `TreeBuilder`
/// uses a random number generator to pick the value for each node.
pub trait Builder {
type Output;
fn build(&self) -> Self::Output;
Expand Down
2 changes: 1 addition & 1 deletion radiate-gp/src/collections/trees/codex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ where
C: Clone + PartialEq + Default + NodeCell,
{
fn encode(&self) -> Genotype<TreeChromosome<C>> {
let root = self.builder.build().root().take().unwrap().to_owned();
let root = self.builder.build().take_root().unwrap();

if let Some(constraint) = &self.constraint {
if !constraint(&root) {
Expand Down

0 comments on commit 66372ec

Please sign in to comment.