Esempio n. 1
0
        private void voBtnSequentialRosenbrock_Click(object sender, EventArgs e)
        {
            SwarmResult koResult;
            SwarmSystem koSys = new SwarmSystem(0);

            koSys.MInitialize(20, 20);
            koResult            = koSys.MDoPS0( );
            this.voLblBest.Text = koResult.ToString( );
        }
Esempio n. 2
0
        private void voBtnParallelRosenbrock_Click(object sender, EventArgs e)
        {
            int kiNumSwarms = 10;
            int kiI;

            Task <SwarmResult>[] koTask   = new Task <SwarmResult> [kiNumSwarms];
            List <SwarmResult>   koResult = new List <SwarmResult>( );
            Task koFinal;

            for (kiI = 0; kiI < koTask.Length; kiI++)
            {
                koTask[kiI] = Task.Factory.StartNew <SwarmResult>((aoContext) =>
                {
                    SwarmResult koRes;
                    SwarmSystem koSys = new SwarmSystem(( int )aoContext);
                    koSys.MInitialize(20, 20);
                    koRes = koSys.MDoPS0( );
                    return(koRes);
                }, kiI);
            }

            koFinal = Task.Factory.ContinueWhenAll(koTask, (aoTask) =>
            {
                Console.WriteLine(aoTask.Length.ToString( ) + " tasks");
                for (kiI = 0; kiI < aoTask.Length; kiI++)
                {
                    koResult.Add(aoTask[kiI].Result);
                }
            });

            koFinal.Wait( );
            koResult.Sort( );
            this.voDataGridView.DataSource = koResult;
            this.voDataGridView.Refresh( );
            this.voLblBest.Text = koResult[0].ToString( );
        }