Beispiel #1
0
 public void AddGene(Gene gene, int indexInGenome)
 {
     gene.IndexInGenome = indexInGenome;
       Elements.Add(gene);
 }
Beispiel #2
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;
        }