Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include<random>
  2. #include<fstream>
  3. #include"opt_alg.h"
  4. #include"ode_solver.h"
  5.  
  6. int main()
  7. {
  8.     try
  9.     {
  10.         double epsilon = 1e-3;
  11.         int Nmax = 1000;
  12.         matrix x0(2, 1);
  13.         random_device rd;
  14.  
  15.         double kroki[3] = { 0.05, 0.11, 0 };
  16.  
  17.         ofstream pointsFile, resultsFile;
  18.  
  19.         pointsFile.open("points.csv");
  20.         resultsFile.open("results.csv");
  21.         for (int i = 0; i < 100; i++)
  22.         {
  23.             x0(0) = 20.0*rd() / rd.max() - 10;
  24.             x0(1) = 20.0*rd() / rd.max() - 10;
  25.             pointsFile << x0 << endl;
  26.  
  27.             for (int j = 0; j < 3; j++)
  28.             {
  29.                 double krok = kroki[j];
  30.  
  31.                 resultsFile << x0;
  32.  
  33.                 if (krok == 0) {
  34.                     resultsFile << "M. zk.;";
  35.                 }
  36.                 else {
  37.                     resultsFile << krok << ";";
  38.                 }
  39.  
  40.                 solution::f_calls = 0;
  41.                 solution::g_calls = 0;
  42.                 solution::H_calls = 0;
  43.                 solution opt_ns = najszybszy_spadek(x0, epsilon, Nmax, 0);
  44.                 resultsFile << opt_ns.x << opt_ns.y << solution::f_calls << ";" << solution::g_calls << ";";
  45.  
  46.                 solution::f_calls = 0;
  47.                 solution::g_calls = 0;
  48.                 solution::H_calls = 0;
  49.                 solution opt_gs = gradienty_sprzezone(x0, epsilon, Nmax, 0);
  50.                 resultsFile << opt_gs.x << opt_gs.y << solution::f_calls << ";" << solution::g_calls << ";";
  51.  
  52.                 solution::f_calls = 0;
  53.                 solution::g_calls = 0;
  54.                 solution::H_calls = 0;
  55.                 solution opt_n = metoda_Newtona(x0, epsilon, Nmax, 0);
  56.                 resultsFile << opt_n.x << opt_n.y << solution::f_calls << ";" << solution::g_calls << ";" << solution::H_calls << ";" << endl;
  57.             }
  58.  
  59.             cout << (i + 1) << "%" << endl;
  60.         }
  61.         pointsFile.close();
  62.         resultsFile.close();
  63.  
  64.  
  65.     }
  66.     catch (char * EX_INFO)
  67.     {
  68.         cout << EX_INFO << endl;
  69.     }
  70.     system("pause");
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement