Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<random>
- #include<fstream>
- #include"opt_alg.h"
- #include"ode_solver.h"
- int main()
- {
- try
- {
- /*double x0,
- a = 1e-4,
- b = 1e-2,
- epsilon = 1e-6,
- d = 1e-5,
- alfa = 1.76;
- int Nmax = 1000;
- random_device rd;
- int i = 1;
- ofstream file("wynik.csv");
- file << "Iteracja" << "," << "x0" << "," << "w" << "," << "a" << "," << "b" << ","
- << "x_opt_f" << "," << "y_opt_f" << "," << "w_f" << ","
- << "x_opt_l" << "," << "y_opt_l" << "," << "w_l" << endl;
- for (i; i < 4; i++) {
- x0 = (b - a)*rd() / rd.max() + a;
- double *p = expansion(x0, d, alfa, Nmax);
- int w_eksp = solution::f_calls;
- solution::f_calls = 0;
- solution opt_f = fib(p[0], p[1], epsilon);
- int w_fib = solution::f_calls;
- solution::f_calls = 0;
- matrix f_x = opt_f.x;
- matrix f_y = opt_f.y;
- opt_f = lag(p[0], p[1], epsilon, Nmax);
- int w_lag = solution::f_calls;
- solution::f_calls = 0;
- matrix l_x = opt_f.x;
- matrix l_y = opt_f.y;
- file << i << "," << x0 << "," << w_eksp << "," << p[0] << "," << p[1] << ","
- << f_x << "," << f_y << "," << w_fib << ","
- << l_x << "," << l_y << "," << w_lag << endl;
- }
- file.close();
- */
- //********************************* LAB 2**************************************
- /*double alfa, beta, epsilon = 1e-3, s = 0.9;
- int Nmax = 1000;
- matrix x0(2, 1);
- ofstream file("wynik.csv");
- //petla
- for (int i=1;i<101;i++)
- {
- random_device rd;
- x0(0) = 10.0 * rd() / rd.max(); // k1-k2 zmieniaja sie w zakresie od 1-10
- x0(1) = 10.0 * rd() / rd.max();
- cout << x0 << endl << endl;
- file << i << ";" << x0(0) << ";" << x0(1) << ";";
- solution::f_calls = 0;
- alfa = 0.5;
- solution opt_HJ = HJ(x0, s, alfa, epsilon, Nmax);
- cout << opt_HJ.x << endl << opt_HJ.y << endl << solution::f_calls << endl;
- file << opt_HJ.x(0) << ";" << opt_HJ.x(1) << ";" << opt_HJ.y << ";" << solution::f_calls << ";";
- solution::f_calls = 0;
- matrix s0(new double[2]{ s,s }, 2);
- alfa = 2;
- beta = 0.5;
- solution opt_R = Rosen(x0, s0, alfa, beta, epsilon, Nmax);
- cout << opt_R.x(0) << endl << opt_R.y << endl << solution::f_calls << endl;
- file << opt_R.x(0) << ";" << opt_R.x(1) << ";" << opt_R.y << ";" << solution::f_calls << endl;
- }
- file.close();
- */
- //LAB 4
- double epsilon = 1e-3;
- int Nmax = 1000;
- matrix x0(2, 1);
- random_device rd;
- x0(0) = 20.0*rd() / rd.max() - 10;
- x0(1) = 20.0*rd() / rd.max() - 10;
- cout << x0 << endl << endl;
- solution optSD = SD(x0, epsilon, Nmax);
- cout << optSD.x << endl << optSD.y << endl << solution::f_calls << endl << solution::g_calls << endl << endl;
- }
- catch (char * EX_INFO)
- {
- cout << EX_INFO << endl;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement