Exemplo n.º 1
0
        internal EntitySet(S settings, GenePool <S, G, R> genePool, int cohortId,
                           IEnumerable <Entity <S, G, R> > entities)
        {
            Cohort = new Cohort(cohortId);

            if (entities == null)
            {
                for (int entityId = 0; entityId <= settings.Population - 1; entityId++)
                {
                    var codeTree = new CodeTree <S, G, R>(
                        genePool, genePool.GetFunction(), settings.MaxTreeDepth);

                    var knownAs = new KnownAs(Cohort, entityId);

                    Items.Add(new Entity <S, G, R>(knownAs, codeTree));
                }
            }
            else
            {
                Items.AddRange(entities.Take(settings.NumToKeep));

                for (int entityId = Count; entityId <= settings.Population - 2; entityId += 2)
                {
                    CodeTree <S, G, R> child1, child2, parent1, parent2;
                    int index1, index2;

                    SelectAndCloneParents(genePool, this, settings.NumToKeep,
                                          out index1, out parent1, out index2, out parent2);

                    Crossover(genePool, parent1, parent2, out child1, out child2);

                    Items.Add(new Entity <S, G, R>(new KnownAs(Cohort, entityId),
                                                   this[index1].KnownAs, this[index2].KnownAs, child1));

                    Items.Add(new Entity <S, G, R>(new KnownAs(Cohort, entityId + 1),
                                                   this[index1].KnownAs, this[index2].KnownAs, child2));
                }
            }
        }
Exemplo n.º 2
0
 public EmitException(Cohort cohort, IEnumerable <Diagnostic> failures)
     : base($"The source for {cohort} is invalid!")
 {
     Failures = failures.ToList();
 }
Exemplo n.º 3
0
 public KnownAs(Cohort cohort, int entityId)
     : base(cohort.CohortId)
 {
     EntityId = entityId;
 }