Exemplo n.º 1
0
 public GARun(
     int ai_recpergen,
     string as_path,
     int ai_poolsize,
     int ai_generations,
     double ad_modifyprob,
     double ad_recomprob,
     Selectors aen_selector,
     Recombinators aen_recomb,
     Randoms aen_random,
     int ai_elites         = 1,
     int ai_ts_contestants = 2,
     bool ab_adaptivemut   = true,
     bool ab_rog           = false,
     bool ab_lrog          = true
     )
 {
     ii_recpergen      = ai_recpergen;
     ii_path           = as_path;
     ii_poolsize       = ai_poolsize;
     ii_generations    = ai_generations;
     id_modifyprob     = ad_modifyprob;
     id_recomprob      = ad_recomprob;
     ien_selector      = aen_selector;
     ien_recomb        = aen_recomb;
     ien_random        = aen_random;
     ii_elites         = ai_elites;
     ii_ts_contestants = ai_ts_contestants;
     ib_adaptivemut    = ab_adaptivemut;
     ib_rog            = ab_rog;
     ib_lrog           = ab_lrog;
     id   = id + 1;
     myid = id;
 }
Exemplo n.º 2
0
 public GARun(
         int ai_recpergen,
         string as_path,
         int ai_poolsize,
         int ai_generations,
         double ad_modifyprob,
         double ad_recomprob,
         Selectors aen_selector,
         Recombinators aen_recomb,
         Randoms aen_random,
         int ai_elites = 1,
         int ai_ts_contestants = 2,
         bool ab_adaptivemut = true,
         bool ab_rog = false,
         bool ab_lrog = true
     )
 {
     ii_recpergen = ai_recpergen;
     ii_path = as_path;
     ii_poolsize = ai_poolsize;
     ii_generations = ai_generations;
     id_modifyprob = ad_modifyprob;
     id_recomprob = ad_recomprob;
     ien_selector = aen_selector;
     ien_recomb = aen_recomb;
     ien_random = aen_random;
     ii_elites = ai_elites;
     ii_ts_contestants = ai_ts_contestants;
     ib_adaptivemut = ab_adaptivemut;
     ib_rog = ab_rog;
     ib_lrog = ab_lrog;
     id = id + 1;
     myid = id;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Pass the population to the Recombination operator of choice to create children for a new generation.
        /// </summary>
        /// <param name="ao_pop"></param>
        /// <param name="aen_recomtype"></param>
        public static void Recombination(Chromosome <T>[] ao_pop, Recombinators aen_recomtype)
        {
            Recombination <T> lo_recom;

            if (aen_recomtype == Recombinators.OnePointCrossoverPMX)
            {
                lo_recom = new OnePointCrossoverPMX <T>();
            }
            else
            {
                lo_recom = new TwoPointCrossoverPMX <T>();
            }
            ao_pop = lo_recom.GenerateChildren(ao_pop);
        }
Exemplo n.º 4
0
 public void init
 (
     GARun ao_run,
     ref Wrapper ao_wrapper
 )
 {
     io_wrapper        = ao_wrapper;
     io_run            = ao_run;
     ii_recpergen      = ao_run.ii_recpergen;
     ii_path           = ao_run.ii_path;
     ii_poolsize       = ao_run.ii_poolsize;
     ii_generations    = ao_run.ii_generations;
     id_modifyprob     = ao_run.id_modifyprob;
     id_recomprob      = ao_run.id_recomprob;
     ien_selector      = ao_run.ien_selector;
     ien_recomb        = ao_run.ien_recomb;
     ien_random        = ao_run.ien_random;
     ii_elites         = ao_run.ii_elites;
     ii_ts_contestants = ao_run.ii_ts_contestants;
     ib_adaptivemut    = ao_run.ib_adaptivemut;
     ib_rog            = ao_run.ib_rog;
     ib_lrog           = ao_run.ib_lrog;
     ida_starttime     = new DateTime();
 }
Exemplo n.º 5
0
 public void init(
     GARun ao_run,
     ref Wrapper ao_wrapper
 )
 {
     io_wrapper = ao_wrapper;
     io_run = ao_run;
     ii_recpergen = ao_run.ii_recpergen;
     ii_path = ao_run.ii_path;
     ii_poolsize = ao_run.ii_poolsize;
     ii_generations = ao_run.ii_generations;
     id_modifyprob = ao_run.id_modifyprob;
     id_recomprob = ao_run.id_recomprob;
     ien_selector = ao_run.ien_selector;
     ien_recomb = ao_run.ien_recomb;
     ien_random = ao_run.ien_random;
     ii_elites = ao_run.ii_elites;
     ii_ts_contestants = ao_run.ii_ts_contestants;
     ib_adaptivemut = ao_run.ib_adaptivemut;
     ib_rog = ao_run.ib_rog;
     ib_lrog = ao_run.ib_lrog;
     ida_starttime = new DateTime();
 }
Exemplo n.º 6
0
        /// <summary>
        /// Starts the Genetic Algorithm.
        /// </summary>
        /// <param name="ao_data">List of IData to be converted into Genes and stored in Chromosome.</param>
        /// <param name="ai_poolsize">Size of population.</param>
        /// <param name="ai_generations">Number of generations to iterate algorithm.</param>
        /// <param name="ad_modifyprob">Probability of modification/mutation.</param>
        /// <param name="ad_recomprob">Probability of recombination/crossover.</param>
        /// <param name="aen_selector">Selector Operator.</param>
        /// <param name="aen_recomb">Recombination Operator.</param>
        /// <param name="aen_random">Random basic vs adv</param>
        /// <param name="ai_elites">Number of Elites.</param>
        /// <param name="ai_ts_contestants">Number of Contestants for Tournament Selector.</param>
        /// <param name="ab_adaptivemut">Adaptive Mutation Enabler.</param>
        /// <param name="ab_rog">ROG Enabler.</param>
        /// <param name="ab_lrog">LROG Enabler.</param>
        public void Execute
        (
            List <T> ao_data,
            int ai_poolsize,
            int ai_generations,
            double ad_modifyprob,
            double ad_recomprob,
            Selectors aen_selector,
            Recombinators aen_recomb,
            Randoms aen_random,
            int ai_elites         = 1,
            int ai_ts_contestants = 2,
            bool ab_adaptivemut   = true,
            bool ab_rog           = false,
            bool ab_lrog          = true
        )
        {
            //Initialize global variables.
            Globals <T> .DATA = DataEncoder <T> .EncodeListFromData(ao_data);

            Globals <T> .GENERATIONS = ai_generations;
            Globals <T> .POOLSIZE    = ai_poolsize;
            Globals <T> .MODIFYPROB  = ad_modifyprob;
            Globals <T> .MODIFYBONUS = 0;
            Globals <T> .RECOMPROB   = ad_recomprob;
            Globals <T> .ELITENUM    = ai_elites;
            Globals <T> .ADAPTMUT    = ab_adaptivemut;
            Globals <T> .ROG         = ab_rog;
            Globals <T> .LROG        = ab_lrog;

            if (aen_random == Randoms.Basic)
            {
                Globals <T> .RAND = new BasicRandom();
            }
            else
            {
                Globals <T> .RAND = new AdvRandom();
            }


            //Initialize local variables.
            NotableChromosomes <T> lo_noteablechroms = new NotableChromosomes <T>();

            Chromosome <T>[] lo_pop            = new Chromosome <T> [Globals <T> .POOLSIZE];
            double           ld_fitness        = 0;
            double           ld_popbestfitness = 0;
            double           ld_inifitness     = 0;
            int li_generation = 0;

            //Start LROG thread if it's active.
            //if (Globals<T>.LROG && io_thread == null)
            //{
            //    Globals<T>.CPQ = new ConcurrentPriorityQueue<Chromosome<T>>(100);
            //    LessROG<T> lo_seeder = new LessROG<T>(ref Globals<T>.CPQ);
            //    io_thread = new Thread(new ThreadStart(lo_seeder.Run));
            //    io_thread.Start();
            //}

            if (Globals <T> .LROG && Globals <T> .SROGTHREAD == null)
            {
                Globals <T> .CPQ = new ConcurrentPriorityQueue <Chromosome <T> >(100);
                LessROG <T> lo_seeder = new LessROG <T>(ref Globals <T> .CPQ);
                Globals <T> .SROGTHREAD = new Thread(new ThreadStart(lo_seeder.Run));
                Globals <T> .SROGTHREAD.Start();
            }


            //Initialize population.
            ExecutionFunctions <T> .Initialize(ref ld_inifitness, ref ld_popbestfitness, lo_pop, lo_noteablechroms);

            Chromosome <T>[] lo_newpop = new Chromosome <T> [Globals <T> .POOLSIZE];
            //Iterate Genetic Algorithm.
            while (ContinueGA(ref li_generation))
            {
                ExecutionFunctions <T> .EvaluateElite(lo_pop);

                ExecutionFunctions <T> .Select(lo_pop, lo_newpop, aen_selector, ai_ts_contestants);

                ExecutionFunctions <T> .Recombination(lo_newpop, aen_recomb);

                ExecutionFunctions <T> .Modification(lo_newpop);

                ExecutionFunctions <T> .EvaluateFitness(ref ld_fitness, ref ld_popbestfitness, lo_newpop, lo_noteablechroms);

                lo_pop = lo_newpop;
                //Send statistics to UI.
                OnChanged(new APIEventArgs("", false, ld_fitness, ld_popbestfitness, lo_noteablechroms.GetFinalBest().fitness, lo_noteablechroms.GetFinalBest().ToString()));
            }

            //Send final statistics to UI.
            OnChanged(new APIEventArgs("Initial avg fitness: ", false, ld_inifitness, ld_popbestfitness, lo_noteablechroms.GetFinalBest().fitness, lo_noteablechroms.GetFinalBest().ToString()));
            OnChanged(new APIEventArgs("Final avg fitness: ", false, ld_fitness, ld_popbestfitness, lo_noteablechroms.GetFinalBest().fitness, lo_noteablechroms.GetFinalBest().ToString()));
            OnChanged(new APIEventArgs("Initial best fitness: ", false, ld_fitness, ld_popbestfitness, lo_noteablechroms.GetFinalBest().fitness, lo_noteablechroms.GetFinalBest().ToString()));
            OnChanged(new APIEventArgs("Overall best fitness: ", false, ld_fitness, ld_popbestfitness, lo_noteablechroms.GetFinalBest().fitness, lo_noteablechroms.GetFinalBest().ToString(), true));
        }