Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 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.  
  11. /*double x0,
  12. a = 1e-4,
  13. b = 1e-2,
  14. epsilon = 1e-6,
  15. d = 1e-5,
  16. alfa = 1.76;
  17.  
  18. int Nmax = 1000;
  19. random_device rd;
  20.  
  21. int i = 1;
  22. ofstream file("wynik.csv");
  23.  
  24. file << "Iteracja" << "," << "x0" << "," << "w" << "," << "a" << "," << "b" << ","
  25. << "x_opt_f" << "," << "y_opt_f" << "," << "w_f" << ","
  26. << "x_opt_l" << "," << "y_opt_l" << "," << "w_l" << endl;
  27.  
  28. for (i; i < 4; i++) {
  29. x0 = (b - a)*rd() / rd.max() + a;
  30.  
  31. double *p = expansion(x0, d, alfa, Nmax);
  32. int w_eksp = solution::f_calls;
  33. solution::f_calls = 0;
  34.  
  35. solution opt_f = fib(p[0], p[1], epsilon);
  36. int w_fib = solution::f_calls;
  37. solution::f_calls = 0;
  38. matrix f_x = opt_f.x;
  39. matrix f_y = opt_f.y;
  40.  
  41. opt_f = lag(p[0], p[1], epsilon, Nmax);
  42. int w_lag = solution::f_calls;
  43. solution::f_calls = 0;
  44. matrix l_x = opt_f.x;
  45. matrix l_y = opt_f.y;
  46.  
  47. file << i << "," << x0 << "," << w_eksp << "," << p[0] << "," << p[1] << ","
  48. << f_x << "," << f_y << "," << w_fib << ","
  49. << l_x << "," << l_y << "," << w_lag << endl;
  50. }
  51. file.close();
  52. */
  53.  
  54. //********************************* LAB 2**************************************
  55. /*double alfa, beta, epsilon = 1e-3, s = 0.9;
  56. int Nmax = 1000;
  57. matrix x0(2, 1);
  58. ofstream file("wynik.csv");
  59. //petla
  60. for (int i=1;i<101;i++)
  61. {
  62. random_device rd;
  63. x0(0) = 10.0 * rd() / rd.max(); // k1-k2 zmieniaja sie w zakresie od 1-10
  64. x0(1) = 10.0 * rd() / rd.max();
  65. cout << x0 << endl << endl;
  66.  
  67. file << i << ";" << x0(0) << ";" << x0(1) << ";";
  68.  
  69. solution::f_calls = 0;
  70. alfa = 0.5;
  71. solution opt_HJ = HJ(x0, s, alfa, epsilon, Nmax);
  72. cout << opt_HJ.x << endl << opt_HJ.y << endl << solution::f_calls << endl;
  73. file << opt_HJ.x(0) << ";" << opt_HJ.x(1) << ";" << opt_HJ.y << ";" << solution::f_calls << ";";
  74.  
  75.  
  76. solution::f_calls = 0;
  77. matrix s0(new double[2]{ s,s }, 2);
  78. alfa = 2;
  79. beta = 0.5;
  80. solution opt_R = Rosen(x0, s0, alfa, beta, epsilon, Nmax);
  81. cout << opt_R.x(0) << endl << opt_R.y << endl << solution::f_calls << endl;
  82. file << opt_R.x(0) << ";" << opt_R.x(1) << ";" << opt_R.y << ";" << solution::f_calls << endl;
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89. file.close();
  90. */
  91. //LAB 4
  92. double epsilon = 1e-3;
  93. int Nmax = 1000;
  94. matrix x0(2, 1);
  95. random_device rd;
  96. x0(0) = 20.0*rd() / rd.max() - 10;
  97. x0(1) = 20.0*rd() / rd.max() - 10;
  98. cout << x0 << endl << endl;
  99. solution optSD = SD(x0, epsilon, Nmax);
  100. cout << optSD.x << endl << optSD.y << endl << solution::f_calls << endl << solution::g_calls << endl << endl;
  101.  
  102.  
  103. }
  104. catch (char * EX_INFO)
  105. {
  106. cout << EX_INFO << endl;
  107. }
  108. system("pause");
  109.  
  110. return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement