1 | function output = callmexpress(interfacedata) |
---|
2 | |
---|
3 | % Author Johan Löfberg |
---|
4 | % $Id: callmexpress.m,v 1.7 2005/05/07 13:53:20 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 | H = full(2*Q); |
---|
49 | if nnz(Q)==0 |
---|
50 | H = []; |
---|
51 | end |
---|
52 | |
---|
53 | if options.verbose==0 |
---|
54 | options.xpress.msglev = 0; |
---|
55 | else |
---|
56 | options.xpress.msglev = 1; |
---|
57 | end |
---|
58 | |
---|
59 | if options.savedebug |
---|
60 | save mexpressdebug SENSE H C A B CTYPE LB UB VARTYPE options |
---|
61 | end |
---|
62 | |
---|
63 | % Call mex-interface |
---|
64 | solvertime = clock; |
---|
65 | [x,FMIN,STATUS,EXTRA] = mexpress(SENSE,H,C,A,B,CTYPE,LB,UB,VARTYPE,options.xpress,0); |
---|
66 | solvertime = etime(clock,solvertime); |
---|
67 | problem = 0; |
---|
68 | if isstruct(EXTRA) |
---|
69 | D_struc = -EXTRA.lambda; |
---|
70 | else |
---|
71 | D_struc = []; |
---|
72 | end |
---|
73 | |
---|
74 | % Check (error code depends on problem type!) |
---|
75 | if isempty(union(binary_variables,integer_variables)) |
---|
76 | switch STATUS |
---|
77 | case 1 |
---|
78 | problem = 0; |
---|
79 | case 2 |
---|
80 | problem = 1; |
---|
81 | case 5 |
---|
82 | problem = 2; |
---|
83 | case 4 |
---|
84 | problem = 3; |
---|
85 | case {0,3,6} |
---|
86 | problem = 11; |
---|
87 | otherwise |
---|
88 | problem = -1; |
---|
89 | end |
---|
90 | else |
---|
91 | switch STATUS |
---|
92 | case 6 |
---|
93 | problem = 0; |
---|
94 | case 5 |
---|
95 | problem = 1; |
---|
96 | case 4 |
---|
97 | problem = 2; |
---|
98 | case {4,3} |
---|
99 | problem = 3; |
---|
100 | case {0,1,2} |
---|
101 | problem = 11; |
---|
102 | otherwise |
---|
103 | problem = -1; |
---|
104 | end |
---|
105 | |
---|
106 | end |
---|
107 | infostr = yalmiperror(problem,'MEXPRESS'); |
---|
108 | |
---|
109 | % Save all data sent to solver? |
---|
110 | if options.savesolverinput |
---|
111 | solverinput.H = H; |
---|
112 | solverinput.A = A; |
---|
113 | solverinput.C = C; |
---|
114 | solverinput.B = B; |
---|
115 | solverinput.CTYPE = CTYPE; |
---|
116 | solverinput.LB = LB; |
---|
117 | solverinput.UB = UB; |
---|
118 | else |
---|
119 | solverinput = []; |
---|
120 | end |
---|
121 | |
---|
122 | % Save all data from the solver? |
---|
123 | if options.savesolveroutput |
---|
124 | solveroutput.x = x; |
---|
125 | solveroutput.FMIN = FMIN; |
---|
126 | solveroutput.STATUS = STATUS; |
---|
127 | solveroutput.EXTRA=EXTRA; |
---|
128 | else |
---|
129 | solveroutput = []; |
---|
130 | end |
---|
131 | |
---|
132 | |
---|
133 | % Standard interface |
---|
134 | output.Primal = x; |
---|
135 | output.Dual = D_struc; |
---|
136 | output.Slack = []; |
---|
137 | output.problem = problem; |
---|
138 | output.infostr = infostr; |
---|
139 | output.solverinput = solverinput; |
---|
140 | output.solveroutput= solveroutput; |
---|
141 | output.solvertime = solvertime; |
---|