public Problem(OptimisationProblem problem, FitnessHandler fitnessFunction, double[] initialWeights) { this.fitnessFunction = fitnessFunction; solution = new Position(initialWeights.Length); SS = new SwarmSize(initialWeights.Length); int d; this.function = (int)problem; this.epsilon = 0.00000; // Acceptable error (default). May be modified below this.objective = 0; // Objective value (default). May be modified below //this.evalMax =100000 // Define the solution point, for test // NEEDED when param.stop = 2 // i.e. when stop criterion is distance_to_solution < epsilon /* for (d = 0; d < 30; d++) { this.solution.x[d] = 0; } */ this.SS.q.size = this.SS.D; this.SS.D = initialWeights.Length;// Dimension for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -1; // -100 this.SS.max[d] = 1; // 100 this.SS.q.q[d] = 0; // Relative quantisation, in [0,1]. } this.evalMax = int.MaxValue;// Max number of evaluations for each run this.epsilon = 0.0; // 1e-3; this.objective = 0; // For test purpose, the initialisation space may be different from // the search space. If so, just modify the code below for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } }
public static void quantis(Position position, SwarmSize SS) { /* Quantisatition of a position Only values like x+k*q (k integer) are admissible */ int d; double qd; for (d = 0; d < position.size; d++) { qd = SS.q.q[d]; if (qd > 0.0) // Note that qd can't be < 0 { //qd = qd * (SS.max[d] - SS.min[d]) / 2; position.x[d] = qd * Math.Floor(0.5 + position.x[d] / qd); } } }
public Problem() { solution = new Position(); SS = new SwarmSize(); }
public Problem(OptimisationProblem problem) { solution = new Position(); SS = new SwarmSize(); int d; int nAtoms; // For Lennard-Jones problem double[] lennard_jones = new[] { -1, -3, -6, -9.103852, -12.71, -16.505384, -19.821489, -24.113360, -28.422532, -32.77, -37.97, -44.33, -47.84, -52.32 }; this.function = (int)problem; this.epsilon = 0.00000; // Acceptable error (default). May be modified below this.objective = 0; // Objective value (default). May be modified below // Define the solution point, for test // NEEDED when param.stop = 2 // i.e. when stop criterion is distance_to_solution < epsilon for (d = 0; d < 30; d++) { this.solution.x[d] = 0; } // ------------------ Search space switch (this.function) { case 0: // Parabola this.SS.D = 30;// Dimension for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -100; // -100 this.SS.max[d] = 100; // 100 this.SS.q.q[d] = 0; // Relative quantisation, in [0,1]. } this.evalMax = 100000;// Max number of evaluations for each run this.epsilon = 0.0; // 1e-3; this.objective = 0; // For test purpose, the initialisation space may be different from // the search space. If so, just modify the code below for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; // May be a different value this.SS.minInit[d] = this.SS.min[d]; // May be a different value } break; case 100: // CEC 2005 F1 this.SS.D = 30;//30; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -100; this.SS.max[d] = 100; this.SS.q.q[d] = 0; } this.evalMax = this.SS.D * 10000; this.epsilon = 0.000001; //Acceptable error this.objective = -450; // Objective value for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 102: // Rosenbrock. CEC 2005 F6 this.SS.D = 10; // 10 // Boundaries for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -100; this.SS.max[d] = 100; this.SS.q.q[d] = 0; } this.evalMax = this.SS.D * 10000; this.epsilon = 0.01; //0.01 Acceptable error this.objective = 390; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 103:// CEC 2005 F9, Rastrigin this.SS.D = 30; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -5; this.SS.max[d] = 5; this.SS.q.q[d] = 0; } this.epsilon = 0.01; // 0.01; // Acceptable error this.objective = -330; // Objective value this.evalMax = this.SS.D * 10000; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 104:// CEC 2005 F2 Schwefel this.SS.D = 10; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -100; this.SS.max[d] = 100; this.SS.q.q[d] = 0; } this.epsilon = 0.00001; // Acceptable error this.objective = -450; // Objective value this.evalMax = this.SS.D * 10000; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 105:// CEC 2005 F7 Griewank (NON rotated) this.SS.D = 10; // 10 for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -600; this.SS.max[d] = 600; this.SS.q.q[d] = 0; } this.epsilon = 0.01; //Acceptable error this.objective = -180; // Objective value this.evalMax = this.SS.D * 10000; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 106:// CEC 2005 F8 Ackley (NON rotated) this.SS.D = 10; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -32; this.SS.max[d] = 32; this.SS.q.q[d] = 0; } this.epsilon = 0.0001; // Acceptable error this.objective = -140; // Objective value this.evalMax = this.SS.D * 10000; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; /* case 100: // Parabola this.SS.D =10;// Dimension for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -100; // -100 this.SS.max[d] = 100; // 100 this.SS.q.q[d] = 0; // Relative quantisation, in [0,1]. } this.evalMax = 100000;// Max number of evaluations for each run this.epsilon=0.00000; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d]=this.SS.max[d]; this.SS.minInit[d]=this.SS.min[d]; } break; */ case 1: // Griewank this.SS.D = 10; // Boundaries for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -100; this.SS.max[d] = 100; this.SS.q.q[d] = 0; } this.evalMax = 400000; this.epsilon = 0.05; this.objective = 0; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 2: // Rosenbrock this.SS.D = 30; // 30 // Boundaries for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -30; // -30; this.SS.max[d] = 30; // 30; this.SS.q.q[d] = 0; } this.epsilon = 0; this.evalMax = 300000; //2.e6; // 40000 this.objective = 0; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = 30; //this.SS.max[d]; this.SS.minInit[d] = 15; //this.SS.min[d]; } break; case 3: // Rastrigin this.SS.D = 10; // Boundaries for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -5.12; this.SS.max[d] = 5.12; this.SS.q.q[d] = 0; } this.evalMax = 3200; this.epsilon = 0.0; this.objective = 0; for (d = 0; d < this.SS.D; d++) { this.SS.minInit[d] = this.SS.min[d]; this.SS.maxInit[d] = this.SS.max[d]; } break; case 4: // Tripod this.SS.D = 2; // Dimension // Boundaries for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -100; this.SS.max[d] = 100; this.SS.q.q[d] = 0; } this.evalMax = 10000; this.epsilon = 0.0001; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 5: // Ackley this.SS.D = 10; // Boundaries for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -32; // 32 this.SS.max[d] = 32; this.SS.q.q[d] = 0; } this.evalMax = 3200; this.epsilon = 0.0; this.objective = 0; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 6: // Schwefel. Min on (A=420.8687, ..., A) this.SS.D = 30; //this.objective=-this.SS.D*420.8687*sin(Math.Sqrt(420.8687)); this.objective = -12569.5; this.epsilon = 2569.5; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -500; this.SS.max[d] = 500; this.SS.q.q[d] = 0; } this.evalMax = 300000; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 7: // Schwefel 1.2 this.SS.D = 40; this.objective = 0; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -100; this.SS.max[d] = 100; this.SS.q.q[d] = 0; } this.evalMax = 40000; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 8: // Schwefel 2.22 this.SS.D = 30; this.objective = 0; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -10; this.SS.max[d] = 10; this.SS.q.q[d] = 0; } this.evalMax = 100000; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 9: // Neumaier 3 this.SS.D = 40; this.objective = 0; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -this.SS.D * this.SS.D; this.SS.max[d] = -this.SS.min[d]; this.SS.q.q[d] = 0; } this.evalMax = 40000; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 10: // G3 (constrained) this.SS.D = 10; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = 0; this.SS.max[d] = 1; this.SS.q.q[d] = 0; } this.evalMax = 340000; this.objective = 0; this.epsilon = 1e-6; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 11: // Network // btsNb=5; bcsNb=2; btsNb = 19; bcsNb = 4; this.SS.D = bcsNb * btsNb + 2 * bcsNb; this.objective = 0; for (d = 0; d < bcsNb * btsNb; d++) // Binary representation. 1 means: there is a link { this.SS.min[d] = 0; this.SS.max[d] = 1; this.SS.q.q[d] = 1; } for (d = bcsNb * btsNb; d < this.SS.D; d++) // 2D space for the BSC positions { this.SS.min[d] = 0; this.SS.max[d] = 20; //15; this.SS.q.q[d] = 0; } this.evalMax = 50; this.objective = 0; this.epsilon = 0; break; case 12: // Schwefel this.SS.D = 30; this.objective = 0; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -500; this.SS.max[d] = 500; this.SS.q.q[d] = 0; } this.evalMax = 200000; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 13: // 2D Goldstein-Price function (f_min=3, on (0,-1)) this.SS.D = 2; // Dimension this.objective = 0; this.SS.min[0] = -100; this.SS.max[0] = 100; this.SS.q.q[0] = 0; this.SS.min[1] = -100; this.SS.max[1] = 100; this.SS.q.q[1] = 0; this.evalMax = 720; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 14: // Schaffer f6 this.SS.D = 2; // Dimension this.objective = 0; this.SS.min[0] = -100; this.SS.max[0] = 100; this.SS.q.q[0] = 0; this.SS.min[1] = -100; this.SS.max[1] = 100; this.SS.q.q[1] = 0; this.evalMax = 4000; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 15: // Step this.SS.D = 20; this.objective = 0; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -100; this.SS.max[d] = 100; this.SS.q.q[d] = 0; } this.evalMax = 2500; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 16: // Schwefel 2.21 this.SS.D = 30; this.objective = 0; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -100; this.SS.max[d] = 100; this.SS.q.q[d] = 0; } this.evalMax = 100000; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 17: // Lennard-Jones nAtoms = 2; // in {2, ..., 15} this.SS.D = 3 * nAtoms; this.objective = lennard_jones[nAtoms - 2]; this.evalMax = 5000 + 3000 * nAtoms * (nAtoms - 1); // Empirical rule this.epsilon = 1e-6; // Note: with this acceptable error, nAtoms=10 seems to be the maximum // possible value for a non-null success rate (5%) //this.SS.D=3*21; this.objective=-81.684; //this.SS.D=3*27; this.objective=-112.87358; //this.SS.D=3*38; this.objective=-173.928427; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -2; this.SS.max[d] = 2; this.SS.q.q[d] = 0; } for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; case 18: //Gear Train this.SS.D = 4; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = 12; this.SS.max[d] = 60; this.SS.q.q[d] = 1; this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } this.evalMax = 20000; this.epsilon = 1e-13; this.objective = 2.7e-12; break; case 19: // Compression spring this.constraint = 4; this.SS.D = 3; this.SS.min[0] = 1; this.SS.max[0] = 70; this.SS.q.q[0] = 1; this.SS.min[1] = 0.6; this.SS.max[1] = 3; this.SS.q.q[1] = 0; this.SS.min[2] = 0.207; this.SS.max[2] = 0.5; this.SS.q.q[2] = 0.001; //for (d = 0; d < this.SS.D; d++) //{ // this.SS.maxS[d] = this.SS.max[d]; // this.SS.minS[d] = this.SS.min[d]; //} this.evalMax = 20000; this.epsilon = 1e-10; this.objective = 2.6254214578; break; case 99: // Test this.SS.D = 2; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -100; this.SS.max[d] = 100; this.SS.q.q[d] = 0; } this.evalMax = 40000; this.objective = 0.0; this.epsilon = 0.00; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; //TODO: Figure out why the following is unreachable /* // 2D Peaks function this.SS.D = 2; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -3; this.SS.max[d] = 3; this.SS.q.q[d] = 0; } this.evalMax = 50000; this.objective = -6.551133; this.epsilon = 0.001; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; // Quartic this.SS.D = 50; this.objective = 0; for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -10; this.SS.max[d] = 10; this.SS.q.q[d] = 0; } this.evalMax = 25000; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; this.SS.D = 2; // Dimension this.objective = -2; this.SS.min[0] = -2; this.SS.max[0] = 2; this.SS.q.q[0] = 0; this.SS.min[1] = -3; this.SS.max[1] = 3; this.SS.q.q[1] = 0; this.evalMax = 10000; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; this.SS.D = 1; // Dimension // Boundaries for (d = 0; d < this.SS.D; d++) { this.SS.min[d] = -10; this.SS.max[d] = 10; this.SS.q.q[d] = 0; } this.objective = -1000; // Just a sure too small value for the above search space this.evalMax = 1000; for (d = 0; d < this.SS.D; d++) { this.SS.maxInit[d] = this.SS.max[d]; this.SS.minInit[d] = this.SS.min[d]; } break; */ } this.SS.q.size = this.SS.D; }