예제 #1
0
파일: GA.cs 프로젝트: dam44/AI_SEM6120_A2
 protected virtual void OnChartUpdate(GUIGAEvent e)
 {
     if (ChartUpdate != null)
     {
         ChartUpdate(this, e);
     }
 }
예제 #2
0
파일: GA.cs 프로젝트: dam44/AI_SEM6120_A2
        //Handles event from GA.
        private void Changed(object sender, GeneticAPI.Events.APIEventArgs e)
        {
            if (ida_starttime == DateTime.MinValue)
            {
                ida_starttime = DateTime.Now;
            }
            //Record statistics.
            ii_reccount++;
            id_avgavg    += e.avgfitness;
            id_avgavgavg += e.avgfitness;
            il_msgcount++;
            ii_gencount++;
            if (e.finished)
            {
                Complete();
            }
            if (ii_reccount >= ii_recpergen)
            {
                e.avgfitness = (id_avgavg / ii_reccount);

                id_best      = e.bestfitness;
                is_bestchrom = e.bestchrom;
                ii_reccount  = 0;
                id_avgavg    = 0;
                //Send event to GUI.
                GUIGAEvent gui_e = new GUIGAEvent(e, ii_gencount);
                if (ii_gencount > ii_generations)
                {
                    gui_e.ib_pastgens = true;
                }
                OnChartUpdate(gui_e);
            }
        }
예제 #3
0
        //Recieve changed event from GA class.
        private void Changed(object sender, GUIGAEvent e)
        {
            if (!e.ib_pastgens)
            {
                UpdateLabels(e);
                for (int i = 0; i < SERIES.Count; i++)
                {
                    if (SERIES[i] == "Average Fitness")
                    {
                        UpdateGraph(SERIES[i], e.avgfitness);
                    }
                    else
                    {
                        UpdateGraph(SERIES[i], e.bestfitness);
                    }
                }
            }
            if (e.finished)
            {
                try
                {
                    //try
                    //{
                    //    io_ga.SROGThread.Abort();
                    //} catch (Exception ex)
                    //{
                    //    Debug.WriteLine("Couldn't abort SROG thread");
                    //}
                    SROGThreads.Add(io_ga.SROGThread);
                    io_gathread.Abort();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("oops");
                }
                finally
                {
                    io_gathread = null;
                    WriteToPDF("Results/" + io_runs[0].FileName());

                    UpdateListBox();
                    //io_runs = new BindingList<GARun>(io_runs);
                    Start();
                }
            }
        }
예제 #4
0
 //Updates the labels.
 private void UpdateLabels(GUIGAEvent e)
 {
     try
     {
         if (this.cha_line_ga.InvokeRequired)
         {
             UpdateLabelsCallback lo_cb = new UpdateLabelsCallback(UpdateLabels);
             this.Invoke(lo_cb, new Object[] { e });
         }
         else
         {
             lb_bestfit.Text = e.bestfitness.ToString();
             lb_gen.Text     = e.ii_generations.ToString();
             lb_pavfit.Text  = e.avgfitness.ToString();
             lb_bestc.Text   = e.bestchrom;
         }
     }
     catch (Exception ex)
     {
     }
 }
예제 #5
0
파일: GA.cs 프로젝트: dam44/AI_SEM6120_A2
        //Handles event from GA.
        private void Changed(object sender, GeneticAPI.Events.APIEventArgs e)
        {
            if (ida_starttime == DateTime.MinValue)
            {
                ida_starttime = DateTime.Now;
            }
            //Record statistics.
            ii_reccount++;
            id_avgavg += e.avgfitness;
            id_avgavgavg += e.avgfitness;
            il_msgcount++;
            ii_gencount++;
            if (e.finished)
            {
                Complete();
            }
            if (ii_reccount >= ii_recpergen)
            {
                e.avgfitness = (id_avgavg / ii_reccount);

                id_best = e.bestfitness;
                is_bestchrom = e.bestchrom;
                ii_reccount = 0;
                id_avgavg = 0;
                //Send event to GUI.
                GUIGAEvent gui_e = new GUIGAEvent(e, ii_gencount);
                if (ii_gencount > ii_generations) gui_e.ib_pastgens = true;
                 OnChartUpdate(gui_e);
            }
        }
예제 #6
0
파일: GA.cs 프로젝트: dam44/AI_SEM6120_A2
 protected virtual void OnChartUpdate(GUIGAEvent e)
 {
     if (ChartUpdate != null)
     {
         ChartUpdate(this, e);
     }
 }
예제 #7
0
        //Updates the labels.
        private void UpdateLabels(GUIGAEvent e)
        {
            try
            {
                if (this.cha_line_ga.InvokeRequired)
                {
                    UpdateLabelsCallback lo_cb = new UpdateLabelsCallback(UpdateLabels);
                    this.Invoke(lo_cb, new Object[] { e });
                }
                else
                {
                    lb_bestfit.Text = e.bestfitness.ToString();
                    lb_gen.Text = e.ii_generations.ToString();
                    lb_pavfit.Text = e.avgfitness.ToString();
                    lb_bestc.Text = e.bestchrom;
                }
            }
            catch (Exception ex)
            {

            }
        }
예제 #8
0
        //Recieve changed event from GA class.
        private void Changed(object sender, GUIGAEvent e)
        {
            if (!e.ib_pastgens)
            {
                UpdateLabels(e);
                for (int i = 0; i < SERIES.Count; i++)
                {
                    if (SERIES[i] == "Average Fitness")
                    {
                        UpdateGraph(SERIES[i], e.avgfitness);
                    }
                    else
                    {
                        UpdateGraph(SERIES[i], e.bestfitness);
                    }
                }
            }
            if (e.finished)
            {
                try
                {
                    //try
                    //{
                    //    io_ga.SROGThread.Abort();
                    //} catch (Exception ex)
                    //{
                    //    Debug.WriteLine("Couldn't abort SROG thread");
                    //}
                    SROGThreads.Add(io_ga.SROGThread);
                    io_gathread.Abort();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("oops");
                }
                finally
                {
                    io_gathread = null;
                    WriteToPDF("Results/" + io_runs[0].FileName());

                    UpdateListBox();
                    //io_runs = new BindingList<GARun>(io_runs);
                    Start();
                }

            }
        }