public static void Main(string[] args) { try { Console.WriteLine("\nBegin Multiple Particle Swarm optimization demo\n"); Console.WriteLine("Goal is to minimize Rastrigin's function"); Console.WriteLine("Function has known solution of 0.0 at x0 = 0.0, x1 = 0.0"); Console.WriteLine("\nSetting minX = -100.0 and maxX = +100.0"); int dim = 2; double minX = -100.0; double maxX = 100.0; Console.WriteLine("Setting number particles in each swarm = 4"); Console.WriteLine("Setting number swarms in multiswarm = 3"); int numParticles = 4; // number particles in each swarm int numSwarms = 3; // number swarms in multiswarm Console.WriteLine("\nInitializing all swarms in multiswarm"); Multiswarm ms = new Multiswarm(numSwarms, numParticles, dim, minX, maxX); Console.WriteLine("\nInitial multiswarm:"); Console.WriteLine(ms.ToString()); int maxLoop = 150; Console.WriteLine("\nSetting maxLoop = " + maxLoop); Console.WriteLine("Entering main solve loop"); ms.Solve(maxLoop); Console.WriteLine("Solve loop complete"); Console.WriteLine("\nFinal multiswarm:"); Console.WriteLine(ms.ToString()); Console.WriteLine("\nBest solution found = " + ms.bestMultiCost.ToString("F6")); Console.Write("at x0 = " + ms.bestMultiPos[0].ToString("F4")); Console.WriteLine(", x1 = " + ms.bestMultiPos[1].ToString("F4")); Console.WriteLine("\nEnd demo\n"); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }