Ejemplo n.º 1
0
        public Sequence recombine(double swap_proba, Random r)
        {
            Sequence neo = new Sequence(this, false);


            for (int x = 0; x < neo.source_code.Count; x++)
            {
                Instruction first  = new Instruction();
                int         ystock = -1;

                for (int y = 0; y < neo.source_code[x].Count; y++)
                {
                    double dice = r.NextDouble();
                    if (dice < swap_proba)
                    {
                        if (ystock == -1)
                        {
                            ystock = y;
                            first  = neo.source_code[x][y];
                        }
                        else
                        {
                            neo.setInstruction(x, ystock, neo.source_code[x][y]);
                            neo.setInstruction(x, y, first);
                            ystock = -1;
                        }
                    }
                }
            }

            return(neo);
        }
Ejemplo n.º 2
0
        public static Individual RandomIndividual(Random r, Sequence sample)
        {
            Sequence neo = new Sequence(sample, false);

            int function = 0;
            int size = neo.getSizeOfFunction(function);

            while (size != -1)
            {
                for (int u = 0; u < size; u++)
                {
                    neo.setInstruction(function, u, randomInstruction(r, neo.nbFunctions));
                }
                function++;
                size = neo.getSizeOfFunction(function);
            }
            return new Individual(neo);
        }
Ejemplo n.º 3
0
        public static Individual RandomIndividual(Random r, Sequence sample)
        {
            Sequence neo = new Sequence(sample, false);

            int function = 0;
            int size     = neo.getSizeOfFunction(function);

            while (size != -1)
            {
                for (int u = 0; u < size; u++)
                {
                    neo.setInstruction(function, u, randomInstruction(r, neo.nbFunctions));
                }
                function++;
                size = neo.getSizeOfFunction(function);
            }
            return(new Individual(neo));
        }
Ejemplo n.º 4
0
        private Sequence splitAndConcat(Sequence other, Random r)//, int index)
        {
            Sequence result = new Sequence(other, false);

            //int curs = 0;

            for (int x = 0; x < source_code.Count /*&& curs < index*/; x++)
            {
                for (int y = 0; y < source_code[x].Count /*&& curs < index*/; y++)
                {
                    if (r.NextDouble() < 0.5)
                    {
                        result.setInstruction(x, y, source_code[x][y]);
                    }
                    //curs++;
                }
            }

            return(result);
        }
Ejemplo n.º 5
0
        //, int index)
        private Sequence splitAndConcat(Sequence other, Random r)
        {
            Sequence result = new Sequence(other, false);
               //int curs = 0;

               for (int x = 0; x < source_code.Count /*&& curs < index*/; x++)
               {
               for (int y = 0; y < source_code[x].Count /*&& curs < index*/; y++)
               {
                   if (r.NextDouble() < 0.5)
                   {
                       result.setInstruction(x, y, source_code[x][y]);
                   }
                   //curs++;
               }
               }

               return result;
        }
Ejemplo n.º 6
0
        public Sequence recombine(double swap_proba, Random r)
        {
            Sequence neo = new Sequence(this, false);

               for (int x = 0; x < neo.source_code.Count; x++)
               {
               Instruction first = new Instruction();
               int ystock = -1;

               for (int y = 0; y < neo.source_code[x].Count; y++)
               {
                   double dice = r.NextDouble();
                   if (dice < swap_proba)
                   {
                       if (ystock == -1)
                       {
                           ystock = y;
                           first = neo.source_code[x][y];
                       }
                       else
                       {
                           neo.setInstruction(x, ystock, neo.source_code[x][y]);
                           neo.setInstruction(x, y, first);
                           ystock = -1;
                       }
                   }

               }
               }

               return neo;
        }