Exemplo n.º 1
0
        private void computeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ComputeForm cf = new ComputeForm();

            if (cf.ShowDialog() == DialogResult.OK)
            {
                this.UseWaitCursor = true;
                pm.SetSolutions(cf.NSol);
                pm.Seed          = cf.SeedVal;
                pm.ProblemType   = cf.ProblemType;
                pm.MaxIterSecond = cf.MaxIterSec;
                pm.Verbose       = cf.Verbose;

                ConsoleAppendText("\r\nStarting computation...");
                ConsoleAppendText("\r\nNumber of solution          : " + pm.Nsolution);
                ConsoleAppendText("\r\nCompute As Parallel         : " + cf.AsParSol.ToString());
                ConsoleAppendText("\r\nRefine Clusters As Parallel : " + cf.AsParClu.ToString());
                ConsoleAppendText("\r\nVerbose                     : " + pm.Verbose.ToString() + "\r\n");

                backgroundWorkerParameter param = new backgroundWorkerParameter();
                param.Parallel = cf.AsParSol;
                param.Clusters = cf.AsParClu;
                computeToolStripMenuItem.Enabled = false;
                openToolStripMenuItem.Enabled    = false;
                viewToolStripMenuItem.Enabled    = false;
                toolStripProgressBar1.Maximum    = (int)pm.Nsolution;
                toolStripProgressBar1.Value      = 0;
                SolutionViewer.Nodes.Clear();
                ClusterTextBox.Text           = "";
                SolutionViewer.Enabled        = false;
                SolutionViewer.Visible        = false;
                toolStripStatusLabel1.Enabled = false;
                backgroundWorker1.RunWorkerAsync(param);
            }
        }
Exemplo n.º 2
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            backgroundWorkerParameter param = e.Argument as backgroundWorkerParameter;

            if (pm is PMed3)
            {
                if (!pm.ComputeSolutions(param.Parallel, param.Clusters))
                {
                    MessageBox.Show("An Error as occured, check Console Text Box for info.\r\n Maybe out of memory exception.", "PMedLib.dll error");

                    //MessageBox.Show("It's Better Close program and restart it!!!", "Warning !!!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                //               else //tutto ok...
                //               {
                //               }
            }
            else
            {
                pm.ComputeSolutions(param.Parallel, param.Clusters);
            }

            //metto qui l'aggiornamenti della form e vari...

            ConsoleAppendText("\r\nFinished Computing Solutions...");

            ConsoleAppendText(String.Format("\r\n--- Best    Solution is {0} = {1}", pm.BestSolutionIndex, pm.Solutions[pm.BestSolutionIndex]));
            if (pm.WrapperSolution > 0)
            {
                ConsoleAppendText(String.Format("\r\n--- Wrapper Solution is     = {0}", pm.WrapperSolution));
            }
            pm.ShowElapsedTime();

            ConsoleAppendText(String.Format("\r\nPopulating solution viewer..."));
            Stopwatch solw = new Stopwatch();

            solw.Start();
            //aggiorno la lista delle soluzioni alla fine... così da rendere l'algortimo più efficente...

            try
            {
                for (uint i = 0; i < pm.Nsolution; i++)
                {
                    if (SolutionViewer.InvokeRequired)
                    {
                        SolutionViewer.Invoke(UpdateSolutionVieverCallBack, i);
                    }
                    else
                    {
                        UpdateSolutionViever(i);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "PMedian Project - Solution Viewer");
                //cancello la lista altrimenti può crashare tutto!!!
                //e metto solo il meglio trovato...
                if (SolutionViewer.InvokeRequired)
                {
                    SolutionViewer.Invoke(SolutionViewerClearCallBack);
                    SolutionViewer.Invoke(UpdateSolutionVieverCallBack, pm.BestSolutionIndex);
                }
                else
                {
                    SolutionViewer.Nodes.Clear();
                    UpdateSolutionViever(pm.BestSolutionIndex);
                }
            }

            solw.Stop();
            ConsoleAppendText(String.Format("\r\nTime Elapsed Pouplation Solution Viewer {0}", solw.Elapsed));
        }