1 | function output = callcplexint(interfacedata) |
---|
2 | |
---|
3 | % Author Johan Löfberg |
---|
4 | % $Id: callcplexint.m,v 1.19 2006/07/13 14:48:55 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 CPLEXINT',options.showprogress); |
---|
19 | |
---|
20 | SENSE = 1; |
---|
21 | C = full(c); |
---|
22 | if K.l+K.f+K.q == 0 |
---|
23 | A = zeros(1,length(c));A(1)=1; |
---|
24 | B = 1e6; |
---|
25 | % A = []; |
---|
26 | % b = []; |
---|
27 | else |
---|
28 | A =-(F_struc(1:K.f+K.l,2:end)); |
---|
29 | B = full(F_struc(1:K.f+K.l,1)); |
---|
30 | end |
---|
31 | |
---|
32 | INDEQ = []; |
---|
33 | if K.f>0 |
---|
34 | INDEQ(1:K.f) = 1:K.f; |
---|
35 | end |
---|
36 | |
---|
37 | if K.q(1)>0 |
---|
38 | top = K.f+K.l + 1; |
---|
39 | for i = 1:length(K.q) |
---|
40 | % [cx+d;Ax+b] |Ax+b|<cx+d, originally a QCQP |
---|
41 | m = K.q(i); |
---|
42 | ci = F_struc(top,2:end)'; |
---|
43 | di = F_struc(top,1); |
---|
44 | Ai = F_struc(top+1:top+m-1,2:end); |
---|
45 | bi = F_struc(top+1:top+m-1,1); |
---|
46 | QC(i).Q = full(Ai'*Ai - ci*ci'); |
---|
47 | QC(i).r = full(di'*di - bi'*bi); |
---|
48 | QC(i).L = full(2*bi'*Ai - 2*di*ci'); |
---|
49 | top = top+m; |
---|
50 | end |
---|
51 | else |
---|
52 | QC = []; |
---|
53 | end |
---|
54 | |
---|
55 | VARTYPE = repmat('C',size(A,2),1); |
---|
56 | VARTYPE(integer_variables)='I'; % Integer variables |
---|
57 | VARTYPE(binary_variables) ='B'; % Binary variables |
---|
58 | |
---|
59 | if nnz(Q)==0 |
---|
60 | H = []; |
---|
61 | else |
---|
62 | H = full(2*Q); |
---|
63 | end |
---|
64 | |
---|
65 | PARAM = options.cplex.param; |
---|
66 | OPTIONS.verbose = options.verbose; |
---|
67 | OPTIONS.logfile = options.cplex.logfile; |
---|
68 | if ~isempty(x0) |
---|
69 | OPTIONS.x0 = [(1:length(x0))' x0(:)]; |
---|
70 | end |
---|
71 | |
---|
72 | if options.savedebug |
---|
73 | save cplexintdebug H C A B LB UB QC VARTYPE INDEQ PARAM OPTIONS |
---|
74 | end |
---|
75 | |
---|
76 | % Call mex-interface |
---|
77 | solvertime = clock; |
---|
78 | [x,FMIN,SOLSTAT,DETAILS] = cplexint(H, C, A, B, INDEQ, QC, LB, UB,VARTYPE,PARAM,OPTIONS); |
---|
79 | if interfacedata.getsolvertime solvertime = etime(clock,solvertime);else solvertime = 0;end |
---|
80 | problem = 0; |
---|
81 | D_struc = -DETAILS.dual; |
---|
82 | |
---|
83 | switch SOLSTAT |
---|
84 | case {1,101,102} |
---|
85 | problem = 0; |
---|
86 | case {3,22} |
---|
87 | problem = 1; |
---|
88 | case 108 |
---|
89 | problem = 3; |
---|
90 | case {2} |
---|
91 | problem = 2; |
---|
92 | case {4,119} |
---|
93 | problem = 12; |
---|
94 | otherwise |
---|
95 | problem = -1; |
---|
96 | end |
---|
97 | infostr = yalmiperror(problem,'CPLEXINT'); |
---|
98 | |
---|
99 | % Save all data sent to solver? |
---|
100 | if options.savesolverinput |
---|
101 | solverinput.H = H; |
---|
102 | solverinput.A = A; |
---|
103 | solverinput.C = C; |
---|
104 | solverinput.INDEQ = INDEQ; |
---|
105 | solverinput.QC = QC; |
---|
106 | solverinput.B = B; |
---|
107 | solverinput.CTYPE = CTYPE; |
---|
108 | solverinput.LB = LB; |
---|
109 | solverinput.UB = UB; |
---|
110 | else |
---|
111 | solverinput = []; |
---|
112 | end |
---|
113 | |
---|
114 | % Save all data from the solver? |
---|
115 | if options.savesolveroutput |
---|
116 | solveroutput.x = x; |
---|
117 | solveroutput.FMIN = FMIN; |
---|
118 | solveroutput.SOLSTAT = SOLSTAT; |
---|
119 | solveroutput.DETAILS=DETAILS; |
---|
120 | else |
---|
121 | solveroutput = []; |
---|
122 | end |
---|
123 | |
---|
124 | |
---|
125 | % Standard interface |
---|
126 | output.Primal = x; |
---|
127 | output.Dual = D_struc; |
---|
128 | output.Slack = []; |
---|
129 | output.problem = problem; |
---|
130 | output.infostr = infostr; |
---|
131 | output.solverinput = solverinput; |
---|
132 | output.solveroutput= solveroutput; |
---|
133 | output.solvertime = solvertime; |
---|