Example #1
0
        private Individ crossover_uniform(Individ another_parent, double level_cross, Random Rand)
        {
            Individ child = new Individ(this);

            for (int i = 0; i < child.count_step_rotate; i++)
            {
                if (Rand.NextDouble() < level_cross)
                {
                    child.step_rotate[i] = another_parent.step_rotate[i];
                }
            }

            for (int i = 0; i < child.count_step_sko; i++)
            {
                if (Rand.NextDouble() < level_cross)
                {
                    child.step_sko[i] = another_parent.step_sko[i];
                }
            }


            child.hrom_vector.crossover_uniform(another_parent.hrom_vector, Rand, level_cross);

            return(child);
        }
Example #2
0
        public double Calc_Error(a_Fuzzy_System error_checker)
        {
            Individ temp_Best = null;
            double  min_error = double.PositiveInfinity;

            foreach (Individ indiv in the_popualate)
            {
                indiv.calc_Error(error_checker);
                if (min_error > indiv.error)
                {
                    min_error = indiv.error;
                    temp_Best = indiv;
                }
            }


            if (temp_Best != null)
            {
                if (best_individ != null)
                {
                    if (temp_Best.error < best_individ.error)
                    {
                        best_individ = temp_Best;
                    }
                }
                else
                {
                    best_individ = temp_Best;
                }
            }


            return(min_error);
        }
Example #3
0
        private Individ crossover_multipoint(Individ another_parent, int count_multipoint, Random Rand)
        {
            Individ child = new Individ(this);

            int size = child.step_sko.Count;

            size += child.hrom_vector.Core_Check.Terms_Set.Count();

            size += child.hrom_vector.Core_Check.Rules_Database.Count;

            List <int> trigger_cross = new List <int>(count_multipoint);

            do
            {
                trigger_cross.Add(Rand.Next(size));
                trigger_cross = trigger_cross.Distinct().ToList();
            } while (trigger_cross.Count < count_multipoint);
            trigger_cross.Sort();



            Boolean flag_reverse = false;



            /*
             * for (int i = 0; i < child.count_step_rotate; i++)
             * {
             *  if (flag_reverse)
             *  {
             *      child.step_rotate[i] = another_parent.step_rotate[i];
             *  }
             *
             * }
             */

            int current_pos = 0;


            for (int i = 0; i < child.count_step_sko; i++)
            {
                if ((trigger_cross.Count > 0) && (current_pos == trigger_cross[0]))
                {
                    flag_reverse = !flag_reverse;
                    trigger_cross.RemoveAt(0);
                }

                if (flag_reverse)
                {
                    child.step_sko[i] = another_parent.step_sko[i];
                }
                current_pos++;
            }


            child.hrom_vector.crossover_multipoint(another_parent.hrom_vector, Rand, current_pos, trigger_cross, flag_reverse);

            return(child);
        }
Example #4
0
        public Individ(Individ the_individ)
        {
            hrom_vector       = new Hromosom(the_individ.hrom_vector);
            step_rotate       = new List <double>(the_individ.step_rotate);
            step_sko          = new List <double>(the_individ.step_sko);
            count_step_rotate = the_individ.count_step_rotate;

            count_step_sko = the_individ.count_step_sko;
            Data           = the_individ.Data;
        }
Example #5
0
        public Individ crossover(Individ another_parent, Alg_crossover type_cross, Random rand, double param)
        {
            Individ cross_hrom = null;

            switch (type_cross)
            {
            case Alg_crossover.Унифицированный: cross_hrom = crossover_uniform(another_parent, param, rand); break;

            case Alg_crossover.Многоточечный: cross_hrom = crossover_multipoint(another_parent, (int)param, rand); break;

            default: cross_hrom = crossover_uniform(another_parent, param, rand); break;
            }



            return(cross_hrom);
        }