Evolution calculation (instance: Multi-peak function

zhaozj2021-02-16  56

Evolution calculation is based on new algorithms that are search; its technical model is from natural evolution. Below is an example, the function is a function of typical multi-peak (dramatic). The algorithm used is Guo Tao algorithm.

Question: The maximum value of the function: f (x, y) = 21.5 x * sin (4 * pi * x) y * sin (20 * pi * y) Defining domain D: -3 <= x <= 12.1 , 4.1 <= y <= 5.8 is currently the best results: F (11.6255448, 5.7250441) = 38.8502944790207 Program debug on VC . NET, the original code is as follows (for reference only): / ** Class _point represents the vector of two-dimensional space , Ie the target function's own variable point ************************************************** ****************************** / # pragma onceclass _point {public: double x, y; _point (void): x (0), y (0) { } _Point (double xx, double yy): x (xx), y (yy) {} ~ _point (void) {} ​​_ points & operator = (const _point & point) {this-> x = Point.x; this-> y = point.y; return * this;} _ points-> x = point.x; this-> y = point.y; return * this;} _ points & operator * (Double K) {this-> x * = k; this-> y * = k; return * this;}}; / ** name: percy lee * e-mail: percylee@eyou.com* Time: 2003-3-3- 16 ** compute the max_number of: * f (x, y) = 21.5 x * sin (4 * pi * x) y * SIN (20 * pi * y) * D: -3 <= x <= 12.1 , 4.1 <= y <= 5.8 ************************************************************* ******************************************* / # include #include #include

/ * SEED THE Random-Number Generator with current time SO THAT * The number we run. * / Srand ((unsigned) Time (NULL)); start = clock (); initialize_p (); Long Int T = 0; // Iterative number INT i_WORST = 0; // Best location Double Z_Best = 0.0, z_Worst = 0.0; x_best = getBestX (); x_oldbest = getWorstx (i_Worst); z_best = f (x_best); z_Worst = f (x_worst); while (z_best-z_worst> min) {// iterative calculation x = selectx (); if (xx <-3 || xx> 12.1 || xy <4.1 || xy> 5.8) Continue; if (f (x)> z_WORST) P [i_Worst] = x; Else {//! // //} T ; x_oldbest = x_best; x_best = getBestX (); x_worst = getWorstx (i_Worst); z_best = f (x_best); z_Worst = f (x_worst); // If there is an improvement, print intermediate result if (z_best> f (x_oldbest)) {finish = clock (); cout << "/ nthe time is:" << (Finish-start) << "MS ..." << endl; cout.precision (14); cout << "f (" << x_best.x << "," << x_best.y << ") = "<< z_best << Endl;}} finish = clock (); cout <<" / nthe time is: "<< (finish-start) <<" ms ... "; cout <<" / nnow the Answer Of f) is: "<< Endl; cout.precision (14); cout <<" f ("<< x_best.x <<", "<< x_best.y <<") = "<< z_best << ENDL << ENDL;} / ** Random number generated function (overloaded two) ** / double mAX (double min, double max) {double randnum = 0.0; randnum = (double) rand () / rand_max; randnum * = (max-min); randnum = min; return}} int random (int max) {int RANDNUM = 1; randnum =

(INT) (MAX * ((Double) Rand () / rand_max); Return RandNum;} / ** Seeking the most promising target function ** / double f (const _point & point) {double z = 0.0; z = Point .x * sin (4 * pi * point.x) Point.y * sin (20 * pi * point.y) 21.5; return z;} / ** initialized group ** / void initialize_p () {for ( INT i = 0; i zz) {z = zz Point = p [i]; i_worst = i;}} Return Point;} / ** From the population P in the population P, the conditions should be met according to a [] (random vector): * SUM (a [i ]) = 1, i = 1, 2, ..., m, & -0.5 <= a [i] <= 1.5 * generated from the sub-space V ** / _ point selectx () {_ Point Point; Double A [M]; INT i_RAND = 0; Double SUM = 0.0; Double Max = 1.5; for (INT I = 0; I

转载请注明原文地址:https://www.9cbs.com/read-25451.html

New Post(0)