Hello!
Im having a problem with PSO, i have checked a lot of example codes, i think im doing everything ok, but dont have good results.
Here is code (im from Poland, so names is in Polish and ill explain that a little bit)
listaListPopulacji - in that list i have every imformations about points, like bestPosition, velocity etc (type of it is Jednostka) its looks like that:
http://www.fotoszok.pl/upload/48d323f8.png[
^]
do
{
chart1.Series[0].Points.Clear();
foreach (Jednostka item in listaListPopulacji)
{
double p1 = rnd.NextDouble(), p2 = rnd.NextDouble();
double c1 = 0.001, c2 = 0.05;
double w = 0.6;
for (int i = 0; i < listaListPopulacji.Count; i++)
{
for (int j = 0; j < item.wspolrzedne.Count; j++)
{
listaListPopulacji[i].predkoscJednostki = (w * listaListPopulacji[i].predkoscJednostki)
+ (c1 * p1 * (item.najlepszaOdleglosc - item.wspolrzedne[j]))
+ (c2 * p2 * (listaListPopulacji.Min(x => x.najlepszaOdleglosc) - item.wspolrzedne[j]));
}
}
for (int j = 0; j < item.wspolrzedne.Count-1; j++)
{
item.wspolrzedne[j] += item.predkoscJednostki;
}
double asd = listaListPopulacji.Min(x => x.najlepszaOdleglosc);
Jednostka dddd = (from d in listaListPopulacji where d.najlepszaOdleglosc == asd select d).First();
int index = listaListPopulacji.IndexOf(dddd);
if (item.najlepszaOdleglosc < listaListPopulacji.Min(x => x.najlepszaOdleglosc))
listaListPopulacji[index].najlepszaOdleglosc = item.najlepszaOdleglosc;
item.najlepszaOdleglosc = odlegloscEuklidesowa(item.wspolrzedne, punktNajl);
chart1.Series["Rój"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
chart1.Series["Rój"].Points.AddXY(item.wspolrzedne[0], item.wspolrzedne[1]);
if(szukane%10 == 0)
chart1.SaveImage("D:\\mgr\\" + szukane + ".png", ChartImageFormat.Png);
}
The problem is that, points still going to wrong position..
Screenshoot:
number of population: 15
number of iterations: 300
http://www.fotoszok.pl/upload/c6d480f4.png[
^]
Thank you so much for any help!
I forgot to translate:
predkoscJednostki - velocity
najlepszaPozycja - bestPosition
wspolrzedne - coordinates
najlepszaOdleglosc - best discance from point to target point