Go to the documentation of this file.00001 #include <iostream>
00002 #include <qpOASES.hpp>
00003
00004 using namespace qpOASES;
00005 extern "C" {
00006 double* solve_qpoases_qp (double* ret,
00007 double* eval_weight_matrix, double* eval_coeff_vector,
00008 double* state_min_vector, double* state_max_vector,
00009 double* inequality_matrix, double* inequality_min_vector, double* inequality_max_vector,
00010 int state_len, int inequality_len, PrintLevel print_level, double* ret_status) {
00011 real_t* H = new real_t[state_len*state_len];
00012 real_t* A = new real_t[inequality_len*state_len];
00013 real_t* g = new real_t[state_len];
00014 real_t* ub = new real_t[state_len];
00015 real_t* lb = new real_t[state_len];
00016 real_t* ubA = new real_t[inequality_len];
00017 real_t* lbA = new real_t[inequality_len];
00018 for (int i = 0; i < state_len*state_len; i++) {
00019 H[i] = eval_weight_matrix[i];
00020 }
00021 for (int i = 0; i < state_len; i++) {
00022 ub[i] = state_max_vector[i];
00023 }
00024 for (int i = 0; i < state_len; i++) {
00025 lb[i] = state_min_vector[i];
00026 }
00027 for (int i = 0; i < state_len; i++) {
00028 g[i] = eval_coeff_vector[i];
00029 }
00030 for (int i = 0; i < inequality_len; i++) {
00031 ubA[i] = inequality_max_vector[i];
00032 }
00033 for (int i = 0; i < inequality_len; i++) {
00034 lbA[i] = inequality_min_vector[i];
00035 }
00036 for (int i = 0; i < inequality_len*state_len; i++) {
00037 A[i] = inequality_matrix[i];
00038 }
00039
00040 QProblem example( state_len,inequality_len );
00041 Options options;
00042 options.printLevel = print_level;
00043 example.setOptions( options );
00044
00045 int nWSR = 1000;
00046 returnValue status = example.init( H,g,A,lb,ub,lbA,ubA, nWSR );
00047
00048 ret_status[0] = getSimpleStatus(status, (print_level != PL_NONE)? BT_TRUE:BT_FALSE);
00049
00050 real_t* xOpt = new real_t[state_len];
00051 example.getPrimalSolution( xOpt );
00052 for (int i = 0; i < state_len; i++) {
00053 ret[i] = xOpt[i];
00054 }
00055 delete[] H;
00056 delete[] A;
00057 delete[] g;
00058 delete[] ub;
00059 delete[] lb;
00060 delete[] ubA;
00061 delete[] lbA;
00062 delete[] xOpt;
00063
00064 return ret;
00065 }
00066
00067 double* solve_qpoases_lp (double* ret,
00068 double* eval_coeff_vector,
00069 double* state_min_vector, double* state_max_vector,
00070 double* inequality_matrix, double* inequality_min_vector, double* inequality_max_vector,
00071 int state_len, int inequality_len, PrintLevel print_level, double* ret_status) {
00072 real_t* H = new real_t[state_len*state_len];
00073 real_t* A = new real_t[inequality_len*state_len];
00074 real_t* g = new real_t[state_len];
00075 real_t* ub = new real_t[state_len];
00076 real_t* lb = new real_t[state_len];
00077 real_t* ubA = new real_t[inequality_len];
00078 real_t* lbA = new real_t[inequality_len];
00079
00080 for (int i = 0; i < state_len*state_len; i++) {
00081 H[i] = 0.0;
00082 }
00083 for (int i = 0; i < inequality_len*state_len; i++) {
00084 A[i] = inequality_matrix[i];
00085 }
00086 for (int i = 0; i < state_len; i++) {
00087 g[i] = eval_coeff_vector[i];
00088 }
00089 for (int i = 0; i < state_len; i++) {
00090 ub[i] = state_max_vector[i];
00091 }
00092 for (int i = 0; i < state_len; i++) {
00093 lb[i] = state_min_vector[i];
00094 }
00095 for (int i = 0; i < inequality_len; i++) {
00096 ubA[i] = inequality_max_vector[i];
00097 }
00098 for (int i = 0; i < inequality_len; i++) {
00099 lbA[i] = inequality_min_vector[i];
00100 }
00101
00102
00103 QProblem example( state_len, inequality_len, HST_ZERO );
00104
00105 Options options;
00106 options.printLevel = print_level;
00107 example.setOptions( options );
00108
00109
00110 int nWSR = 1000;
00111 returnValue status = example.init( H,g,A,lb,ub,lbA,ubA, nWSR);
00112 ret_status[0] = getSimpleStatus(status, (print_level != PL_NONE)? BT_TRUE:BT_FALSE);
00113 real_t* xOpt = new real_t[state_len];
00114 example.getPrimalSolution( xOpt );
00115 for (int i = 0; i < state_len; i++) {
00116 ret[i] = xOpt[i];
00117 }
00118
00119 delete[] H;
00120 delete[] A;
00121 delete[] g;
00122 delete[] ub;
00123 delete[] lb;
00124 delete[] ubA;
00125 delete[] lbA;
00126 delete[] xOpt;
00127
00128 return ret;
00129 }
00130 }