Esempio n. 1
0
        //instrukcja do przycisku reset
        private void resetB_Click(object sender, EventArgs e)
        {
            i = 0;
            j = 0;

            avvelocity = new float[1];
            avfitness  = new float[1];
            avbfitness = new float[1];
            List <Particle> itemList = new List <Particle>();

            population = new Populacja(populationestore.dim);
            population = (Populacja)populationestore.Clone();
            foreach (Particle item in populationestore.population)
            {
                Particle tmp = new Particle(populationestore.dim);
                Particle.copy(item, tmp);
                population.population.Add(tmp);
            }

            model = new Thread(GenGraph2);
            model.IsBackground = true;
            model.Start();
            List <Populacja> tmp1 = new PSO(numberIterations, inertiaw, c1, c2, r1r2, linearinertia).PSOALG(population);

            this.functionButtonSet(false);

            animace = new Thread(ShowParticleMove);
            animace.IsBackground = true;
            animace.Start(tmp1);
        }
Esempio n. 2
0
 private void StartBtn_Click(object sender, EventArgs e)
 {
     //string f = FunctionSelectionCombo.SelectedItem.ToString();
     if (!String.IsNullOrEmpty(funkcja) && !funkcja.Equals("Proszę wybrać funkcję do optymalizacji"))
     {
         ileCzastek    = Convert.ToInt16(ParticleQuantityUpDown.Value);
         maxEpochs     = Convert.ToInt16(MaxEpochUpDown.Value);
         optymalizacja = new PSO(dziedzinyFunkcji[funkcja], ileCzastek, maxEpochs, funkcja);
         MessageBox.Show(string.Format("Znalezione minimum to {0} z błędem {1}", PSO.PSOSolution().Item1, PSO.PSOSolution().Item2), "Rezultat optymalizacji", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     else
     {
         MessageBox.Show("Nie wybrano funkcji do optymalizacji", "BŁĄD!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 3
0
        private void StartBtn_Click(object sender, EventArgs e)
        {
            //string f = FunctionSelectionCombo.SelectedItem.ToString();
            //if (!String.IsNullOrEmpty(funkcja)&&!funkcja.Equals("Proszę wybrać funkcję do optymalizacji"))
            //{
            //  ileCzastek = Convert.ToInt16(ParticleQuantityUpDown.Value);
            // maxEpochs = Convert.ToInt16(MaxEpochUpDown.Value);
            // optymalizacja = new PSO(dziedzinyFunkcji[funkcja], ileCzastek, maxEpochs, funkcja);
            //  MessageBox.Show(string.Format("Znalezione minimum to {0} z błędem {1}", PSO.PSOSolution().Item1, PSO.PSOSolution().Item2),"Rezultat optymalizacji",MessageBoxButtons.OK,MessageBoxIcon.Information);
            // }
            // else MessageBox.Show("Nie wybrano funkcji do optymalizacji","BŁĄD!",MessageBoxButtons.OK,MessageBoxIcon.Error);



            // instrukcja do przycisku start
            List <Populacja> tmp = new PSO(numberIterations, inertiaw, c1, c2, r1r2, linearinertia).PSOALG(population);

            this.functionButtonSet(false);

            animace = new Thread(ShowParticleMove);
            animace.IsBackground = true;
            animace.Start(tmp);
            if (thesame == true)
            {
                resetB.Enabled = true;
            }


            double[] tab      = new double[testnumber];
            float[]  sum      = new float[numberIterations];
            float[]  best     = new float[numberIterations];
            float[]  worst    = new float[numberIterations];
            float[]  bgfworst = new float[numberIterations];
            float[]  bgfbest  = new float[numberIterations];
            float[]  bgfav    = new float[numberIterations];

            float[] globalmin     = new float[testnumber];
            double  wynik         = 0;
            double  bestresult    = 0;
            double  worstresult   = 0;
            double  percentsucess = 0;
            double  tmpbest       = 0;
            double  tmpworst      = 0;


            for (int i = 0; i < testnumber; ++i)
            {
                population = new Populacja(PopulationSize, dim, Funkcje.FunctionName.type);
                population.SetRangeOfPopulation(Funkcje.FunctionName.type, error);
                population.GeneratePopulation(dim);
                population.ObliczPopulFitness(Funkcje.FunctionName.type);

                //List<Populacja> tmp = new PSO(numberIterations, inertiaw, c1, c2, r1r2, linearinertia).PSOALG(population);//numberIterations, inertiaw
                tmp.Remove(tmp.Last());
                tab[i]       = tmp.Min((x => x.NajlepszaFitness)); //tablica wartości wyników-z tego obliczyc % sukcesów
                wynik       += tab[i];
                globalmin[i] = (float)tmp.Min((x => x.NajlepszaFitness));


                if (Math.Abs(tab[i] - tmp.First().min) < tmp.First().exitError)
                {
                    percentsucess++;
                }

                if (i == 0)
                {
                    tmpbest  = tab[i];
                    tmpworst = tab[i];
                }
                int popnumber = 0;

                foreach (Populacja pop in tmp)
                {
                    float b = 0;
                    float c = 0;

                    bgfav[popnumber] += (float)pop.NajlepszaFitness / testnumber;

                    var scene = new ILScene();
                    scene.Screen.First <ILLabel>().Visible = false;

                    foreach (Particle item in pop.population)
                    {
                        // MessageBox.Show(a.Length.ToString()+"  " +tmp.populationSize.ToString());
                        b += (float)item.fitnessValue;
                    }
                    c = (b / pop.population.Count) / testnumber;
                    sum[popnumber] += c;
                    if (tab[i] <= tmpbest)
                    {
                        best[popnumber]    = b / pop.population.Count;
                        bgfbest[popnumber] = (float)pop.NajlepszaFitness;
                        bestresult         = pop.NajlepszaFitness;
                        tmpbest            = tab[i];
                    }

                    if (tab[i] >= tmpworst)
                    {
                        worst[popnumber]    = b / pop.population.Count;
                        bgfworst[popnumber] = (float)pop.NajlepszaFitness;
                        worstresult         = pop.NajlepszaFitness;
                        tmpworst            = tab[i];
                    }
                    popnumber++;
                }
            }

            frm.richTextBox1.AppendText("Średnie wartości funkci: " + wynik / testnumber + "\n" + "\n");
            frm.richTextBox1.AppendText("Najlepsza wartość funkcji: " + bestresult + "\n" + "\n");
            frm.richTextBox1.AppendText("Najgorsza wartość funkcji: " + worstresult + "\n" + "\n");
            frm.richTextBox1.AppendText("Procent sukcesu: " + percentsucess / testnumber * 100 + "%" + "\n" + "\n");

            var scena = new ILScene();

            using (ILScope.Enter())
            {
                ILArray <float> AV       = sum;
                ILArray <float> BEST     = best;
                ILArray <float> WORST    = worst;
                ILArray <float> BGFworst = bgfworst;
                ILArray <float> BGFbest  = bgfbest;
                ILArray <float> BGFav    = bgfav;
                ILArray <float> GLOBAL   = globalmin;
                var             plot     = scena.Add(new ILPlotCube()
                {
                    ScreenRect = new RectangleF(0, 0, 1, 0.4f),
                    Children   = { new ILLinePlot(AV.T,  lineColor:Color.Yellow),
                                   new ILLinePlot(BEST.T,  lineColor:Color.Blue),
                                   new ILLinePlot(WORST.T, lineColor:Color.Red), }
                });

                var plot1 = scena.Add(new ILPlotCube()
                {
                    ScreenRect = new RectangleF(0, 0.33f, 1, 0.4f),
                    Children   = { new ILLinePlot(BGFav.T,  lineColor:Color.Yellow),
                                   new ILLinePlot(BGFbest.T,  lineColor:Color.Blue),
                                   new ILLinePlot(BGFworst.T, lineColor:Color.Red), },
                });

                var plot2 = scena.Add(new ILPlotCube()
                {
                    ScreenRect = new RectangleF(0, 0.66f, 1, 0.3f),
                    Children   = { new ILLinePlot(GLOBAL.T, markerStyle: MarkerStyle.Diamond, lineColor: Color.Black) },
                });

                var dg2 = plot2.AddDataGroup();
                dg2.Add(new ILLinePlot(GLOBAL.T, markerStyle: MarkerStyle.Diamond, lineColor: Color.Red));//,lineColor: Color.Red));
                dg2.ScaleModes.YAxisScale = AxisScale.Logarithmic;
                var axisY2 = plot2.Axes.Add(new ILAxis(dg2)
                {
                    AxisName = AxisNames.YAxis,
                    Position = new Vector3(1, 0, 0),
                    Label    = { Text = "osiągnięte minimum (log)", Color = Color.Red },
                    Ticks    = { DefaultLabel = { Color = Color.Red } }
                });


                frm.ilgraf.Scene = scena;
                frm.Show();
            }
        }