% ------------------------------------------------------- % [QP_reform,alg_data] = run_code_gen(QP,opts) % ------------------------------------------------------- % Generate C code to solve parametric QP:s of the form % % minimize 1/2 x'Hx + g'x + h(Cx) % subject to Ax = b % % where: % - H, C, and A are fixed matrices % - h is a soft constraint function: % % \ / % h(y) = \ / % \______/ % % with potentially infinite slopes % - g and/or b are parameters that may change for each solve % % if g parametric, then g = G*gt where gt is parameter, else g = G % if b parametric, then b = B*bt where bt is parameter, else b = B % ------------------------------------------------------- % INPUTS: QP (required), opts (optional) % ------------------------------------------------------- % % INPUT QP: (required) % % ====INDICATORS==== % QP.gt = {0,1} : indicates if g is parametric or not % QP.bt = {0,1} : indicates if b is parametric or not % % ====DATA==== % QP.H : Hessian H (required) % QP.G : linear cost matrix G (column vector if QP.gt == 0) % QP.A : equality constraint matrix A % QP.B : equality constraint r.h.s. matrix B (column vector if QP.bt == 0) % QP.C : matrix C (required) % QP.h.fcn : 'indicator' or '1norm' (required) % if QP.h.fcn == 'indicator' % QP.h.Lb : lower bounds to Cx (required) % QP.h.Ub : upper bounds to Cx (required) % QP.h.soft : slope for soft constraints for Cx (may be inf) % if QP.h.fcn == '1norm' % QP.h.gamma : scalar uniform soft penalty (required) % % this is translated to % QP.h.fcn == 'indicator' % QP.h.Lb = 0 % QP.h.Ub = 0 % QP.h.soft = QP.h.gamma % % % INPUT opts: (optional) % % - run print_opts(desc) to see available options % desc : {0,1} where 1 gives more information, and 0 gives less % ------------------------------------------------------- % OUTPUTS: QP_reform, alg_data % ------------------------------------------------------- % QP_reform: % - contains data for reformulated QP % - contains original problem in QP_reform.QP % - contains chosen options in QP_reform.opts % % alg_data: % - contains algorithm data % ------------------------------------------------------- % File generation: QPgen.h (header file) % QPgen.c (main c file with solver qp()) % qp_mex.c (mex gateway file) % qp_mex.mex* (compiled mex-file, if mex-compilation works) % ------------------------------------------------------- % MATLAB usage: [sol,iter] = qp_mex(gt,bt); (if MPC.gt == 1 and MPC.bt == 1) % [sol,iter] = qp_mex(bt); (if MPC.gt == 0 and MPC.bt == 1) % [sol,iter] = qp_mex(gt); (if MPC.gt == 1 and QP.bt == 0) % % INPUT SIZES: gt = size(QP.G,2)x1, bt = size(QP.B,2)x1 % -------------------------------------------------------