[37] | 1 | function output = callnage04naf(varargin) |
---|
| 2 | % Author Johan Löfberg |
---|
| 3 | % $Id: callnage04naf.m,v 1.12 2006/04/10 09:34:47 joloef Exp $ |
---|
| 4 | |
---|
| 5 | % Hack for NAG |
---|
| 6 | persistent Q |
---|
| 7 | |
---|
| 8 | if nargin>1 |
---|
| 9 | output = Q*varargin{6}; |
---|
| 10 | return |
---|
| 11 | end |
---|
| 12 | |
---|
| 13 | % Retrieve needed data |
---|
| 14 | interfacedata = varargin{1}; |
---|
| 15 | options = interfacedata.options; |
---|
| 16 | F_struc = interfacedata.F_struc; |
---|
| 17 | c = interfacedata.c; |
---|
| 18 | K = interfacedata.K; |
---|
| 19 | x0 = interfacedata.x0; |
---|
| 20 | Q = 2*interfacedata.Q; |
---|
| 21 | ub = interfacedata.ub; |
---|
| 22 | lb = interfacedata.lb; |
---|
| 23 | |
---|
| 24 | bigbnd = options.nag.bigbnd; |
---|
| 25 | if isempty(ub) |
---|
| 26 | ub = bigbnd*ones(length(c),1); |
---|
| 27 | lb = -bigbnd*ones(length(c),1); |
---|
| 28 | end |
---|
| 29 | |
---|
| 30 | % NAG fails on semidefinite |
---|
| 31 | if nnz(Q)>0 |
---|
| 32 | ii = find(diag(Q)==0); |
---|
| 33 | if ~isempty(ii) |
---|
| 34 | d = zeros(length(Q),1); |
---|
| 35 | d(ii) = sqrt(eps); |
---|
| 36 | Q = Q + diag(d); |
---|
| 37 | end |
---|
| 38 | end |
---|
| 39 | |
---|
| 40 | showprogress('Calling NAG',options.showprogress); |
---|
| 41 | |
---|
| 42 | if ~isempty(F_struc) |
---|
| 43 | A =-F_struc(1:end,2:end); |
---|
| 44 | beq = F_struc(1:1:K.f,1); |
---|
| 45 | b = F_struc(K.f+1:end,1); |
---|
| 46 | |
---|
| 47 | ub = full([ub;beq;b]); |
---|
| 48 | lb = full([lb;beq;-bigbnd*ones(length(b),1)]); |
---|
| 49 | elseif ~isempty(lb)% NAG stinks on problems with no A<b constraints |
---|
| 50 | A = eye(length(c)); |
---|
| 51 | ub = full([ub;ub]); |
---|
| 52 | lb = full([lb;lb]); |
---|
| 53 | else |
---|
| 54 | A = zeros(1,length(c)); |
---|
| 55 | ub = full([ub;1]); |
---|
| 56 | lb = full([lb;0]); |
---|
| 57 | end |
---|
| 58 | |
---|
| 59 | % Bug prevents lp=full(nnz(... |
---|
| 60 | if nnz(Q)==0 |
---|
| 61 | lp = 1; |
---|
| 62 | else |
---|
| 63 | lp = 0; |
---|
| 64 | end |
---|
| 65 | |
---|
| 66 | cold = 1; |
---|
| 67 | istate = zeros(length(ub),1); |
---|
| 68 | featol = options.nag.featol*ones(length(ub),1); |
---|
| 69 | switch options.verbose |
---|
| 70 | case 0 |
---|
| 71 | msglev = -1; |
---|
| 72 | ifail = 1; |
---|
| 73 | case 1 |
---|
| 74 | msglev = 2; |
---|
| 75 | ifail = -1; |
---|
| 76 | otherwise |
---|
| 77 | msglev = 5*options.verbose; |
---|
| 78 | ifail = -1; |
---|
| 79 | end |
---|
| 80 | solvertime = clock; |
---|
| 81 | |
---|
| 82 | [x,iter,obj,clambda,istate,ifail] = e04naf(full(lb),full(ub),'callnage04naf',zeros(length(c),1),full(c),full(A),0,lp, cold,istate,featol,msglev,options.nag.itmax,options.nag.bigbnd,options.nag.orthog,ifail); |
---|
| 83 | |
---|
| 84 | solvertime = etime(clock,solvertime); |
---|
| 85 | problem = 0; |
---|
| 86 | |
---|
| 87 | % Internal format for duals |
---|
| 88 | D_struc = -clambda(length(c)+1:end); |
---|
| 89 | |
---|
| 90 | switch ifail |
---|
| 91 | case {-1,0,1,3} |
---|
| 92 | problem = 0; |
---|
| 93 | case 2 |
---|
| 94 | problem = 2; |
---|
| 95 | case {4,7} |
---|
| 96 | problem = 4; |
---|
| 97 | case {5,8} |
---|
| 98 | problem = 3; |
---|
| 99 | case 6 |
---|
| 100 | problem = 1; |
---|
| 101 | otherwise |
---|
| 102 | problem = 9; |
---|
| 103 | end |
---|
| 104 | infostr = yalmiperror(problem,'NAG'); |
---|
| 105 | |
---|
| 106 | % Save all data sent to solver? |
---|
| 107 | if options.savesolverinput |
---|
| 108 | solverinput.bl = full(lb); |
---|
| 109 | solverinput.bu = full(ub); |
---|
| 110 | solverinput.X = zeros(length(c),1); |
---|
| 111 | solverinput.cvec = full(c); |
---|
| 112 | solverinput.A = full(A); |
---|
| 113 | else |
---|
| 114 | solverinput = []; |
---|
| 115 | end |
---|
| 116 | |
---|
| 117 | % Save all data from the solver? |
---|
| 118 | if options.savesolveroutput |
---|
| 119 | solveroutput.x = x; |
---|
| 120 | solveroutput.iter = iter; |
---|
| 121 | solveroutput.obj = obj; |
---|
| 122 | solveroutput.clambda=clambda; |
---|
| 123 | solveroutput.istate=istate; |
---|
| 124 | solveroutput.ifail=ifail; |
---|
| 125 | else |
---|
| 126 | solveroutput = []; |
---|
| 127 | end |
---|
| 128 | |
---|
| 129 | % Standard interface |
---|
| 130 | output.Primal = x; |
---|
| 131 | output.Dual = D_struc; |
---|
| 132 | output.Slack = []; |
---|
| 133 | output.problem = problem; |
---|
| 134 | output.infostr = infostr; |
---|
| 135 | output.solverinput = solverinput; |
---|
| 136 | output.solveroutput= solveroutput; |
---|
| 137 | output.solvertime = solvertime; |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | % NAG-hack |
---|
| 141 | clear Q |
---|