Пример #1
0
        public Genome Duplicate(int newId)
        {
            Genome retGenome = new Genome();
              retGenome.Id = newId;
              foreach (var element in Elements)
              {
            var elementDuplicate = element.Duplicate();
            retGenome.Elements.Add(elementDuplicate);
              }

              return retGenome;
        }
Пример #2
0
 public void Prune(Genome toRemove)
 {
     this.Genomes.Remove(toRemove);
       BuildText();
 }
Пример #3
0
        /// <summary>
        /// This loads the stream (represents the file, but not necessarily of type FileStream) into a Team
        /// object and returns that object.
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static Team LoadFromFile(Stream stream)
        {
            Team retTeam = new Team();

              var reader = new StreamReader(stream);
              stream.Position = 0;
              List<string> lines = new List<string>();
              string allText = reader.ReadToEnd();
              stream.Position = 0;
              //string[] separators = new string[] { "\\r\\n" };
              string[] allLines = Team.ParseAllText(allText);
              var currentGenome = new Genome();
              int elementIndex = 0;

              for (int i = 0; i < allLines.Length; i++)
              {
            var line = reader.ReadLine();
            var lineStart = line.Substring(0, 4);
            if (lineStart == "geno")
            {
              if (line.Substring(0, 7) == "genomes")
              {
            //we have a beginning of a genome line
            currentGenome = new Genome();
            elementIndex = 0;
            string idAsString = line.Substring(_LengthGenomeStartTag + 1, line.Length - _LengthGenomeStartTag - 1);
            currentGenome.Id = int.Parse(idAsString);
              }
              else
              {
            //we have an endgenome tag, so add the genome to the team
            retTeam.Genomes.Add(currentGenome);
            currentGenome = null;
              }
            }
            else if (lineStart == "trai")
            {
              //this line is a trait
              elementIndex++;
              var newTrait = new Trait();
              newTrait.FullLineText = line;
              currentGenome.AddTrait(newTrait, elementIndex);
            }
            else if (lineStart == "gene")
            {
              //this line is a gene element
              elementIndex++;
              var newElement = new Gene();
              newElement.FullLineText = line;
              currentGenome.AddGene(newElement, elementIndex);
            }
            else if (lineStart == "node")
            {
              //this line is a node element
              elementIndex++;
              var newElement = new Node();
              newElement.FullLineText = line;
              currentGenome.AddNode(newElement, elementIndex);
            }
            else
              throw new Exception();
              }
              return retTeam;
        }
Пример #4
0
        public Genome DuplicateGenome(Genome genome, bool createNewId = true)
        {
            var id = genome.Id;
              if (createNewId)
              {
            IEnumerable<int> idsAlreadyUsed = from g in Genomes
                                          select g.Id;

            id = idsAlreadyUsed.Max<int>() + 1;
              }

              return genome.Duplicate(id);
        }