Broad categoric
This commit is contained in:
parent
66a4c4fa46
commit
8d46e9218a
4 changed files with 25 additions and 6 deletions
|
|
@ -49,9 +49,15 @@ layout_mode = 2
|
|||
size_flags_horizontal = 3
|
||||
text = "Категориальная трансформация"
|
||||
|
||||
[node name="CategoricBroad" type="Button" parent="CanvasLayer/HBoxContainer" unique_id=575186107]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Категориальная трансформация (обобщённая)"
|
||||
|
||||
[node name="ReferencePairModifier" type="ReferencePairModifier" parent="CanvasLayer" unique_id=2068562861 node_paths=PackedStringArray("godot_genome_a", "godot_genome_b")]
|
||||
godot_genome_a = NodePath("../../GenomeA")
|
||||
godot_genome_b = NodePath("../../GenomeB")
|
||||
|
||||
[connection signal="pressed" from="CanvasLayer/HBoxContainer/Allelic" to="CanvasLayer/HBoxContainer" method="_on_allelic_pressed"]
|
||||
[connection signal="pressed" from="CanvasLayer/HBoxContainer/Categoric" to="CanvasLayer/HBoxContainer" method="_on_categoric_pressed"]
|
||||
[connection signal="pressed" from="CanvasLayer/HBoxContainer/CategoricBroad" to="CanvasLayer/HBoxContainer" method="_on_categoric_broad_pressed"]
|
||||
|
|
|
|||
|
|
@ -7,5 +7,10 @@ func _on_allelic_pressed() -> void:
|
|||
|
||||
|
||||
func _on_categoric_pressed() -> void:
|
||||
reference_pair_modifier.categoric_crossingover()
|
||||
reference_pair_modifier.categoric_crossingover(false)
|
||||
|
||||
|
||||
|
||||
|
||||
func _on_categoric_broad_pressed() -> void:
|
||||
reference_pair_modifier.categoric_crossingover(true)
|
||||
|
|
|
|||
|
|
@ -41,18 +41,26 @@ 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() {
|
||||
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() {
|
||||
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 {
|
||||
let Some(indices_b) = categories_b.get(category) else { continue; };
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue