capability_grower_configuration/
construction.rs

1// ---------------- [ File: capability-grower-configuration/src/construction.rs ]
2crate::ix!();
3
4impl GrowerTreeConfiguration {
5    /// Creates a minimal config with the given core fields.
6    pub fn base_config(depth: u8, breadth: u8, density: u8) -> Self {
7        GrowerTreeConfigurationBuilder::default()
8            .depth(depth)
9            .breadth(breadth)
10            .density(density)
11            .leaf_granularity(0.0)
12            .balance_symmetry(0.0)
13            .try_build()
14            .unwrap()
15    }
16
17    /// Convert the existing config into a builder, copying all fields.
18    pub fn to_builder(&self) -> GrowerTreeConfigurationBuilder {
19        let mut builder = GrowerTreeConfigurationBuilder::default();
20        builder = builder
21            .depth(*self.depth())
22            .breadth(*self.breadth())
23            .density(*self.density())
24            .leaf_granularity(*self.leaf_granularity())
25            .balance_symmetry(*self.balance_symmetry())
26            .complexity(*self.complexity())
27            .level_specific(self.level_specific().clone())
28            .weighted_branching(self.weighted_branching().clone())
29            .level_skipping(self.level_skipping().clone())
30            .capstone(self.capstone().clone())
31            .ordering(self.ordering().clone())
32            .ai_confidence(self.ai_confidence().clone());
33
34        builder
35    }
36
37    /// Attaches an AI-confidence sub-struct, returning a new config.
38    pub fn with_ai_conf(
39        self, 
40        base_factor: u8, 
41        factor_multiplier: f32
42    ) -> Self {
43        let ai = AiTreeBranchingConfidenceConfigurationBuilder::default()
44            .base_factor(base_factor)
45            .factor_multiplier(factor_multiplier)
46            .build()
47            .unwrap();
48
49        let mut builder = self.to_builder();
50        builder = builder.ai_confidence(Some(ai));
51        builder.try_build().unwrap()
52    }
53
54    /// Attaches WeightedBranching with the given mean/variance.
55    pub fn with_weighted_branching(
56        self, 
57        mean: u8, 
58        variance: u8
59    ) -> Self {
60        let wb = WeightedBranchingConfigurationBuilder::default()
61            .mean(mean)
62            .variance(variance)
63            .build()
64            .unwrap();
65
66        let mut builder = self.to_builder();
67        builder = builder.weighted_branching(Some(wb));
68        builder.try_build().unwrap()
69    }
70
71    /// Attaches LevelSkipping with the given skip probabilities.
72    pub fn with_level_skipping(
73        self, 
74        skip_probs: Vec<f32>
75    ) -> Self {
76        let ls = LevelSkippingConfigurationBuilder::default()
77            .leaf_probability_per_level(skip_probs)
78            .build()
79            .unwrap();
80
81        let mut builder = self.to_builder();
82        builder = builder.level_skipping(Some(ls));
83        builder.try_build().unwrap()
84    }
85
86    /// Attaches LevelSpecific with the given breadth/density arrays.
87    pub fn with_level_specific(
88        self, 
89        bpl: Vec<u8>, 
90        dpl: Vec<u8>
91    ) -> Self {
92        let lspec = TreeLevelSpecificConfigurationBuilder::default()
93            .breadth_per_level(bpl)
94            .density_per_level(dpl)
95            .build()
96            .unwrap();
97
98        let mut builder = self.to_builder();
99        builder = builder.level_specific(Some(lspec));
100        builder.try_build().unwrap()
101    }
102
103    /// Attaches a Capstone sub-struct with the given mode/prob.
104    pub fn with_capstone(
105        self, 
106        mode: CapstoneMode, 
107        prob: f32
108    ) -> Self {
109        let cap = CapstoneGenerationConfigurationBuilder::default()
110            .mode(mode)
111            .probability(prob)
112            .build()
113            .unwrap();
114
115        let mut builder = self.to_builder();
116        builder = builder.capstone(Some(cap));
117        builder.try_build().unwrap()
118    }
119}