예제 #1
0
        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());
        }
예제 #2
0
        public AbstractPSOParticle(EFunction functionType, EConstrictionFactor constrictionType)
        {
            Position = new double[Parameters.DIMENSION_AMOUNT];
            Velocity = new double[Parameters.DIMENSION_AMOUNT];

            if (function == null || constriction == null)
            {
                AbstractPSOParticle.functionType     = functionType;
                AbstractPSOParticle.constrictionType = constrictionType;
                function     = AbstractFunction.InstanceFunction(functionType);
                constriction = AbstractConstrictionFactor.InstanceFunction(constrictionType);
            }
        }
예제 #3
0
        public FocalParticle(EFunction functionType, EConstrictionFactor constrictionType, List <AbstractPSOParticle> swarm, bool isFocalParticle) : base(functionType, constrictionType)
        {
            this.swarm           = swarm;
            this.IsFocalParticle = isFocalParticle;

            foreach (AbstractPSOParticle abs in swarm)
            {
                if (((FocalParticle)abs).IsFocalParticle)
                {
                    focalParticle = abs;
                    break;
                }
            }
        }
예제 #4
0
        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 AbstractConstrictionFactor InstanceFunction(EConstrictionFactor constrictionFactor)
 {
     if (constrictionFactor == EConstrictionFactor.FixedInertia)
     {
         return(new FixedInertia());
     }
     else if (constrictionFactor == EConstrictionFactor.FloatingInertia)
     {
         return(new FloatingInertia());
     }
     else
     {
         return(new ClercConstriction());
     }
 }
예제 #6
0
        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);
        }
예제 #7
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);
        }
예제 #8
0
 public Swarm(ETopology topology, EFunction function, EConstrictionFactor constrictionFactor)
 {
     AbstractPSOParticle.ClearStaticFields();
     ParticleList = AbstractPSOParticle.CreateSwarm(topology, function, constrictionFactor, Parameters.PARTICLE_AMOUNT);
 }
예제 #9
0
 public GlobalParticle(EFunction functionType, EConstrictionFactor constrictionType) : base(functionType, constrictionType)
 {
 }
 public LocalParticle(EFunction functionType, EConstrictionFactor parameter) : base(functionType, parameter)
 {
 }