Cheetah Software  1.0
test_goldfarb.cpp
Go to the documentation of this file.
1 #include "gmock/gmock.h"
2 #include "gtest/gtest.h"
3 
4 #include "../third-party/Goldfarb_Optimizer/QuadProg++.hh"
5 #include "Utilities/utilities.h"
6 
7 TEST(Goldfarb_Optimizer, Goldfarb_opt_test) {
8  // problem:
9  // >> H = [4 1; 1 2]; f = [1;1]; A = [1 1; 1 0; 0 1; -1 -1; -1 0; 0 -1]; b =
10  // [1 .7 .7 -1 0 0]';
11  // >> x = quadprog(H,f,A,b)
12  // x =
13  //
14  // 0.3000
15  // 0.7000
16 
17  // hessian
18  GMatr<double> G(2, 2);
19  G[0][0] = 4.0;
20  G[0][1] = 1.;
21  G[1][0] = 1.;
22  G[1][1] = 2.;
23 
24  GVect<double> g0(2);
25  g0[0] = 1.;
26  g0[1] = 1.;
27 
28  GMatr<double> CE(0., 2, 1);
29  CE[0][0] = 1.;
30  CE[1][0] = 1.;
31  GVect<double> ce0(1);
32  ce0[0] = -1.0;
33 
34  GMatr<double> CI(0., 2, 4);
35  CI[0][0] = 1.;
36  CI[1][1] = 1.;
37  CI[0][2] = -1.;
38  CI[1][3] = -1.;
39 
40  GVect<double> ci0(4);
41  ci0[0] = 0.;
42  ci0[1] = 0.;
43  ci0[2] = 0.7;
44  ci0[3] = 0.7;
45 
46  GVect<double> x;
47  double f = solve_quadprog(G, g0, CE, ce0, CI, ci0, x);
48 
49  printf("cost: %f\n", f);
50  printf("solution: %6.3f, %6.3f\n", x[0], x[1]);
51 
52  EXPECT_TRUE(fpEqual(x[0], .3, .0001));
53  EXPECT_TRUE(fpEqual(x[1], .7, .0001));
54 }
bool fpEqual(T a, T b, T tol)
Definition: utilities.h:15
TEST(Goldfarb_Optimizer, Goldfarb_opt_test)
MX f(const MX &x, const MX &u)