Esempio n. 1
0
        public static List <AbstractPSOParticle> CreateSwarm(ETopology topology, EFunction function, EConstrictionFactor constrictionFactor, int particleAmmount)
        {
            List <AbstractPSOParticle> swarm = new List <AbstractPSOParticle>();

            for (int i = 0; i < particleAmmount; i++)
            {
                if (topology == ETopology.Ring)
                {
                    swarm.Add(new LocalParticle(function, constrictionFactor));
                }
                else if (topology == ETopology.Global)
                {
                    swarm.Add(new GlobalParticle(function, constrictionFactor));
                }
                else if (topology == ETopology.Focal)
                {
                    swarm.Add(new FocalParticle(function, constrictionFactor, swarm, i == 0));
                }
            }

            if (topology == ETopology.Ring)
            {
                for (int i = 0; i < swarm.Count; i++)
                {
                    ((LocalParticle)swarm[i]).LinkSwarm(swarm, i);
                }
            }

            return(swarm);
        }
        public static void SaveToFile(ETopology top, EFunction fun, EConstrictionFactor cons, List <List <Double> > outputSamples, int id)
        {
            List <String> stringList = new List <string>();
            String        s          = "";

            for (int i = 0; i < Parameters.SAMPLE_COUNT; i++)
            {
                s += (i + 1) + "\t";
            }

            stringList.Add(s + "Fitness\tIterations (Average from 30 samples)");

            for (int i = 0; i < Parameters.ITERATION_AMOUNT; i++)
            {
                String temp = "";
                Double sum  = 0d;
                for (int j = 0; j < Parameters.PARTICLE_AMOUNT; j++)
                {
                    sum  += outputSamples[j][i];
                    temp += outputSamples[j][i] + "\t";
                }
                stringList.Add(temp + i + "\t" + sum / Parameters.PARTICLE_AMOUNT);
            }

            System.IO.File.WriteAllLines(@"WriteLines" + top.ToString() + "," + fun.ToString() + "," + cons.ToString() + "," + id + ".txt", stringList.ToArray());
        }
        public static void SaveToFile2(ETopology top, EFunction fun, EConstrictionFactor cons, List <List <Double> > outputSamples, int id)
        {
            List <String> stringList = new List <string>();

            stringList.Add("Iterations\tFitness (Avergage from 30 samples)");
            stringList.Add("{");
            for (int i = 0; i < Parameters.SAMPLE_COUNT; i++)
            {
                stringList.Add((outputSamples[i][outputSamples[i].Count - 1]).ToString().Replace(',', '.') + ",");
            }
            stringList.Add("}");

            System.IO.File.WriteAllLines(@"" + top + ", " + fun + ", " + cons + ", " + id + ".txt", stringList.ToArray());
        }
        public static void BeginSimulationPSO(ETopology top, EFunction fun, EConstrictionFactor cons, int id)
        {
            List <List <Double> > lld = new List <List <Double> >();

            for (int i = 0; i < Parameters.SAMPLE_COUNT; i++)
            {
                Particle_Swarm_Optimization.Swarm s = (new Particle_Swarm_Optimization.Swarm(top, fun, cons));
                s.InitializeSwarm();
                s.UpdatePopulation(true);

                lld.Add(s.GlobalBestLog);

                Console.WriteLine("Iteração " + i + ": GBest: " + AbstractPSOParticle.GlobalBest);
            }


            SaveToFile(top, fun, cons, lld, id);
            SaveToFile2(top, fun, cons, lld, id);
        }
 private void radioButtonTopo_CheckedChanged(object sender, EventArgs e)
 {
     if (radioButtonTFull.Checked)
     {
         topolagyType = ETopology.Full;
         return;
     }
     if (radioButtonTRing.Checked)
     {
         topolagyType = ETopology.Ring;
         return;
     }
     if (radioButtonT4.Checked)
     {
         topolagyType = ETopology.N4;
         return;
     }
 }
Esempio n. 6
0
 public Swarm(ETopology topology, EFunction function, EConstrictionFactor constrictionFactor)
 {
     AbstractPSOParticle.ClearStaticFields();
     ParticleList = AbstractPSOParticle.CreateSwarm(topology, function, constrictionFactor, Parameters.PARTICLE_AMOUNT);
 }