[37] | 1 | function output = callmexpress(interfacedata) |
---|
| 2 | |
---|
| 3 | % Author Johan Löfberg |
---|
| 4 | % $Id: callmexpress11.m,v 1.1 2006/08/07 11:31:25 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 | UB = interfacedata.ub; |
---|
| 16 | LB = interfacedata.lb; |
---|
| 17 | |
---|
| 18 | showprogress('Calling XPRESS',options.showprogress); |
---|
| 19 | |
---|
| 20 | SENSE = 1; |
---|
| 21 | C = full(c); |
---|
| 22 | if isempty(F_struc) |
---|
| 23 | A = zeros(1,length(c));A(1)=1; |
---|
| 24 | B = 1e6; |
---|
| 25 | else |
---|
| 26 | A =-(F_struc(:,2:end)); |
---|
| 27 | B = full(F_struc(:,1)); |
---|
| 28 | end |
---|
| 29 | |
---|
| 30 | % XPRESS complains about large bounds |
---|
| 31 | if isempty(LB) |
---|
| 32 | % LB = repmat(-2147483647,length(c),1); |
---|
| 33 | else |
---|
| 34 | LB(LB<-2147483647) = -2147483647; |
---|
| 35 | end |
---|
| 36 | if isempty(UB) |
---|
| 37 | % UB = repmat(2147483647,length(c),1); |
---|
| 38 | else |
---|
| 39 | UB(UB>2147483647) = 2147483647; |
---|
| 40 | end |
---|
| 41 | |
---|
| 42 | CTYPE = repmat('L',K.l+K.f,1); % Inequalities |
---|
| 43 | CTYPE(1:K.f) = 'E'; % Equality constraints |
---|
| 44 | VARTYPE = repmat('C',size(A,2),1); |
---|
| 45 | VARTYPE(integer_variables)='I'; % Integer variables |
---|
| 46 | VARTYPE(binary_variables) ='B'; % Binary variables |
---|
| 47 | |
---|
| 48 | if nnz(Q)==0 |
---|
| 49 | H = []; |
---|
| 50 | else |
---|
| 51 | H = full(2*Q); |
---|
| 52 | end |
---|
| 53 | |
---|
| 54 | if options.verbose==0 |
---|
| 55 | options.xpress.msglev = 0; |
---|
| 56 | else |
---|
| 57 | options.xpress.msglev = 1; |
---|
| 58 | end |
---|
| 59 | |
---|
| 60 | if options.savedebug |
---|
| 61 | save mexpressdebug SENSE H C A B CTYPE LB UB VARTYPE options |
---|
| 62 | end |
---|
| 63 | |
---|
| 64 | % Call mex-interface |
---|
| 65 | solvertime = clock; |
---|
| 66 | [x,FMIN,STATUS,EXTRA] = xpress(H,C,A,B,LB,UB,CTYPE,VARTYPE,SENSE,options.xpress); |
---|
| 67 | solvertime = etime(clock,solvertime); |
---|
| 68 | problem = 0; |
---|
| 69 | if isstruct(EXTRA) |
---|
| 70 | D_struc = -EXTRA.lambda; |
---|
| 71 | else |
---|
| 72 | D_struc = []; |
---|
| 73 | end |
---|
| 74 | |
---|
| 75 | % Check (error code depends on problem type!) |
---|
| 76 | if isempty(union(binary_variables,integer_variables)) |
---|
| 77 | switch STATUS |
---|
| 78 | case 1 |
---|
| 79 | problem = 0; |
---|
| 80 | case 2 |
---|
| 81 | problem = 1; |
---|
| 82 | case 5 |
---|
| 83 | problem = 2; |
---|
| 84 | case 4 |
---|
| 85 | problem = 3; |
---|
| 86 | case {0,3,6} |
---|
| 87 | problem = 11; |
---|
| 88 | otherwise |
---|
| 89 | problem = -1; |
---|
| 90 | end |
---|
| 91 | else |
---|
| 92 | switch STATUS |
---|
| 93 | case 6 |
---|
| 94 | problem = 0; |
---|
| 95 | case 5 |
---|
| 96 | problem = 1; |
---|
| 97 | case 4 |
---|
| 98 | problem = 2; |
---|
| 99 | case {4,3} |
---|
| 100 | problem = 3; |
---|
| 101 | case {0,1,2} |
---|
| 102 | problem = 11; |
---|
| 103 | otherwise |
---|
| 104 | problem = -1; |
---|
| 105 | end |
---|
| 106 | |
---|
| 107 | end |
---|
| 108 | infostr = yalmiperror(problem,'MEXPRESS'); |
---|
| 109 | |
---|
| 110 | % Save all data sent to solver? |
---|
| 111 | if options.savesolverinput |
---|
| 112 | solverinput.H = H; |
---|
| 113 | solverinput.A = A; |
---|
| 114 | solverinput.C = C; |
---|
| 115 | solverinput.B = B; |
---|
| 116 | solverinput.CTYPE = CTYPE; |
---|
| 117 | solverinput.LB = LB; |
---|
| 118 | solverinput.UB = UB; |
---|
| 119 | else |
---|
| 120 | solverinput = []; |
---|
| 121 | end |
---|
| 122 | |
---|
| 123 | % Save all data from the solver? |
---|
| 124 | if options.savesolveroutput |
---|
| 125 | solveroutput.x = x; |
---|
| 126 | solveroutput.FMIN = FMIN; |
---|
| 127 | solveroutput.STATUS = STATUS; |
---|
| 128 | solveroutput.EXTRA=EXTRA; |
---|
| 129 | else |
---|
| 130 | solveroutput = []; |
---|
| 131 | end |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | % Standard interface |
---|
| 135 | output.Primal = x; |
---|
| 136 | output.Dual = D_struc; |
---|
| 137 | output.Slack = []; |
---|
| 138 | output.problem = problem; |
---|
| 139 | output.infostr = infostr; |
---|
| 140 | output.solverinput = solverinput; |
---|
| 141 | output.solveroutput= solveroutput; |
---|
| 142 | output.solvertime = solvertime; |
---|