private void btnStartThreads_Click(object sender, EventArgs e)
        {
            if (PointsList.Count == 0)
            {
                MessageBox.Show("No City Matrix loaded, Choose File Load" +
                                "\n or from the TSGA(simple threaded) map, capture  points");
                return;
            }
            if (opt2.Checked == true)
            {
                numThreads = 2;
            }
            if (opt3.Checked == true)
            {
                numThreads = 3;
            }
            if (opt4.Checked == true)
            {
                numThreads = 4;
            }

            GAs  = new TSGA[numThreads];
            TGAs = new Thread[numThreads];
            for (int i = 0; i < numThreads; i++)
            {
                GAs[i] = new TSGA(TSGAConstants.PopSize, TSGAConstants.NumCities,
                                  (float)((i + 1) * 0.02), TSGAConstants.CrossoverRate, DistMat, ref lockobj);
                //   i*0.2 is the mutation rate for each thread
                TGAs[i] = new Thread(new ThreadStart(GAs[i].RunGA));
                TGAs[i].Start();
                btnStartThreads.Enabled = false;
                timer2.Enabled          = true;
            }
        }
        private void btnStartThreadsXchg_Click(object sender, EventArgs e)
        {
            if (PointsList.Count == 0)
            {
                MessageBox.Show("No City Matrix loaded, Choose File Load" +
                                "\n or from the TSGA(simple threaded) map, capture  points");
                return;
            }
            int i = 0;

            if (opt2.Checked == true)
            {
                numThreads = 2;
            }
            if (opt3.Checked == true)
            {
                numThreads = 3;
            }
            if (opt4.Checked == true)
            {
                numThreads = 4;
            }

            GAs  = new TSGA[numThreads];
            TGAs = new Thread[numThreads];

            synchObjsA = new object[numThreads];
            synchObjsB = new object[numThreads];
            dataready  = new int[numThreads];
            xchgdone   = new int[numThreads];

            for (i = 0; i < numThreads; i++)
            {
                synchObjsA[i] = new object();
                synchObjsB[i] = new object();
            }

            for (i = 0; i < numThreads; i++)
            {
                GAs[i] = new TSGA(TSGAConstants.PopSize, TSGAConstants.NumCities,
                                  (float)((i + 1) * 0.02), TSGAConstants.CrossoverRate, DistMat, ref lockobj, ref synchObjsA,
                                  ref synchObjsB, dataready, xchgdone, i);
                //   i*0.2 is the mutation rate for each thread
                TGAs[i] = new Thread(new ThreadStart(GAs[i].RunGA_XCHG));
                TGAs[i].Start();
                btnStartThreads.Enabled = false;
                timer2.Enabled          = true;
            }

            //----start the exchange in another thread so that
            //---- user interface continues to show updates
            thXchg = new Thread(new ThreadStart(this.ExchangeData));
            Thread.Sleep(100);
            thXchg.Start();
        }
 private void btnRunGA_Click(object sender, EventArgs e) //all above stay in client Windows Form app
 {
     lblStatus.Text = "Starting GA for TSP";
     //	ReadDistMat();
     ga = new TSGA(TSGAConstants.PopSize, TSGAConstants.NumCities,
                   TSGAConstants.MutationRate, TSGAConstants.CrossoverRate, DistMat, ref lockobj);
     tga            = new Thread(new ThreadStart(ga.RunGA));
     timer1.Enabled = true;
     tga.Start();
     btnRunGA.Enabled = false;
 }
예제 #4
0
 private void btnRunGA_Click(object sender, EventArgs e)
 {
     lblStatus.Text = "Starting GA for TSP";
     //	ReadDistMat();
     ga = new TSGA(TSGAConstants.PopSize, TSGAConstants.NumCities,
                   TSGAConstants.MutationRate, TSGAConstants.CrossoverRate, DistMat, ref lockobj);
     tsgaClient.SubscribeToResultChange(bestPath, "myPath");
     tga            = new Thread(new ThreadStart(ga.RunGA));
     timer1.Enabled = true;
     tga.Start();
     btnRunGA.Enabled = false;
 }