[37] | 1 | function output = calllpsolve(interfacedata) |
---|
| 2 | |
---|
| 3 | % Author Johan Löfberg |
---|
| 4 | % $Id: calllpsolve.m,v 1.9 2006/05/23 14:15:22 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 | integer_variables = interfacedata.integer_variables; |
---|
| 12 | binary_variables = interfacedata.binary_variables; |
---|
| 13 | ub = interfacedata.ub; |
---|
| 14 | lb = interfacedata.lb; |
---|
| 15 | |
---|
| 16 | n = length(c); |
---|
| 17 | % Bounded variables converted to constraints |
---|
| 18 | if ~isempty(ub) |
---|
| 19 | LB = lb; |
---|
| 20 | UB = ub; |
---|
| 21 | % LB(isinf(LB)) = -1e12; |
---|
| 22 | % UB(isinf(UB)) = 1e12; |
---|
| 23 | else |
---|
| 24 | if isempty(integer_variables) & isempty(binary_variables) |
---|
| 25 | LB = -ones(n,1)*inf;;%-ones(n,1)*0; |
---|
| 26 | UB = ones(n,1)*inf;;%[];%ones(n,1)*500; |
---|
| 27 | else |
---|
| 28 | %LP_SOLVE FAILS IF BOUNDS NOT EXPLICIT |
---|
| 29 | [LB,UB,used_rows] = findulb(F_struc,K); |
---|
| 30 | LB(isinf(LB)) = -1e12; |
---|
| 31 | UB(isinf(UB)) = 1e12; |
---|
| 32 | F_struc(K.f+used_rows,:)=[]; |
---|
| 33 | K.l = K.l - length(used_rows); |
---|
| 34 | LB(binary_variables) = max(LB(binary_variables),0); |
---|
| 35 | UB(binary_variables) = min(UB(binary_variables),0); |
---|
| 36 | end |
---|
| 37 | end |
---|
| 38 | |
---|
| 39 | if options.showprogress;showprogress('Calling LPSOLVE',options.showprogress);end |
---|
| 40 | |
---|
| 41 | f = - full(c); % Must be full |
---|
| 42 | A = - F_struc(:,2:end); |
---|
| 43 | b = full(F_struc(:,1)); % Must be full |
---|
| 44 | e = -ones(size(A,1),1); |
---|
| 45 | e(1:K.f) = 0; |
---|
| 46 | |
---|
| 47 | xint = uniquestripped([integer_variables binary_variables]); |
---|
| 48 | |
---|
| 49 | % Call mex-interface |
---|
| 50 | solvertime = clock; |
---|
| 51 | if options.savedebug |
---|
| 52 | save mxlpsolvedebug f A b e UB LB xint |
---|
| 53 | end |
---|
| 54 | |
---|
| 55 | lp = create_lp_solve_model(A,b,f,xint,LB,UB,e,options); |
---|
| 56 | |
---|
| 57 | try |
---|
| 58 | solvertime = clock; |
---|
| 59 | if options.showprogress;showprogress(['Calling ' interfacedata.solver.tag],options.showprogress);end |
---|
| 60 | result=mxlpsolve('solve', lp); |
---|
| 61 | solvertime = etime(clock,solvertime); |
---|
| 62 | if result == 0 | result == 1 | result == 11 | result == 12 |
---|
| 63 | [obj, x, duals] = mxlpsolve('get_solution', lp); |
---|
| 64 | else |
---|
| 65 | obj = []; |
---|
| 66 | x = zeros(length(c),1); |
---|
| 67 | duals = []; |
---|
| 68 | end |
---|
| 69 | mxlpsolve('delete_lp', lp); |
---|
| 70 | catch |
---|
| 71 | obj = []; |
---|
| 72 | x = zeros(length(c),1); |
---|
| 73 | duals = []; |
---|
| 74 | result = -1; |
---|
| 75 | mxlpsolve('delete_lp', lp); |
---|
| 76 | end |
---|
| 77 | |
---|
| 78 | if options.saveduals & isempty(integer_variables) |
---|
| 79 | D_struc = duals; |
---|
| 80 | else |
---|
| 81 | D_struc = []; |
---|
| 82 | end |
---|
| 83 | |
---|
| 84 | switch result |
---|
| 85 | case 0 |
---|
| 86 | problem = 0; % OPTIMAL |
---|
| 87 | case 2 |
---|
| 88 | problem = 1; % INFEASIBLE |
---|
| 89 | case 3 |
---|
| 90 | problem = 2; % UNBOUNDED |
---|
| 91 | case {1,7,12,13} |
---|
| 92 | problem = 3; % RUN OUT OF TIME OR SIMILIAR |
---|
| 93 | case 5 |
---|
| 94 | problem = 4; |
---|
| 95 | case {-2,10,11} |
---|
| 96 | problem = 11; |
---|
| 97 | otherwise |
---|
| 98 | problem = -1; |
---|
| 99 | end |
---|
| 100 | |
---|
| 101 | infostr = yalmiperror(problem,interfacedata.solver.tag); |
---|
| 102 | |
---|
| 103 | % Save all data sent to solver? |
---|
| 104 | if options.savesolverinput |
---|
| 105 | solverinput.A = A; |
---|
| 106 | solverinput.f = f; |
---|
| 107 | solverinput.b = b; |
---|
| 108 | solverinput.LB = LB; |
---|
| 109 | solverinput.UB = UB; |
---|
| 110 | solverinput.xint = xint; |
---|
| 111 | else |
---|
| 112 | solverinput = []; |
---|
| 113 | end |
---|
| 114 | |
---|
| 115 | % Save all data from the solver? |
---|
| 116 | if options.savesolveroutput |
---|
| 117 | solveroutput.x = x; |
---|
| 118 | solveroutput.obj = obj; |
---|
| 119 | solveroutput.duals = duals; |
---|
| 120 | solveroutput.result = result; |
---|
| 121 | else |
---|
| 122 | solveroutput = []; |
---|
| 123 | end |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | % Standard interface |
---|
| 127 | output.Primal = x; |
---|
| 128 | output.Dual = D_struc; |
---|
| 129 | output.Slack = []; |
---|
| 130 | output.problem = problem; |
---|
| 131 | output.infostr = infostr; |
---|
| 132 | output.solverinput = solverinput; |
---|
| 133 | output.solveroutput= solveroutput; |
---|
| 134 | output.solvertime = solvertime; |
---|