def cross_gene_sequences(gene_a, gene_b): atomised_a = gene_a.strip().split() atomised_b = gene_b.strip().split() new_action = random.choice([atomised_a.pop(0), atomised_b.pop(0)]) func_a = parse_func(atomised_a) func_b = parse_func(atomised_b) node_a = random.choice(func_a.as_list()) node_b = random.choice(func_b.as_list()) if node_a.parent is None: return new_action + " " + str(func_b) elif node_a.parent.left == node_a: node_a.parent.left = node_b else: node_a.parent.right = node_b root = node_a.parent while root.parent is not None: root = root.parent return new_action + " " + str(root)
def __init__(self, meta, sequence): # Set up first the metagenome meta_genes = [float(g) for g in meta.strip().split()] self.colors = [ meta_genes[i:i + 3] + [1.0] for i in range(*Genome.META_INDICES["colors"], 3) ] self.fuzziness = Genome.meta_item(meta_genes, "fuzziness") self.const_bounds = Genome.meta_item(meta_genes, "const_bounds") self.fun_gen_depth = Genome.meta_item(meta_genes, "fun_gen_depth") self.incr_range = Genome.meta_item(meta_genes, "incr_range") self.mult_range = Genome.meta_item(meta_genes, "mult_range") self.mute_rates = {} self.mute_rates["mute"] = Genome.meta_item(meta_genes, "mute") self.mute_rates["genome"] = Genome.meta_item(meta_genes, "genome") self.mute_rates["gene_action"] = Genome.meta_item( meta_genes, "gene_action") self.mute_rates["struct_mod"] = Genome.meta_item( meta_genes, "struct_mod") self.mute_rates["leaf_type"] = Genome.meta_item( meta_genes, "leaf_type") self.mute_rates["genome_rel"] = dict( zip(list(GenomeMutes), Genome.meta_item(meta_genes, "genome_rel"))) self.mute_rates["const_rel"] = dict( zip(list(ConstMutes), Genome.meta_item(meta_genes, "const_rel"))) self.mute_rates["leaf_rel"] = dict( zip(list(RefType), Genome.meta_item(meta_genes, "leaf_rel"))) self.mute_rates["enum_rel"] = dict( zip(list(EnumMutes), Genome.meta_item(meta_genes, "enum_rel"))) self.mute_rates["struct_rel"] = dict( zip(list(StructMutes), Genome.meta_item(meta_genes, "struct_rel"))) # Now handle the behavioural genes gene_sequences = [s.strip().split() for s in sequence.split("|")] self.genes = [Gene(None, None) for _ in range(len(gene_sequences))] for i in range(len(self.genes)): action = goomba.Action(int(gene_sequences[i].pop(0))) func = parse_func(gene_sequences[i]) self.fuzzify(func) self.genes[i].action = action self.genes[i].function = func self.link()
def __init__(self, meta, sequence): # Set up first the metagenome meta_genes = [float(g) for g in meta.strip().split()] self.colors = [meta_genes[i:i+3] + [1.0] for i in range(*Genome.META_INDICES["colors"], 3)] self.fuzziness = Genome.meta_item(meta_genes, "fuzziness") self.const_bounds = Genome.meta_item(meta_genes, "const_bounds") self.fun_gen_depth = Genome.meta_item(meta_genes, "fun_gen_depth") self.incr_range = Genome.meta_item(meta_genes, "incr_range") self.mult_range = Genome.meta_item(meta_genes, "mult_range") self.mute_rates = {} self.mute_rates["mute"] = Genome.meta_item(meta_genes, "mute") self.mute_rates["genome"] = Genome.meta_item(meta_genes, "genome") self.mute_rates["gene_action"] = Genome.meta_item(meta_genes, "gene_action") self.mute_rates["struct_mod"] = Genome.meta_item(meta_genes, "struct_mod") self.mute_rates["leaf_type"] = Genome.meta_item(meta_genes, "leaf_type") self.mute_rates["genome_rel"] = dict(zip(list(GenomeMutes), Genome.meta_item(meta_genes, "genome_rel"))) self.mute_rates["const_rel"] = dict(zip(list(ConstMutes), Genome.meta_item(meta_genes, "const_rel"))) self.mute_rates["leaf_rel"] = dict(zip(list(RefType), Genome.meta_item(meta_genes, "leaf_rel"))) self.mute_rates["enum_rel"] = dict(zip(list(EnumMutes), Genome.meta_item(meta_genes, "enum_rel"))) self.mute_rates["struct_rel"] = dict(zip(list(StructMutes), Genome.meta_item(meta_genes, "struct_rel"))) # Now handle the behavioural genes gene_sequences = [s.strip().split() for s in sequence.split("|")] self.genes = [Gene(None, None) for _ in range(len(gene_sequences))] for i in range(len(self.genes)): action = goomba.Action(int(gene_sequences[i].pop(0))) func = parse_func(gene_sequences[i]) self.fuzzify(func) self.genes[i].action = action self.genes[i].function = func self.link()