Beispiel #1
0
        private void btn_Run_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (Points.Count < 2)
                {
                    MessageBox.Show("No Enough cities");
                    return;
                }
                this.m_chro = null;
                Refresh();
                //新加的部分
                points.Clear();
                temps.Clear();
                DrawPoints();
                GALib.Initializer newItializer = new GALib.Initializer(this.Initializer);
                GALib.Mutate      mutater      = new GALib.Mutate(this.ChromoseCompraror);
                GALib.Fitness     fitmethod    = new GALib.Fitness(this.Fitness);
                GALib.CrossOver   CrossMethod  = new GALib.CrossOver(this.CrossOver);

                GALib.GA GAAlgo = new GA(newItializer, fitmethod, mutater, CrossMethod);
                GAAlgo.Generations    = long.Parse(this.num_Gnr.Value.ToString());
                GAAlgo.PopulationSize = ushort.Parse(this.num_PopSiz.Value.ToString());
                GAAlgo.Mutation       = double.Parse(this.num_Mutation.Value.ToString());
                GAAlgo.CrossOver      = double.Parse(this.numCO.Value.ToString());

                if (Tool_MainBar.Buttons[1].Pushed)
                {
                    GAAlgo.EnableLogging = true;
                    GAAlgo.LogFilePath   = this.openFileDialog.FileName;
                }

                GAAlgo.Initialize();

                while (!GAAlgo.IsDone())
                {
                    GAAlgo.CreateNextGeneration();
                }

                m_chro = GAAlgo.GetBestChromosome();
                DrawCitiesPath();
            }
            catch (System.FormatException exp)
            {
                MessageBox.Show("Please check your Input Parameters " + exp);
            }
        }
Beispiel #2
0
        private void btn_Run_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (Points.Count < 2)
                {
                    MessageBox.Show("No Enough cities");
                    return;
                }
                this.m_chro = null;
                Refresh();
                //�¼ӵIJ���
                points.Clear();
                temps.Clear();
                DrawPoints();
                GALib.Initializer newItializer = new GALib.Initializer(this.Initializer);
                GALib.Mutate	  mutater	   = new GALib.Mutate(this. ChromoseCompraror);
                GALib.Fitness	  fitmethod	   = new GALib.Fitness(this.Fitness);
                GALib.CrossOver	  CrossMethod  = new GALib.CrossOver(this.CrossOver);

                GALib.GA GAAlgo			= new GA(newItializer,fitmethod,mutater,CrossMethod);
                GAAlgo.Generations		= long.Parse(this.num_Gnr.Value.ToString());
                GAAlgo.PopulationSize	= ushort.Parse(this.num_PopSiz.Value.ToString());
                GAAlgo.Mutation			= double.Parse(this.num_Mutation.Value.ToString());
                GAAlgo.CrossOver		= double.Parse(this.numCO.Value.ToString());

                if(Tool_MainBar.Buttons[1].Pushed)
                {
                    GAAlgo.EnableLogging = true;
                    GAAlgo.LogFilePath   = this.openFileDialog.FileName;

                }

                GAAlgo.Initialize();

                while (!GAAlgo.IsDone())
                    GAAlgo.CreateNextGeneration();

                m_chro = GAAlgo.GetBestChromosome();
                DrawCitiesPath();
            }
            catch(System.FormatException exp)
            {
                MessageBox.Show("Please check your Input Parameters "+exp);
            }
        }