Click here to Skip to main content
15,912,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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[^]


C#
do //do while numbers of iterations = X
{
    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; 

// two loops, one for count of all items on listalistPopulacji, second for counts of coordinates

        for (int i = 0; i < listaListPopulacji.Count; i++) //item.wspolrzedne.Count
        {
            for (int j = 0; j < item.wspolrzedne.Count; j++)
	{
// update new velocity
	listaListPopulacji[i].predkoscJednostki = (w * listaListPopulacji[i].predkoscJednostki)
                + (c1 * p1 * (item.najlepszaOdleglosc - item.wspolrzedne[j]))
                + (c2 * p2 * (listaListPopulacji.Min(x => x.najlepszaOdleglosc) - item.wspolrzedne[j]));
			}
        }
// change coordinates for: coordinate = cooridnate + velocity
        for (int j = 0; j < item.wspolrzedne.Count-1; j++)
        {
                item.wspolrzedne[j] += item.predkoscJednostki;//item.predkoscJednostki;
        }
        //find best distance(interval) on listalistPopulacji
        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);
        //check each distance, if its smaller than minimum, change it            
        if (item.najlepszaOdleglosc < listaListPopulacji.Min(x => x.najlepszaOdleglosc))
            listaListPopulacji[index].najlepszaOdleglosc = item.najlepszaOdleglosc;

        item.najlepszaOdleglosc = odlegloscEuklidesowa(item.wspolrzedne, punktNajl);
                    
                      

//draw points on chart, and save it to img
        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
Posted
Updated 16-Apr-12 10:24am
v4
Comments
Nelek 15-Apr-12 17:53pm    
Hi, just a tiny advice. It is easier for you to get the snippet into notepad and do a "search and replace" of the terms, posting here the translated code, than for us to read the code having to pay attention to your translatios below the code. If you don't mind... it will make things easier for us, what means, easier for you to get help :)
Sergey Alexandrovich Kryukov 16-Apr-12 18:41pm    
Good idea. I also advise to write all code in English, regardless of one's native culture. Honestly, this is easier for everyone, including the original author.
--SA
Sergey Alexandrovich Kryukov 16-Apr-12 18:40pm    
Is it Polish?
--SA
Nelek 16-Apr-12 18:47pm    
I would say yes. Link of the image is .pl
SASS_Shooter 23-Apr-12 12:35pm    
I would agree with the others that if you update your code into all English, then improve your post with the new code will make it easier to read.

It seems from what little I read that you have a target for your swarm? The image does not show that clearly. (Make your target bright red!!!) Your image doesn't help to understand if the swarm is just swimming around, if each member of the swarm has a range of detection, if any of them are actually moving towards the target.

I'd suggest starting with a swarm of 1 particle. Put tracing into your code and stop at each iteration waiting for a button click. At times that is the only way to see if you AI is working or whack. Use tracing to determine why you are computing the new values. Your values should become a linear graph from point of detection to attack of the target...unless the target is moving all the time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900