00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00032 #include <acado/code_generation/export_qpoases_interface.hpp>
00033 #include <acado/code_generation/templates/templates.hpp>
00034
00035 using namespace std;
00036
00037 BEGIN_NAMESPACE_ACADO
00038
00039
00040 ExportQpOasesInterface::ExportQpOasesInterface( const std::string& _headerFileName,
00041 const std::string& _sourceFileName,
00042 const std::string& _commonHeaderName,
00043 const std::string& _realString,
00044 const std::string& _intString,
00045 int _precision,
00046 const std::string& _commentString
00047 )
00048 : qpoHeader(QPOASES_HEADER, _headerFileName, _commonHeaderName, _realString, _intString, _precision, _commentString),
00049 qpoSource(QPOASES_SOURCE, _sourceFileName, _commonHeaderName, _realString, _intString, _precision, _commentString)
00050 {}
00051
00052
00053 returnValue ExportQpOasesInterface::configure( const std::string& _prefix,
00054 const std::string& _solverDefine,
00055 const int nvmax,
00056 const int ncmax,
00057 const int nwsrmax,
00058 const std::string& _printLevel,
00059 bool _useSinglePrecision,
00060
00061 const std::string& _commonHeader,
00062 const std::string& _namespace,
00063 const std::string& _primalSolution,
00064 const std::string& _dualSolution,
00065 const std::string& _sigma,
00066 bool _hotstartQP,
00067 bool _externalCholesky,
00068 const std::string& _qpH,
00069 const std::string& _qpR,
00070 const std::string& _qpg,
00071 const std::string& _qpA,
00072 const std::string& _qplb,
00073 const std::string& _qpub,
00074 const std::string& _qplbA,
00075 const std::string& _qpubA
00076 )
00077 {
00078
00079
00080
00081
00082 stringstream s, ctor;
00083 string solverName;
00084 if (ncmax > 0)
00085 {
00086 solverName = "QProblem";
00087
00088 s << _qpH << ", ";
00089 if (_externalCholesky == false)
00090 s << _qpR << ", ";
00091 s << _qpg << ", " << _qpA << ", " << _qplb << ", " << _qpub << ", "
00092 << _qplbA << ", " << _qpubA << ", " << "nWSR";
00093
00094 if ( (bool)_hotstartQP == true )
00095 s << ", " << _dualSolution;
00096
00097 ctor << solverName << " qp(" << nvmax << ", " << ncmax << ")";
00098 }
00099 else
00100 {
00101 solverName = "QProblemB";
00102
00103 s << _qpH << ", ";
00104 if (_externalCholesky == false)
00105 s << _qpR << ", ";
00106 s << _qpg << ", " << _qplb << ", " << _qpub << ", " << "nWSR";
00107
00108 if ( (bool)_hotstartQP == true )
00109 s << ", " << _dualSolution;
00110
00111 ctor << solverName << " qp( " << nvmax << " )";
00112 }
00113
00114 qpoSource.dictionary[ "@ACADO_COMMON_HEADER@" ] = _commonHeader;
00115 qpoSource.dictionary[ "@SOLVER_NAME@" ] = solverName;
00116 qpoSource.dictionary[ "@PREFIX@" ] = _prefix;
00117 qpoSource.dictionary[ "@USE_NAMESPACE@" ] = _namespace;
00118 qpoSource.dictionary[ "@CALL_SOLVER@" ] = s.str();
00119 qpoSource.dictionary[ "@PRIMAL_SOLUTION@" ] = _primalSolution;
00120 qpoSource.dictionary[ "@DUAL_SOLUTION@" ] = _dualSolution;
00121 qpoSource.dictionary[ "@CTOR@" ] = ctor.str();
00122 qpoSource.dictionary[ "@SIGMA@" ] = _sigma;
00123
00124
00125 qpoSource.fillTemplate();
00126
00127
00128
00129
00130
00131
00132 qpoHeader.dictionary[ "@PREFIX@" ] = _prefix;
00133 qpoHeader.dictionary[ "@SOLVER_DEFINE@" ] = _solverDefine;
00134
00135 qpoHeader.dictionary[ "@NVMAX@" ] = toString( nvmax );
00136
00137 qpoHeader.dictionary[ "@NCMAX@" ] = toString( ncmax );
00138
00139 qpoHeader.dictionary[ "@NWSRMAX@" ] = toString(nwsrmax > 0 ? nwsrmax : 3 * (nvmax + ncmax));
00140
00141 qpoHeader.dictionary[ "@PRINT_LEVEL@" ] = _printLevel;
00142
00143 double eps;
00144 string realT;
00145 if ( _useSinglePrecision )
00146 {
00147 eps = 1.193e-07;
00148 realT = "float";
00149 }
00150 else
00151 {
00152 eps = 2.221e-16;
00153 realT = "double";
00154 }
00155 qpoHeader.dictionary[ "@EPS@" ] = toString( eps );
00156 qpoHeader.dictionary[ "@REAL_T@" ] = toString( realT );
00157
00158
00159 qpoHeader.fillTemplate();
00160
00161 return SUCCESSFUL_RETURN;
00162 }
00163
00164 returnValue ExportQpOasesInterface::exportCode()
00165 {
00166 qpoHeader.exportCode();
00167 qpoSource.exportCode();
00168
00169 return SUCCESSFUL_RETURN;
00170 }
00171
00172
00173 CLOSE_NAMESPACE_ACADO