[37] | 1 | function output = callcplexmex(interfacedata) |
---|
| 2 | |
---|
| 3 | % Author Johan Löfberg |
---|
| 4 | % $Id: callcplexmex.m,v 1.4 2006/05/03 07:58:45 joloef Exp $ |
---|
| 5 | |
---|
| 6 | % Retrieve needed data |
---|
| 7 | options = interfacedata.options; |
---|
| 8 | F_struc = interfacedata.F_struc; |
---|
| 9 | c = interfacedata.c; |
---|
| 10 | Q = interfacedata.Q; |
---|
| 11 | K = interfacedata.K; |
---|
| 12 | x0 = interfacedata.x0; |
---|
| 13 | integer_variables = interfacedata.integer_variables; |
---|
| 14 | binary_variables = interfacedata.binary_variables; |
---|
| 15 | LB = interfacedata.lb; |
---|
| 16 | UB = interfacedata.ub; |
---|
| 17 | |
---|
| 18 | showprogress('Calling CPLEXMEX',options.showprogress); |
---|
| 19 | |
---|
| 20 | if ~isempty(LB) |
---|
| 21 | LB(isinf(LB)) = -1e12; |
---|
| 22 | UB(isinf(UB)) = 1e12; |
---|
| 23 | end |
---|
| 24 | |
---|
| 25 | SENSE = 1; |
---|
| 26 | C = c(:); |
---|
| 27 | if ~isempty(F_struc) |
---|
| 28 | A =-F_struc(:,2:end); |
---|
| 29 | B = full(F_struc(:,1)); |
---|
| 30 | else |
---|
| 31 | A = zeros(1,length(c));A(1)=1; |
---|
| 32 | B = 1e6; |
---|
| 33 | end |
---|
| 34 | |
---|
| 35 | H = 2*full(Q); |
---|
| 36 | if nnz(H)==0 |
---|
| 37 | H = []; |
---|
| 38 | end |
---|
| 39 | |
---|
| 40 | CTYPE = repmat('L',K.l+K.f,1); % Standard variables |
---|
| 41 | CTYPE(1:K.f) = 'E'; % Equality constrained variables |
---|
| 42 | VARTYPE = repmat('C',size(A,2),1); |
---|
| 43 | VARTYPE(binary_variables) = 'B'; |
---|
| 44 | VARTYPE(integer_variables) = 'I'; |
---|
| 45 | |
---|
| 46 | options.cplexmex.msglev = options.verbose; |
---|
| 47 | if options.cplexmex.msglev>1 |
---|
| 48 | options.cplexmex.msglev = 1; |
---|
| 49 | end |
---|
| 50 | |
---|
| 51 | % Call mex-interface |
---|
| 52 | solvertime = clock; |
---|
| 53 | if options.savedebug |
---|
| 54 | save cplexmexdebug |
---|
| 55 | end |
---|
| 56 | |
---|
| 57 | [x,OPT,STATUS,EXTRA]= cplexmex(SENSE,H,C,A,B,CTYPE,LB,UB,VARTYPE,x0,options.cplexmex); |
---|
| 58 | solvertime = etime(clock,solvertime); |
---|
| 59 | problem = 0; |
---|
| 60 | |
---|
| 61 | D_struc = -EXTRA.lambda; |
---|
| 62 | |
---|
| 63 | % Check, currently not exhaustive... |
---|
| 64 | switch STATUS |
---|
| 65 | case {1,101,102} |
---|
| 66 | problem = 0; |
---|
| 67 | case {3,103} |
---|
| 68 | problem = 1; |
---|
| 69 | case {2,118} |
---|
| 70 | problem = 2; |
---|
| 71 | case {4,119} |
---|
| 72 | problem = 12; |
---|
| 73 | otherwise |
---|
| 74 | problem = -1; |
---|
| 75 | end |
---|
| 76 | infostr = yalmiperror(problem,'CPLEXMEX'); |
---|
| 77 | |
---|
| 78 | % Save all data sent to solver? |
---|
| 79 | if options.savesolverinput |
---|
| 80 | solverinput.SENSE = SENSE; |
---|
| 81 | solverinput.H = H; |
---|
| 82 | solverinput.A = A; |
---|
| 83 | solverinput.C = C; |
---|
| 84 | solverinput.B = B; |
---|
| 85 | solverinput.CTYPE = CTYPE; |
---|
| 86 | solverinput.LB = LB; |
---|
| 87 | solverinput.UB = UB; |
---|
| 88 | solverinput.VARTYPE = VARTYPE; |
---|
| 89 | solverinput.x0 = x0; |
---|
| 90 | solverinput.param = options.cplexmex; |
---|
| 91 | else |
---|
| 92 | solverinput = []; |
---|
| 93 | end |
---|
| 94 | |
---|
| 95 | % Save all data from the solver? |
---|
| 96 | if options.savesolveroutput |
---|
| 97 | solveroutput.X = x; |
---|
| 98 | solveroutput.OPT = OPT; |
---|
| 99 | solveroutput.STATUS = STATUS; |
---|
| 100 | solveroutput.EXTRA = EXTRA; |
---|
| 101 | else |
---|
| 102 | solveroutput = []; |
---|
| 103 | end |
---|
| 104 | |
---|
| 105 | % Standard interface |
---|
| 106 | output.Primal = x; |
---|
| 107 | output.Dual = D_struc; |
---|
| 108 | output.Slack = []; |
---|
| 109 | output.problem = problem; |
---|
| 110 | output.infostr = infostr; |
---|
| 111 | output.solverinput = solverinput; |
---|
| 112 | output.solveroutput= solveroutput; |
---|
| 113 | output.solvertime = solvertime; |
---|