public void Initialize() { Genes.Clear(); Fitness = 0; int genes = _settings.GenomeLength; // create a random bit string (random genes) for (int i = 0; i < genes; ++i) { var gene = new Gene <TCombinationModel>(_settings); int initPasses = 0; // Make sure all genes are unique do { gene.Initialize(); initPasses++; } while (Genes.Any(g => g.GetActivePartsString().Equals(gene.GetActivePartsString()))); Genes.Add(gene); Debug.WriteLineIf(initPasses > 1, $"# Re-initialized because of duplicate gene ({initPasses})"); } RebuildModelFollowingGenes(); UpdateFitnessScore(); }
public void MutateGeneExpression() { IGene gene = Genes[new Random().Next(Genes.Count)]; Genes[new Random().Next(Genes.Count)].MutateExpression(); // Avoid Node Isolation if (!gene.IsExpressed && !Genes.Any(g => g.NodeIn == gene.NodeIn)) { gene.MutateExpressionEnable(); } }