[37] | 1 | function output = callquadprog(interfacedata) |
---|
| 2 | |
---|
| 3 | % Author Johan Löfberg |
---|
| 4 | % $Id: callpennlp.m,v 1.5 2005/05/07 13:53:20 joloef Exp $ |
---|
| 5 | |
---|
| 6 | % Retrieve needed data |
---|
| 7 | options = interfacedata.options; |
---|
| 8 | F_struc = interfacedata.F_struc; |
---|
| 9 | c = interfacedata.c; |
---|
| 10 | K = interfacedata.K; |
---|
| 11 | x0 = interfacedata.x0; |
---|
| 12 | Q = interfacedata.Q; |
---|
| 13 | lb = interfacedata.lb; |
---|
| 14 | ub = interfacedata.ub; |
---|
| 15 | monomtable = interfacedata.monomtable; |
---|
| 16 | |
---|
| 17 | switch options.verbose |
---|
| 18 | case 0 |
---|
| 19 | options.fmincon.Display = 'off'; |
---|
| 20 | case 1 |
---|
| 21 | options.fmincon.Display = 'final'; |
---|
| 22 | otherwise |
---|
| 23 | options.fmincon.Display = 'iter'; |
---|
| 24 | end |
---|
| 25 | |
---|
| 26 | % Do some pre-calc to be used in calls from pennlp |
---|
| 27 | temp = sum(interfacedata.monomtable,2)>1; |
---|
| 28 | temp = (sum(interfacedata.monomtable,2)==1 & sum(interfacedata.monomtable~=0,2)==1); |
---|
| 29 | nonlinearindicies = find(full(~temp)); |
---|
| 30 | linearindicies = find(full(temp)); |
---|
| 31 | interfacedata.nonlinearindicies = nonlinearindicies; |
---|
| 32 | interfacedata.linearindicies = linearindicies; |
---|
| 33 | |
---|
| 34 | Infinity = 1.0E38; |
---|
| 35 | if isempty(lb) |
---|
| 36 | lb = -Infinity*ones(length(linearindicies),1); |
---|
| 37 | else |
---|
| 38 | lb(isinf(lb)) = -Infinity; |
---|
| 39 | end |
---|
| 40 | if isempty(ub) |
---|
| 41 | ub = Infinity*ones(length(linearindicies),1); |
---|
| 42 | else |
---|
| 43 | ub(isinf(ub)) = Infinity; |
---|
| 44 | end |
---|
| 45 | |
---|
| 46 | % Numer of constraints |
---|
| 47 | m = K.l+K.f; |
---|
| 48 | n = length(linearindicies); |
---|
| 49 | |
---|
| 50 | lb = lb(linearindicies); |
---|
| 51 | ub = ub(linearindicies); |
---|
| 52 | |
---|
| 53 | lbc = 0*ones(m,1); |
---|
| 54 | ubc = Infinity*ones(m,1); |
---|
| 55 | ubc(1:K.f) = 0; |
---|
| 56 | |
---|
| 57 | if isempty(x0) |
---|
| 58 | x0 = zeros(length(linearindicies),1); |
---|
| 59 | else |
---|
| 60 | x0 = x0(linearindicies); |
---|
| 61 | end |
---|
| 62 | |
---|
| 63 | linearConstraints = ~any(F_struc(1:K.f+K.l,1+nonlinearindicies),2); |
---|
| 64 | if ~isempty(linearConstraints) |
---|
| 65 | F = F_struc(1:K.f+K.l,:); |
---|
| 66 | F_struc = [F(~linearConstraints,:);F(linearConstraints,:);F_struc(K.f+K.l+1:end,:)]; |
---|
| 67 | lbc = [lbc(~linearConstraints);lbc(linearConstraints)]; |
---|
| 68 | ubc = [ubc(~linearConstraints);ubc(linearConstraints)]; |
---|
| 69 | end |
---|
| 70 | |
---|
| 71 | functiondata.nonlinearindicies = nonlinearindicies; |
---|
| 72 | functiondata.linearindicies = linearindicies; |
---|
| 73 | functiondata.monomtable = monomtable; |
---|
| 74 | functionGradientdata.nonlinearindicies = nonlinearindicies; |
---|
| 75 | functionGradientdata.linearindicies = linearindicies; |
---|
| 76 | functionGradientdata.monomtable = monomtable; |
---|
| 77 | functionHessiandata.nonlinearindicies = nonlinearindicies; |
---|
| 78 | functionHessiandata.linearindicies = linearindicies; |
---|
| 79 | functionHessiandata.monomtable = monomtable; |
---|
| 80 | |
---|
| 81 | constraintdata.nonlinearindicies = nonlinearindicies; |
---|
| 82 | constraintdata.linearindicies = linearindicies; |
---|
| 83 | constraintdata.monomtable = monomtable; |
---|
| 84 | constraintGradientdata.nonlinearindicies = nonlinearindicies; |
---|
| 85 | constraintGradientdata.linearindicies = linearindicies; |
---|
| 86 | constraintGradientdata.monomtable = monomtable; |
---|
| 87 | constraintHessiandata.nonlinearindicies = nonlinearindicies; |
---|
| 88 | constraintHessiandata.linearindicies = linearindicies; |
---|
| 89 | constraintHessiandata.monomtable = monomtable; |
---|
| 90 | |
---|
| 91 | functiondata.F_struc = [interfacedata.f c(:)']; |
---|
| 92 | constraintdata.F_struc = F_struc(1:K.l+K.f,:);start = K.f + K.l + 1; |
---|
| 93 | functionGradientdata.F_struc = F_struc(start:start+n-1,:);start = start+n; |
---|
| 94 | functionHessiandata.F_struc = F_struc(start:start+n^2-1,:);start = start+n^2; |
---|
| 95 | constraintGradientdata.F_struc = F_struc(start:start+n*m-1,:);start = start+n*m; |
---|
| 96 | constraintHessiandata.F_struc = F_struc(start:end,:);start = start+n*m; |
---|
| 97 | |
---|
| 98 | datasaver(functiondata,functionGradientdata,functionHessiandata,constraintdata,constraintGradientdata,constraintHessiandata) |
---|
| 99 | |
---|
| 100 | Infinity = 1.0E38; |
---|
| 101 | pen.nvars = n; |
---|
| 102 | pen.nlin = length(find(linearConstraints)); |
---|
| 103 | pen.nconstr = m; |
---|
| 104 | pen.nnz_gradient = n; |
---|
| 105 | pen.nnz_hessian = (n+1)*n/2; |
---|
| 106 | pen.lbv = lb(:)'; |
---|
| 107 | pen.ubv = ub(:)'; |
---|
| 108 | pen.lbc = lbc(:)'; |
---|
| 109 | pen.ubc = ubc(:)'; |
---|
| 110 | pen.xinit= x0(:)'; |
---|
| 111 | pen.my_f = 'pennlp_fun'; |
---|
| 112 | pen.my_f_gradient = 'pennlp_fungrad'; |
---|
| 113 | pen.my_f_hessian = 'pennlp_funhess'; |
---|
| 114 | pen.my_g = 'pennlp_con'; |
---|
| 115 | pen.my_g_gradient = 'pennlp_congrad'; |
---|
| 116 | pen.my_g_hessian = 'pennlp_conhess'; |
---|
| 117 | |
---|
| 118 | ops = struct2cell(options.pennlp);ops = [ops{1:end}]; |
---|
| 119 | pen.ioptions = [ops(1:2) options.verbose ops(3:15)]; |
---|
| 120 | if options.verbose>0 |
---|
| 121 | pen.ioptions(3) = pen.ioptions(3)+1; |
---|
| 122 | end |
---|
| 123 | pen.doptions = ops(16:end); |
---|
| 124 | |
---|
| 125 | %pen.ioptions = ops(1:15); |
---|
| 126 | %pen.foptions = ops(16:end); |
---|
| 127 | %pen.ioptions(4) = max(0,min(3,options.verbose+1)); |
---|
| 128 | |
---|
| 129 | %pen.ioptions = [100 100 2 0 0 0 1 0 0 2 0 0 0 -1 0 1]; |
---|
| 130 | %pen.doptions = [1.0E-7 1.0E0 1.0E-0 1.0E-2 5.0E-1 1.0E-1 1.0E-6 1.0E-12 1.0e-1 0.05 1.0 1.0 1.0]; |
---|
| 131 | |
---|
| 132 | if options.savedebug |
---|
| 133 | save pennlpdebug pen |
---|
| 134 | end |
---|
| 135 | |
---|
| 136 | showprogress('Calling FMINCON',options.showprogress); |
---|
| 137 | solvertime = clock; |
---|
| 138 | [obj,xout,duals,flag] = pennlpm(pen); |
---|
| 139 | solvertime = etime(clock,solvertime); |
---|
| 140 | |
---|
| 141 | if isempty(nonlinearindicies) |
---|
| 142 | x = xout(:); |
---|
| 143 | else |
---|
| 144 | x = zeros(length(interfacedata.c),1); |
---|
| 145 | for i = 1:length(linearindicies) |
---|
| 146 | x(linearindicies(i)) = xout(i); |
---|
| 147 | end |
---|
| 148 | end |
---|
| 149 | |
---|
| 150 | switch flag |
---|
| 151 | case 0 |
---|
| 152 | problem = 0; |
---|
| 153 | case {1,6,7} |
---|
| 154 | problem = 4; |
---|
| 155 | otherwise |
---|
| 156 | problem = 9; |
---|
| 157 | end |
---|
| 158 | |
---|
| 159 | % Internal format for duals |
---|
| 160 | D_struc = []; |
---|
| 161 | |
---|
| 162 | % Save all data sent to solver? |
---|
| 163 | if options.savesolverinput |
---|
| 164 | solverinput.pen = pen; |
---|
| 165 | else |
---|
| 166 | solverinput = []; |
---|
| 167 | end |
---|
| 168 | |
---|
| 169 | % Save all data from the solver? |
---|
| 170 | if options.savesolveroutput |
---|
| 171 | solveroutput.obj = obj; |
---|
| 172 | solveroutput.xout = xout; |
---|
| 173 | solveroutput.duals = duals; |
---|
| 174 | solveroutput.flag = flag; |
---|
| 175 | else |
---|
| 176 | solveroutput = []; |
---|
| 177 | end |
---|
| 178 | |
---|
| 179 | % Standard interface |
---|
| 180 | output.Primal = x; |
---|
| 181 | output.Dual = D_struc; |
---|
| 182 | output.Slack = []; |
---|
| 183 | output.problem = problem; |
---|
| 184 | output.solverinput = solverinput; |
---|
| 185 | output.solveroutput= solveroutput; |
---|
| 186 | output.solvertime = solvertime; |
---|