public CultureConfiguration(CultureConfiguration cfg) { Mode = cfg.Mode; GlobalMutationRate = cfg.GlobalMutationRate; InternalMutationRates = cfg.InternalMutationRates; FitnessFunction = cfg.FitnessFunction; SuccessFunction = cfg.SuccessFunction; EntityCount = cfg.EntityCount; TournamentSize = cfg.TournamentSize; }
public void Populate(bool fromSaved, int cultureCount, int cultureSize) { List <Entity> entities; if (fromSaved) { dataCollection.LoadEntities(out entities); } else { entities = GenerateEntities(cultureSize * cultureCount, dataCollection.InputFeatureCount, dataCollection.OutputFeatureCount); } // TODO: ******** TEMPORARY ******** cultures = new List <Culture>(); var cfg = new CultureConfiguration(CultureConfiguration.Grow); cultures.Add(new Culture(this, cfg)); cfg = new CultureConfiguration(CultureConfiguration.Balance); cultures.Add(new Culture(this, cfg)); cfg = new CultureConfiguration(CultureConfiguration.Shrink); cultures.Add(new Culture(this, cfg)); cfg = new CultureConfiguration(CultureConfiguration.Balance); cultures.Add(new Culture(this, cfg)); cfg = new CultureConfiguration(CultureConfiguration.Grow); cultures.Add(new Culture(this, cfg)); // ********************************* for (int i = 0; i < cultureCount; ++i) { for (int j = 0; j < cultureSize; ++j) { cultures[i].Entities.Add(entities[cultureSize * i + j]); } if (fromSaved) { foreach (var observer in observers) { observer.OnNext(cultures[i].Champion); } } } }
public Entity Copulate(Entity father, CultureConfiguration fatherCfg) { Entity mother = this; if (mother.ComputeFitness(fatherCfg.FitnessFunction) > father.Fitness) { var t1 = mother; mother = father; father = t1; } mother.ChildCount++; father.ChildCount++; var motherGenes = new List <Gene>(mother.Genes); var fatherGenes = new List <Gene>(father.Genes); var commonStructure = new List <Gene>(); var motherUniqueStructure = new List <Gene>(); var fatherUniqueStructure = new List <Gene>(); int m = 0, f = 0; while (m < motherGenes.Count && f < fatherGenes.Count) { var X = motherGenes[m]; var Y = fatherGenes[f]; if (X.Source == Y.Source) { if (X.Destination == Y.Destination) { commonStructure.Add((X.Source, Y.Destination, (X.Strength + Y.Strength) / 2)); m++; f++; } else if (X.Destination.CompareTo(Y.Destination) < 0) { motherUniqueStructure.Add(X); m++; } else { fatherUniqueStructure.Add(Y); f++; } } else if (X.Source.CompareTo(Y.Source) < 0) { motherUniqueStructure.Add(X); m++; } else { fatherUniqueStructure.Add(Y); f++; } } while (m < motherGenes.Count) { var gene = motherGenes[m++]; motherUniqueStructure.Add(gene); } while (f < fatherGenes.Count) { var gene = fatherGenes[f++]; fatherUniqueStructure.Add(gene); } // father is the weaker one switch (fatherCfg.Mode) { case Modes.Grow: // more like mother return(MoreLike(motherGenes, motherUniqueStructure, fatherUniqueStructure, commonStructure)); case Modes.Balance: // exclusive more like mother return(ExclusiveMoreLike(motherGenes, motherUniqueStructure, commonStructure)); case Modes.Shrink: // absolute more like mother return(AbsoluteMoreLike(motherGenes, motherUniqueStructure, commonStructure)); default: return(null); } }
public Culture(Incubator incubator, CultureConfiguration _configuration) { Cfg = _configuration; parentIncubator = incubator; Entities = new List <Entity>(); }