예제 #1
0
 public void GenerateInitialPopulation()
 {
     for (int i = 0; i < PopulationCount; i++)
     {
         Individuals.Add(new Individual(Problem.GenomLength));
     }
 }
예제 #2
0
 public void AddIndividualChromosome(Chromosome <GeneType> chromosome)
 {
     if (Individuals == null)
     {
         Individuals = new List <Chromosome <GeneType> >();
     }
     if (chromosome == null)
     {
         Debug.WriteLine("The Chromosome is not defined");
         return;
     }
     if (Individuals.Count > NumberOfIndividuals)
     {
         Debug.WriteLine("The max number of Chromosome has been reached");
         return;
     }
     if (Environment.AllowDuplicateChildren)
     {
         Individuals.Add(chromosome);
     }
     else
     {
         if (Individuals.Where(x => x.Id == chromosome.Id).FirstOrDefault() != null)
         {
             Debug.WriteLine($"The Chromosome {chromosome.Id} already exists in the population");
             return;
         }
         else
         {
             Individuals.Add(chromosome);
         }
     }
 }
예제 #3
0
 public void FillPopulation()
 {
     for (int i = 0; i < Size; i++)
     {
         Individuals.Add(new GameEnvironment());
     }
 }
예제 #4
0
 /// <summary>
 /// Adds a new individual with the given genome.
 /// Does nothing in the case of a duplicate
 /// </summary>
 /// <param name="genome"></param>
 /// <returns>Successfully added - false id genome already present.</returns>
 public bool AddGenome(string genome)
 {
     if (Individuals.Any(i => i.Genome == genome))
     {
         return(false);
     }
     Individuals.Add(new Individual(genome));
     return(true);
 }
예제 #5
0
 public void CopyIndividuals(Population population)
 {
     Individuals.Clear();
     foreach (Individual item in population.Individuals)
     {
         Individual tmp = new Individual();
         tmp.Copy(item);
         Individuals.Add(tmp);
     }
 }
예제 #6
0
        private void ProcessRootLevel(string[] lineArray)
        {
            switch (_currentRecord)
            {
            case GedcomRecordEnum.Individual:
                Individuals.Add(_currentIndividual);
                break;

            case GedcomRecordEnum.Family:
                Families.Add(_currentFamily);
                break;

            case GedcomRecordEnum.Note:
                Notes.Add(_currentNote);
                break;
            }

            if (lineArray[1] == "HEAD")
            {
                _currentRecord    = GedcomRecordEnum.Header;
                _currentSubRecord = GedcomSubRecordEnum.None;
            }
            else if (lineArray[1].IndexOf("@") >= 0)
            {
                switch (lineArray[2])
                {
                case "INDI":
                    _currentRecord     = GedcomRecordEnum.Individual;
                    _currentIndividual = new Individual {
                        Id = lineArray[1]
                    };
                    _currentSubRecord = GedcomSubRecordEnum.None;
                    break;

                case "FAM":
                    _currentRecord = GedcomRecordEnum.Family;
                    _currentFamily = new Family {
                        Id = lineArray[1]
                    };
                    _currentSubRecord = GedcomSubRecordEnum.None;
                    break;

                case "NOTE":
                    _currentRecord = GedcomRecordEnum.Note;
                    _currentNote   = new Note {
                        Id = lineArray[1]
                    };
                    _currentSubRecord = GedcomSubRecordEnum.None;
                    break;
                }
            }
        }
예제 #7
0
        public void CreatePopulation(Individual gen)
        {
            Individual first = new Individual();

            first.Copy(gen);
            Individuals.Add(first);

            for (int i = 1; i < NumbersOfIndividuals; ++i)
            {
                Individual individual = new Individual();
                individual.CopyGenome(Individuals[i - 1]);
                JGen.Mutation.SwapTwo(individual);
                Individuals.Add(individual);
            }
        }
예제 #8
0
        public IndividualGroup(IndividualType type,
                               int count,
                               IVariables v) : base(type, count)
        {
            var geneticQualities = Utility.NextGaussianNonNegativeSymbols(10,
                                                                          v.SdQuality,
                                                                          count);

            for (var i = 0; i < count; i++)
            {
                var individual = new Individual(
                    type, i + 1,
                    geneticQualities[i],
                    Utility.NextGaussianNonNegative(geneticQualities[i], v.SdPheno)
                    );

                Individuals.Add(individual);
            }
        }
        public void AddIndividual(Individual individual)
        {
            Requires.NotNull("individual", individual);

            //Add to internal List
            Individuals.Add(individual);

            //Add underlying GEDCOM record
            individual.Id = _document.Records.GetNextId(GEDCOMTag.INDI).ToString();

            var record = new GEDCOMIndividualRecord(individual.Id);
            var name   = new GEDCOMNameStructure(String.Format("{0} /{1}/", individual.FirstName, individual.LastName), record.Level + 1);

            record.Name = name;
            record.Sex  = individual.Sex;
            _document.AddRecord(record);

            //Update Family Info
            UpdateFamilyDetails(individual);
        }
