Beispiel #1
0
        public void Go(object sender, EventArgs e)
        {
            this.Validate();

            GADataSet.ProblemsRow currentProblem = (this.problemsBS.Current as DataRowView).Row as GADataSet.ProblemsRow;

            int MINSIZE = 8;  //dummy value
            int MAXSIZE = 16; //dummy value
            int ITERS   = 5;

            //MIN SIZE OF CHROMOSOME TO ITERATE
            MINSIZE = currentProblem.MinSize;
            //MAX SIZE OF CHROMOSOME TO ITERATE
            MAXSIZE = currentProblem.MaxSize;
            ITERS   = currentProblem.Iters;

            int ITERCOUNTER = 1;

            do
            {
                this.gobtn.Enabled   = false;
                this.stopbtn.Enabled = true;

                Probabilities prob = setProbabilities();

                this.toolStripProgressBar1.Maximum = prob.maxPop;
                this.toolStripProgressBar1.Step    = 1;
                this.toolStripProgressBar1.Value   = 0;
                this.toolStripProgressBar1.Minimum = 0;

                //genetic algorithRow
                GADataSet.GARow currentGARow = null;
                currentGARow = this.gADataSet.GA.NewGARow();
                this.gADataSet.GA.AddGARow(currentGARow);

                currentGARow.ProblemID        = currentProblem.ProblemID;
                currentGARow.ChromosomeLength = MINSIZE;
                //create knapRow

                taControl1.UpdateGA(sender, e);

                this.SolBS.Filter = this.gADataSet.Solutions.GAIDColumn
                                    .ColumnName + "=" + currentGARow.ID;
                this.SolBS.Sort = this.gADataSet.Solutions.FitnessColumn
                                  .ColumnName + " desc";

                int[]         selection     = taControl1.GetSelection();
                Configuration Configuration = new Configuration(selection[0], selection[1], selection[2], selection[3], selection[4]);
                ///CUT HERE
                // IsampleControl= new KnapController();

                IControl.SetControllerFor(ref currentProblem, MINSIZE);
                IControl.Probabilities = prob;
                IControl.Config        = Configuration;
                IControl.GARow         = currentGARow;

                IControl.RunConfiguration();

                //refresh progress bar
                IControl.CallBack = delegate
                {
                    Application.DoEvents();
                    this.toolStripProgressBar1.PerformStep();
                };

                //UPDATE DATABASES
                IControl.SaveCallBack = delegate
                {
                    taControl1.UpdateGA(sender, e);
                    taControl1.UpdateSolutions(sender, e);
                };
                //UPDATE DATABASES
                IControl.FinalCallBack = delegate
                {
                    taControl1.UpdateStrings(sender, e);
                    dgvDoubleMouseclick(this.SolutionsDataGridView, new DataGridViewCellMouseEventArgs(0, 0, 0, 0, MOUSEVENT));
                };

                //   IsampleControl.ConfigGA();

                //no BKG worker for now...
                IControl.PostScript(false);

                //ABORT IF STOPPED
                if (!stopbtn.Enabled)
                {
                    break;
                }

                this.gobtn.Enabled   = true;
                this.stopbtn.Enabled = false;

                if (ITERCOUNTER < ITERS)
                {
                    ITERCOUNTER++;
                }
                else
                {
                    ITERCOUNTER = 1;
                    MINSIZE++; //ADD SIZE OF CHROMOSOME NEXT GENETIC ALGORITHM
                }
            }while (MINSIZE <= MAXSIZE);
        }
Beispiel #2
0
        private void dgvDoubleMouseclick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }
            DataGridView dgv = (sender as DataGridView);

            if (dgv.Rows.Count == 0)
            {
                return;
            }

            dynamic dgvr = dgv.Rows[e.RowIndex].DataBoundItem;

            if (dgvr == null)
            {
                return;
            }

            if (sender.Equals(this.problemsDataGridView))
            {
                GADataSet.ProblemsRow currentProblem = dgvr.Row as GADataSet.ProblemsRow;

                //   this.ConditionsBS.Filter = this.gADataSet.Conditions.ProblemIDColumn.ColumnName + "=" + currentProblem.ProblemID;

                //   this.DataBS.Filter = this.gADataSet.Data.ProblemIDColumn.ColumnName + "=" + currentProblem.ProblemID;

                this.gABS.SuspendBinding();

                this.SolBS.SuspendBinding();

                taControl1.FillProblemData(currentProblem.ProblemID);

                this.gABS.Filter = this.gADataSet.GA.ProblemIDColumn.ColumnName + "=" + currentProblem.ProblemID;
                this.gABS.Sort   = this.gADataSet.GA.IDColumn.ColumnName + " desc";

                this.SolBS.Filter = this.gADataSet.Solutions.ProblemIDColumn.ColumnName + "=" + currentProblem.ProblemID;

                this.SolBS.Sort = this.gADataSet.Solutions.ChromosomeLengthColumn.ColumnName + " desc";

                this.gABS.ResumeBinding();
                this.SolBS.ResumeBinding();

                pform.Find(currentProblem.ProblemID);
                pform.Show();
            }
            else if (sender.Equals(this.gADataGridView))
            {
                GADataSet.GARow currentGARow = null;
                currentGARow = dgvr.Row as GADataSet.GARow;

                this.SolBS.Filter = this.gADataSet.Solutions.GAIDColumn.ColumnName + "=" + currentGARow.ID;

                this.SolBS.Sort = this.gADataSet.Solutions.FitnessColumn.ColumnName + " desc";
            }
            else if (sender.Equals(this.SolutionsDataGridView))
            {
                GADataSet.SolutionsRow sol = dgvr.Row as GADataSet.SolutionsRow;
                if (sol.IsChromosomeNull())
                {
                    return;
                }
                System.IO.File.WriteAllBytes("current.gif", sol.Chromosome);
                picBox.ImageLocation = "current.gif";
                picBox.Refresh();
            }
        }