Broad categoric

This commit is contained in:
rendo 2026-04-06 11:01:15 +05:00
commit 8d46e9218a
4 changed files with 25 additions and 6 deletions

View file

@ -41,17 +41,25 @@ impl PairGenomeModificator {
(self.genome_a.clone(),self.genome_b.clone())
}
pub fn categoric_crossingover(&mut self, chance: Option<u8>) -> (Genome,Genome) {
pub fn categoric_crossingover(&mut self, chance: Option<u8>,broad: Option<bool>) -> (Genome,Genome) {
let threshold = chance.unwrap_or(2).max(2);
let mut categories_a: HashMap<String, Vec<usize>> = HashMap::new();
let mut categories_b: HashMap<String, Vec<usize>> = HashMap::new();
for (i, (gene, _)) in self.genome_a.graph.iter().enumerate() {
categories_a.entry(gene.place.to_string()).or_default().push(i);
if broad.unwrap_or(false){
categories_a.entry(gene.place.broad().to_string()).or_default().push(i);
} else {
categories_a.entry(gene.place.to_string()).or_default().push(i);
}
}
for (i, (gene, _)) in self.genome_b.graph.iter().enumerate() {
categories_b.entry(gene.place.to_string()).or_default().push(i);
if broad.unwrap_or(false){
categories_b.entry(gene.place.broad().to_string()).or_default().push(i);
} else {
categories_b.entry(gene.place.to_string()).or_default().push(i);
}
}
for (category, indices_a) in &categories_a {

View file

@ -53,9 +53,9 @@ impl ReferencePairModifier {
}
}
#[func]
fn categoric_crossingover(&mut self) {
fn categoric_crossingover(&mut self, broad: bool) {
if let Some(pair) = self.modifier.as_mut() {
let (genome_a,genome_b) = pair.categoric_crossingover(None);
let (genome_a,genome_b) = pair.categoric_crossingover(None,Some(broad));
self.godot_genome_a.as_mut().unwrap().bind_mut().set_genome(genome_a);
self.godot_genome_b.as_mut().unwrap().bind_mut().set_genome(genome_b);
}