[37] | 1 | function output = calllinprog(interfacedata) |
---|
| 2 | |
---|
| 3 | % Author Johan Löfberg |
---|
| 4 | % $Id: calllinprog.m,v 1.6 2005/05/07 13:53:20 joloef Exp $ |
---|
| 5 | |
---|
| 6 | % Standard input interface |
---|
| 7 | options = interfacedata.options; |
---|
| 8 | F_struc = interfacedata.F_struc; |
---|
| 9 | c = interfacedata.c; |
---|
| 10 | K = interfacedata.K; |
---|
| 11 | Q = interfacedata.Q; |
---|
| 12 | lb = interfacedata.lb; |
---|
| 13 | ub = interfacedata.ub; |
---|
| 14 | |
---|
| 15 | showprogress('Calling LINPROG',options.showprogress); |
---|
| 16 | |
---|
| 17 | if isempty(F_struc) |
---|
| 18 | Aeq = []; |
---|
| 19 | beq = []; |
---|
| 20 | A = []; |
---|
| 21 | b = []; |
---|
| 22 | else |
---|
| 23 | Aeq = -F_struc(1:1:K.f,2:end); |
---|
| 24 | beq = F_struc(1:1:K.f,1); |
---|
| 25 | A =-F_struc(K.f+1:end,2:end); |
---|
| 26 | b = F_struc(K.f+1:end,1); |
---|
| 27 | end |
---|
| 28 | solvertime = clock; |
---|
| 29 | |
---|
| 30 | switch options.verbose |
---|
| 31 | case 0 |
---|
| 32 | options.linprog.Display = 'off'; |
---|
| 33 | case 1 |
---|
| 34 | options.linprog.Display = 'final'; |
---|
| 35 | otherwise |
---|
| 36 | options.linprog.Display = 'iter'; |
---|
| 37 | end |
---|
| 38 | |
---|
| 39 | if isfield(options.linprog,'LargeScale') |
---|
| 40 | if ~isequal(options.linprog.LargeScale,'on') |
---|
| 41 | Q = full(Q); |
---|
| 42 | c = full(c); |
---|
| 43 | A = full(A); |
---|
| 44 | b = full(b); |
---|
| 45 | Aeq = full(Aeq); |
---|
| 46 | beq = full(beq); |
---|
| 47 | end |
---|
| 48 | end |
---|
| 49 | |
---|
| 50 | if options.savedebug |
---|
| 51 | ops = options.linprog; |
---|
| 52 | save linprogdebug c A b Aeq beq lb ub ops |
---|
| 53 | end |
---|
| 54 | |
---|
| 55 | [x,fmin,flag,output,lambda] = linprog(c, A, b, Aeq, beq, lb, ub, [],options.linprog); |
---|
| 56 | solvertime = etime(clock,solvertime); |
---|
| 57 | problem = 0; |
---|
| 58 | |
---|
| 59 | % Internal format for duals |
---|
| 60 | D_struc = [lambda.eqlin;lambda.ineqlin]; |
---|
| 61 | |
---|
| 62 | % Check, currently not exhaustive... |
---|
| 63 | if flag==0 |
---|
| 64 | problem = 3; |
---|
| 65 | else |
---|
| 66 | if flag>0 |
---|
| 67 | problem = 0; |
---|
| 68 | else |
---|
| 69 | if isempty(x) |
---|
| 70 | x = repmat(nan,length(c),1); |
---|
| 71 | end |
---|
| 72 | if any((A*x-b)>sqrt(eps)) | any( abs(Aeq*x-beq)>sqrt(eps)) |
---|
| 73 | problem = 1; % Likely to be infeasible |
---|
| 74 | else |
---|
| 75 | if c'*x<-1e10 % Likely unbounded |
---|
| 76 | problem = 2; |
---|
| 77 | else % Probably convergence issues |
---|
| 78 | problem = 5; |
---|
| 79 | end |
---|
| 80 | end |
---|
| 81 | end |
---|
| 82 | end |
---|
| 83 | infostr = yalmiperror(problem,'LINPROG'); |
---|
| 84 | |
---|
| 85 | % Save all data sent to solver? |
---|
| 86 | if options.savesolverinput |
---|
| 87 | solverinput.A = A; |
---|
| 88 | solverinput.b = b; |
---|
| 89 | solverinput.Aeq = Aq; |
---|
| 90 | solverinput.beq = beq; |
---|
| 91 | solverinput.c = c; |
---|
| 92 | solverinput.options = options.linprog; |
---|
| 93 | else |
---|
| 94 | solverinput = []; |
---|
| 95 | end |
---|
| 96 | |
---|
| 97 | % Save all data from the solver? |
---|
| 98 | if options.savesolveroutput |
---|
| 99 | solveroutput.x = x; |
---|
| 100 | solveroutput.fmin = fmin; |
---|
| 101 | solveroutput.flag = flag; |
---|
| 102 | solveroutput.output=output; |
---|
| 103 | else |
---|
| 104 | solveroutput = []; |
---|
| 105 | end |
---|
| 106 | |
---|
| 107 | % Standard interface |
---|
| 108 | output.Primal = x(:); |
---|
| 109 | output.Dual = D_struc; |
---|
| 110 | output.Slack = []; |
---|
| 111 | output.problem = problem; |
---|
| 112 | output.infostr = infostr; |
---|
| 113 | output.solverinput = solverinput; |
---|
| 114 | output.solveroutput= solveroutput; |
---|
| 115 | output.solvertime = solvertime; |
---|