예제 #10
0
 /// <summary>
 /// Adds IIndividualEntity to the graph.
 /// </summary>
 /// <param name="individualEntity"></param>
 public void Add(IIndividualEntity individualEntity)
 {
     Individuals.Add(individualEntity);
 }
예제 #11
0
        public virtual void Populate(IEvolutionState state, int thread)
        {
            int len   = InitialSize; // original length of individual list
            int start = 0;           // where to start filling new individuals in -- may get modified if we read some individuals in

            // should we load individuals from a file? -- duplicates are permitted
            if (LoadInds)
            {
                using (var stream = state.Parameters.GetResource(FileParam, null))
                {
                    if (stream == null)
                    {
                        state.Output.Fatal("Could not load subpopulation from file", FileParam);
                    }

                    try
                    {
                        ReadSubpopulation(state, new StreamReader(stream, Encoding.Default));
                    }
                    catch (IOException e)
                    {
                        state.Output.Fatal(
                            "An IOException occurred when trying to read from the file " +
                            state.Parameters.GetString(FileParam, null) + ".  The IOException was: \n" + e,
                            FileParam, null);
                    }
                }

                if (len < Individuals.Count)
                {
                    state.Output.Message("Old subpopulation was of size " + len + ", expanding to size " + Individuals.Count);
                    return;
                }
                if (len > Individuals.Count)   // the population was shrunk, there's more space yet
                {
                    // What do we do with the remainder?
                    if (ExtraBehavior == TRUNCATE)
                    {
                        state.Output.Message("Old subpopulation was of size " + len + ", truncating to size " + Individuals.Count);
                        return;  // we're done
                    }
                    if (ExtraBehavior == WRAP)
                    {
                        state.Output.Message("Only " + Individuals.Count + " individuals were read in.  Subpopulation will stay size " + len +
                                             ", and the rest will be filled with copies of the read-in individuals.");

                        start = Individuals.Count;
                        int count = 0;
                        for (int i = start; i < len; i++)
                        {
                            Individuals.Add((Individual)Individuals[count].Clone());
                            if (++count >= start)
                            {
                                count = 0;
                            }
                        }
                        return;
                    }
                    else // if (ExtraBehavior == FILL)
                    {
                        state.Output.Message("Only " + Individuals.Count + " individuals were read in.  Subpopulation will stay size " + len +
                                             ", and the rest will be filled using randomly generated individuals.");

                        // mark the start position for filling in
                        start = Individuals.Count;
                        // now go on to fill the rest below...
                    }
                }
                else // exactly right number, we're done
                {
                    return;
                }
            }

            Hashtable h = null;

            if (NumDuplicateRetries >= 1)
            {
                h = new Hashtable((len - start) / 2); // seems reasonable
            }
            for (var x = start; x < len; x++)
            {
                Individual newInd = null;
                for (var tries = 0; tries <= NumDuplicateRetries; tries++)
                {
                    newInd = Species.NewIndividual(state, thread);

                    if (NumDuplicateRetries >= 1)
                    {
                        // check for duplicates
                        object o = h[newInd];
                        if (o == null) // found nothing, we're safe
                        // hash it and go
                        {
                            h[newInd] = newInd;
                            break;
                        }
                    }
                } // oh well, we tried to cut down the duplicates
                Individuals.Add(newInd);
            }
        }
예제 #12
0
 public Player(string name, int startGold)
 {
     Name = name;
     Gold = startGold;
     Individuals.Add(this); //will it work?
 }
예제 #13
0
 public void AddIndividual(Individual individual)
 {
     Individuals.Add(individual);
 }
예제 #14
0
 public Species AddIndividual(Individual individual)
 {
     Individuals.Add(individual);
     individual.Species = this;
     return(this);
 }
예제 #15
0
 public virtual void Add(Individual individual)
 {
     QualitySum += individual.Quality;
     Individuals.Add(individual);
 }