Exemplo n.º 1
0
        public static Velocity Initialize(Position pos, SwarmSize swarmSize)
        {
            int d;

            var vel = new Velocity(Constants.DMax) {Size = pos.size};

            // Half-diff  0.5*(alea-x)

            for (d = 0; d < vel.Size; d++)
            {
                vel.V[d] = (Alea.NextDouble(swarmSize.min[d], swarmSize.max[d]) - pos.x[d]) / 2;
            }

            return vel;
        }
Exemplo n.º 2
0
 public XV()
 {
     x=new Position(Constants.DMax);
     v=new Velocity(Constants.DMax);
 }
Exemplo n.º 3
0
        // ===========================================================
        static double normL(Velocity v, double L)
        {
            // L-norm of a vector
            int d;
            double n;

            n = 0;

            for (d = 0; d < v.Size; d++)
                n = n + Math.Pow(Math.Abs(v.V[d]), L);

            n = Math.Pow(n, 1 / L);
            return n;
        }
Exemplo n.º 4
0
        static XV move(Result R, int s, int g, IProblem pb,
                    Parameters parameters)
        {
            double c1, c2;
            int d;
            Velocity GX = new Velocity(Constants.DMax);
            Velocity PX = new Velocity(Constants.DMax);

            XV xv = new XV();
            double w;

            xv.x.size = pb.SwarmSize.D;
            xv.v.Size = pb.SwarmSize.D;
            PX.Size = pb.SwarmSize.D;
            GX.Size = pb.SwarmSize.D;

            w = parameters.w;
            c1 = parameters.c1;
            c2 = parameters.c2;

            // Update the velocity (Exploration tendency)
            for (d = 0; d < pb.SwarmSize.D; d++)
            {
                xv.v.V[d] = w * R.SW.V[s].V[d];
            }

            // --------------------------------------------------------NORMAL PSO STRATEGY

            // Prepare Exploitation tendency
            for (d = 0; d < pb.SwarmSize.D; d++) // p-x
            {
                PX.V[d] = R.SW.P[s].x[d] - R.SW.X[s].x[d];
            }

            if (g != s)
            {
                for (d = 0; d < pb.SwarmSize.D; d++) // g-x
                {
                    GX.V[d] = R.SW.P[g].x[d] - R.SW.X[s].x[d];
                }
            }

            // Complete the velocity
            for (d = 0; d < pb.SwarmSize.D; d++)
            {
                xv.v.V[d] = xv.v.V[d] + Alea.NextDouble(0, c1) * PX.V[d];

            }

            if (g != s) // If the best neighbour is not the particle itself
            {
                for (d = 0; d < pb.SwarmSize.D; d++)
                {
                    xv.v.V[d] = xv.v.V[d] + Alea.NextDouble(0, c2) * GX.V[d];
                }
            }

            // Update the position
            for (d = 0; d < pb.SwarmSize.D; d++)
            {
                xv.x.x[d] = R.SW.X[s].x[d] + xv.v.V[d];
            }

            // NOTE that the position is not yet evaluated
            return xv;
        }