Mutate() creating invalid Genotypes 

I'm getting a lot of rejections after running the Genotype.mutate() function lately. Here's a minimal example that you can run in the console:

Genotype.genotype = "(, LLLCFFMMMMQQ(, cX[|1:2.533, 0:0.901,0:1], LCMqX[@T:4.852][@0:-676.863, 1:-4.384][@/:-1.981, 0:-54.120, 1:0.569]LX[@1:0.643][|=:3.615, 0:2.818]";
Simulator.print(Genotype.isValid);
Genotype.mutate();
Simulator.print(Genotype.isValid);

The results are:
Script::Message - 1
Script::Message - 0

So the genotype was valid before, but after the mutation was invalid. This causes problems because I keep finding entire gene pools full of genotypes that can no longer be modified with mutation (which makes evolution difficult).

Any thoughts on this? It may be that the genotype had some errors in it before, and the mutation aggravated them to the point in invalidation. If that's the case, is there any kind of function that could clean those errors up before mutation? Running mutate() multiple times doesn't help.

Forums: 
Maciej Komosinski's picture

Indeed, checking for strict validity is not called often enough. The genotype you cited is obviously invalid (two trailing )) are missing). Genotype validity is tested thoroughly when a new Genotype is added to the gene pool, otherwise it is only approximately tested. This will be improved in version 3.1.

Genotype.genotype = "(, LLLCFFMMMMQQ(, cX[|1:2.533, 0:0.901,0:1], LCMqX[@T:4.852][@0:-676.863, 1:-4.384][@/:-1.981, 0:-54.120, 1:0.569]LX[@1:0.643][|=:3.615, 0:2.818]";
Simulator.print(Genotype.isValid); //displays "1", but the genotype has been checked only approximately.

The Simulator.creatwarnfail is related. It might not help in your case, but it is anyway good to be aware of it. Setting this to "1" will prohibit the simulator from simulating genotypes with minor (i.e., growth-time) errors, like multiple muscles of the same type in the same place in body. Therefore such genotypes will not have a chance to enter the gene pool.

Aha! that explains it all...
In that case I will not bother with isValid and can just use the return from createFromGenotype() to check for major errors:

GenePools.newGenotype(newgenostring);
GenePools.copySelected(currGroup);
if (!Populations.createFromGenotype())
{
   //creature had major error
   GenePools.deleteSelected(); //delete faulty genotype too
}

Thanks again!