Example #1
0
        public static DNA load_dna( string parent,int generation)
        {
            S_DNA dna = new S_DNA();
            DNAPlant result = new DNAPlant(parent,generation);
            result.Generation = generation;
            var query = Context.DNA.Where(S => S.PARENT_ID == parent);
            foreach (S_DNA item in query){

                gen newgen =  new gen(item.GEN,(double) item.VALOR);
                result.dnachain.Add(newgen);
            }
            return result;
        }
        private DNA[] mixDNA(DNA plant, DNA plant_2)
        {
            int generation = plant.Generation > plant_2.Generation ? plant.Generation : plant_2.Generation;
            generation += 1;
            DNA[] LDNA = new DNA[2];
            Random numer = new Random();
            int numberOfGens = plant.dnachain.Count;
            int randomnumer = numer.Next(1, numberOfGens);
            DNA DNA1= new DNAPlant();
            DNA DNA2 = new DNAPlant();
            DNA1.Generation = generation;
            DNA2.Generation = generation;
            foreach(gen g in plant.dnachain.GetRange(0,randomnumer)){
                gen g1 = new gen(g.name, mutation(g.valor));
                DNA1.dnachain.Add(g1);
            }
            foreach (gen g in plant_2.dnachain.GetRange(randomnumer, numberOfGens-randomnumer))
            {
                gen g1 = new gen(g.name, mutation(g.valor));
                DNA1.dnachain.Add(g1);
            }
            foreach (gen g in plant_2.dnachain.GetRange(0, randomnumer))
            {
                gen g1 = new gen(g.name, mutation(g.valor));
                DNA2.dnachain.Add(g1);
            }
            foreach (gen g in plant.dnachain.GetRange(randomnumer, numberOfGens - randomnumer))
            {
                gen g1 = new gen(g.name, mutation(g.valor));
                DNA2.dnachain.Add(g1);
            }

            LDNA[0] = DNA1;
            LDNA[1] = DNA2;

            return LDNA;
        }