1+ #include < iostream>
2+ #include " ../lib/mathalgorithm.h"
3+ using namespace mal ;
4+
5+ /* minimal inclusion:
6+ #include "../lib/optimization.h"
7+ using namespace opt; */
8+
9+ int main ()
10+ {
11+ double epsilon = 1e-6 ;
12+
13+ std::cout << " 约束优化问题:" << std::endl;
14+ function<double (double ,double )> f_pre = [](double x, double y)
15+ {
16+ return x + sqrt (3 .) * y;
17+ };
18+ auto f = MatrizeInputs (f_pre);
19+ function<Matrix<double >(double ,double )> c_pre = [](double x, double y)
20+ {
21+ return Matrix<double >(x*x+y*y-1 .,1 ,1 );
22+ };
23+ auto c = MatrizeInputs (c_pre);
24+ Matrix<double > initial (1 .,2 ,1 );
25+ std::cout << " AugmentedLagrangian" <<std::endl<<
26+ Transpose (AugmentedLagrangian<double >(f, c, initial, epsilon, BFGS<double >))
27+ <<std::endl;
28+
29+ std::cout << " 无约束优化问题:" << std::endl;
30+ function<double (double ,double )> g_pre = [](double x,double y)
31+ {
32+ return x * x + 10 . * y * y;
33+ };
34+ auto g = MatrizeInputs (g_pre);
35+ Matrix<double > initial2 (vector<vector<double >>({{-10 .}, {-1 .}}));
36+ double step = 0.085 ;
37+ std::cout << " GradientDescentFixedStepsize" <<std::endl<<
38+ Transpose (GradientDescentFixedStepsize (g, initial2, epsilon, step)) << std::endl;
39+ std::cout << " GradientDescentWolfe" <<std::endl<<
40+ Transpose (GradientDescentWolfe (g, initial2, epsilon)) << std::endl;
41+ std::cout << " GradientDescentGoldstein" <<std::endl<<
42+ Transpose (GradientDescentGoldstein (g, initial2, epsilon)) << std::endl;
43+ std::cout << " BarzilarBorwein" <<std::endl<<
44+ Transpose (BarzilarBorwein (g, initial2, epsilon)) << std::endl;
45+ std::cout << " FletcherReeves" << std::endl<<
46+ Transpose (FletcherReeves (g, initial2, epsilon)) << std::endl;
47+ std::cout << " PolakRibiere" << std::endl<<
48+ Transpose (PolakRibiere (g, initial2, epsilon)) << std::endl;
49+ std::cout << " SR1" <<std::endl<<
50+ Transpose (SR1 (g, initial2, epsilon)) << std::endl;
51+ std::cout << " DFP" <<std::endl<<
52+ Transpose (DFP (g, initial2, epsilon)) << std::endl;
53+ std::cout << " BFGS" <<std::endl<<
54+ Transpose (BFGS (g, initial2, epsilon)) << std::endl;
55+
56+ Matrix<double > initial3 (vector<vector<double >>({{-0.1 }, {-0.1 }}));
57+ std::cout << " ClassicNewton" <<std::endl<<
58+ Transpose (ClassicNewton (g, initial3, epsilon)) << std::endl;
59+ std::cout << " ModifiedNewtonGoldstein" <<std::endl<<
60+ Transpose (ModifiedNewtonGoldstein (g, initial2, epsilon)) << std::endl;
61+ system (" pause" );
62+ return 0 ;
63+ }
64+
0 commit comments