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 epsilon = 1e-3;
- int Nmax = 1000;
- matrix x0(2, 1);
- random_device rd;
- double kroki[3] = { 0.05, 0.11, 0 };
- ofstream pointsFile, resultsFile;
- pointsFile.open("points.csv");
- resultsFile.open("results.csv");
- for (int i = 0; i < 100; i++)
- {
- x0(0) = 20.0*rd() / rd.max() - 10;
- x0(1) = 20.0*rd() / rd.max() - 10;
- pointsFile << x0 << endl;
- for (int j = 0; j < 3; j++)
- {
- double krok = kroki[j];
- resultsFile << x0;
- if (krok == 0) {
- resultsFile << "M. zk.;";
- }
- else {
- resultsFile << krok << ";";
- }
- solution::f_calls = 0;
- solution::g_calls = 0;
- solution::H_calls = 0;
- solution opt_ns = najszybszy_spadek(x0, epsilon, Nmax, 0);
- resultsFile << opt_ns.x << opt_ns.y << solution::f_calls << ";" << solution::g_calls << ";";
- solution::f_calls = 0;
- solution::g_calls = 0;
- solution::H_calls = 0;
- solution opt_gs = gradienty_sprzezone(x0, epsilon, Nmax, 0);
- resultsFile << opt_gs.x << opt_gs.y << solution::f_calls << ";" << solution::g_calls << ";";
- solution::f_calls = 0;
- solution::g_calls = 0;
- solution::H_calls = 0;
- solution opt_n = metoda_Newtona(x0, epsilon, Nmax, 0);
- resultsFile << opt_n.x << opt_n.y << solution::f_calls << ";" << solution::g_calls << ";" << solution::H_calls << ";" << endl;
- }
- cout << (i + 1) << "%" << endl;
- }
- pointsFile.close();
- resultsFile.close();
- }
- catch (char * EX_INFO)
- {
- cout << EX_INFO << endl;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement