1 | function output = calllindo(interfacedata) |
---|
2 | |
---|
3 | % Author Johan Löfberg |
---|
4 | % $Id: calllindo.m,v 1.6 2006/08/18 11:37:13 joloef Exp $ |
---|
5 | |
---|
6 | switch interfacedata.solver.tag |
---|
7 | |
---|
8 | case {'lindo-NLP'} |
---|
9 | output = calllindo_nlp(interfacedata); |
---|
10 | case {'lindo-MIQP'} |
---|
11 | output = calllindo_miqp(interfacedata); |
---|
12 | otherwise |
---|
13 | error; |
---|
14 | end |
---|
15 | |
---|
16 | % function output = calllindo_nlp(interfacedata) |
---|
17 | % |
---|
18 | % |
---|
19 | % global MY_LICENSE_FILE |
---|
20 | % lindo |
---|
21 | % |
---|
22 | % % Retrieve needed data |
---|
23 | % options = interfacedata.options; |
---|
24 | % F_struc = interfacedata.F_struc; |
---|
25 | % c = interfacedata.c; |
---|
26 | % K = interfacedata.K; |
---|
27 | % x0 = interfacedata.x0; |
---|
28 | % Q = interfacedata.Q; |
---|
29 | % lb = interfacedata.lb; |
---|
30 | % ub = interfacedata.ub; |
---|
31 | % monomtable = interfacedata.monomtable; |
---|
32 | % |
---|
33 | % lindo; |
---|
34 | % |
---|
35 | % nonlinearindicies = find(interfacedata.variabletype~=0); |
---|
36 | % linearindicies = find(interfacedata.variabletype==0); |
---|
37 | % nonlinearindicies = union(nonlinearindicies,interfacedata.evalVariables); |
---|
38 | % linearindicies = setdiff(linearindicies,interfacedata.evalVariables); |
---|
39 | % interfacedata.nonlinearindicies = nonlinearindicies; |
---|
40 | % interfacedata.linearindicies = linearindicies; |
---|
41 | % linear = find(interfacedata.variabletype == 0); |
---|
42 | % variabletype = interfacedata.variabletype; |
---|
43 | % |
---|
44 | % % Init model size |
---|
45 | % m = K.l + K.f; |
---|
46 | % n = length(c); |
---|
47 | % csense = [repmat('E',1,K.f) repmat('L',1,K.l)]; |
---|
48 | % |
---|
49 | % % Specifying variable types... |
---|
50 | % vtype = repmat('C',1,length(c(linear))); |
---|
51 | % vtype(interfacedata.integer_variables) = 'I'; |
---|
52 | % |
---|
53 | % oshift = interfacedata.f; |
---|
54 | % if m>0 |
---|
55 | % A = -F_struc(:,1+linear); |
---|
56 | % b = full(F_struc(:,1)); |
---|
57 | % [Nbegcol,Nlencol,Nrowndx,Nobjcnt,Nobjndx,Apatt] = jacSparsity(interfacedata); |
---|
58 | % A = A.*(~Apatt); |
---|
59 | % else |
---|
60 | % A = []; |
---|
61 | % b = []; |
---|
62 | % end |
---|
63 | % |
---|
64 | % [MY_LICENSE_KEY,nErr] = mxlindo('LSloadLicenseString',MY_LICENSE_FILE); |
---|
65 | % [iEnv,nErr]=mxlindo('LScreateEnv',MY_LICENSE_KEY); |
---|
66 | % if nErr ~= LSERR_NO_ERROR;output = returnempty(-5); return; end; |
---|
67 | % [iModel,nErr]=mxlindo('LScreateModel',iEnv); |
---|
68 | % if nErr ~= LSERR_NO_ERROR;output = returnempty(11); return; end; |
---|
69 | % constant_data = setup_fmincon_params(interfacedata); |
---|
70 | % constant_data.F_struc = F_struc; |
---|
71 | % lindo_fun([],[],[],[],[],[],constant_data); |
---|
72 | % [nErr] = mxlindo('LSsetFuncalc', iModel, 'lindo_fun',constant_data); |
---|
73 | % if nErr ~= LSERR_NO_ERROR;output = returnempty(11); return; end; |
---|
74 | % [nErr] = mxlindo('LSsetModelIntParameter', iModel, LS_IPARAM_NLP_PRINTLEVEL, options.verbose); |
---|
75 | % if nErr ~= LSERR_NO_ERROR;output = returnempty(11); return; end; |
---|
76 | % |
---|
77 | % % Set NLP solver |
---|
78 | % [nErr] = mxlindo('LSsetModelIntParameter', iModel, LS_IPARAM_NLP_SOLVER, LS_NMETHOD_MSW_GRG); |
---|
79 | % [nErr] = mxlindo('LSsetModelIntParameter', iModel, LS_IPARAM_NLP_MAXLOCALSEARCH, 2); |
---|
80 | % |
---|
81 | % % Load the LP portion of model |
---|
82 | % [nErr] = mxlindo('LSXloadLPData', iModel, 1, 0, c(linear), b, csense,sparse(A), lb(linear), ub(linear)); |
---|
83 | % if nErr ~= LSERR_NO_ERROR;output = returnempty(11); return; end; |
---|
84 | % |
---|
85 | % nErr = mxlindo('LSloadVarType',iModel,vtype); |
---|
86 | % if nErr ~= LSERR_NO_ERROR;output = returnempty(11); return; end; |
---|
87 | % |
---|
88 | % % Load the NLP portion of the model |
---|
89 | % [nErr] = mxlindo('LSloadNLPData', iModel, Nbegcol, Nlencol,[], Nrowndx, Nobjcnt,Nobjndx,[]); |
---|
90 | % if nErr ~= LSERR_NO_ERROR;output = returnempty(11); return; end; |
---|
91 | % |
---|
92 | % % Optimize model |
---|
93 | % solvertime = clock; |
---|
94 | % |
---|
95 | % solver = 2; |
---|
96 | % solvertime = clock; |
---|
97 | % switch solver%interfacedata.solver.tag |
---|
98 | % case 1 |
---|
99 | % [solstat,nErr] = mxlindo('LSsolveMIP', iModel); |
---|
100 | % [x,nErr] = mxlindo('LSgetMIPPrimalSolution',iModel); |
---|
101 | % case 2 |
---|
102 | % [solstat,nErr] = mxlindo('LSoptimize', iModel,LS_METHOD_FREE); |
---|
103 | % [x,nErr] = mxlindo('LSgetPrimalSolution',iModel); |
---|
104 | % case 3 |
---|
105 | % [solStatus,nErr] = mxlindo('LSsolveGOP', iModel); |
---|
106 | % [x,nErr] = mxlindo('LSgetPrimalSolution',iModel); |
---|
107 | % otherwise |
---|
108 | % end |
---|
109 | % solstat |
---|
110 | % if interfacedata.getsolvertime solvertime = etime(clock,solvertime);else solvertime = 0;end |
---|
111 | % |
---|
112 | % w = zeros(length(c),1);w(linear) =x; |
---|
113 | % y = []; |
---|
114 | % |
---|
115 | % [nErr]=mxlindo('LSdeleteEnv',iEnv); |
---|
116 | % |
---|
117 | % switch solstat |
---|
118 | % case {LS_STATUS_OPTIMAL,LS_STATUS_BASIC_OPTIMAL,7,8} |
---|
119 | % problem = 0; |
---|
120 | % case {LS_STATUS_INFEASIBLE} |
---|
121 | % problem = 1; |
---|
122 | % case {LS_STATUS_UNBOUNDED} |
---|
123 | % problem = 2; |
---|
124 | % otherwise |
---|
125 | % problem = 11; |
---|
126 | % end |
---|
127 | % infostr = yalmiperror(problem,'LINDO-QP'); |
---|
128 | % |
---|
129 | % % Save all data sent to solver? |
---|
130 | % if options.savesolverinput |
---|
131 | % solverinput.A = A; |
---|
132 | % solverinput.b = b; |
---|
133 | % solverinput.c = c; |
---|
134 | % solverinput.beq = beq; |
---|
135 | % solverinput.options = options.fmincon; |
---|
136 | % else |
---|
137 | % solverinput = []; |
---|
138 | % end |
---|
139 | % |
---|
140 | % % Save all data from the solver? |
---|
141 | % if options.savesolveroutput |
---|
142 | % solveroutput.x = x; |
---|
143 | % solveroutput.fmin = fmin; |
---|
144 | % solveroutput.flag = flag; |
---|
145 | % solveroutput.output=output; |
---|
146 | % solveroutput.lambda=lambda; |
---|
147 | % else |
---|
148 | % solveroutput = []; |
---|
149 | % end |
---|
150 | % |
---|
151 | % % Standard interface |
---|
152 | % output.Primal = w; |
---|
153 | % output.Dual = y; |
---|
154 | % output.Slack = []; |
---|
155 | % output.problem = problem; |
---|
156 | % output.infostr = infostr; |
---|
157 | % output.solverinput = solverinput; |
---|
158 | % output.solveroutput= solveroutput; |
---|
159 | % output.solvertime = solvertime; |
---|
160 | % |
---|
161 | % |
---|
162 | % |
---|
163 | % |
---|
164 | % |
---|
165 | % |
---|
166 | % |
---|
167 | % function [Nbegcol,Nlencol,Nrowndx,Nobjcnt,Nobjndx,cJacobian] = jacSparsity(interfacedata) |
---|
168 | % |
---|
169 | % linear = find(interfacedata.variabletype == 0); |
---|
170 | % oJacobian = zeros(length(linear),1); |
---|
171 | % variabletype = interfacedata.variabletype; |
---|
172 | % c = interfacedata.c; |
---|
173 | % F_struc = interfacedata.F_struc; |
---|
174 | % m = size(interfacedata.F_struc,1); |
---|
175 | % |
---|
176 | % for i = 1:length(c) |
---|
177 | % if c(i) |
---|
178 | % if variabletype(i) |
---|
179 | % variables = find(interfacedata.monomtable(i,:)); |
---|
180 | % oJacobian(variables) = 1; |
---|
181 | % end |
---|
182 | % end |
---|
183 | % end |
---|
184 | % cJacobian = zeros(m,length(linear)); |
---|
185 | % for i = 1:size(F_struc,2)-1 |
---|
186 | % for j = 1:size(F_struc,1) |
---|
187 | % if F_struc(j,i+1) |
---|
188 | % if variabletype(i) |
---|
189 | % variables = find(interfacedata.monomtable(i,:)); |
---|
190 | % cJacobian(j,variables) = 1; |
---|
191 | % end |
---|
192 | % end |
---|
193 | % end |
---|
194 | % end |
---|
195 | % oJacobian = double(oJacobian | any(interfacedata.Q(linear,linear),2)); |
---|
196 | % |
---|
197 | % Nbegcol = []; |
---|
198 | % Nrowndx = []; |
---|
199 | % Nlencol = []; |
---|
200 | % top = 0; |
---|
201 | % for i = 1:size(cJacobian,2) |
---|
202 | % [ii,jj,kk] = find(cJacobian(:,i)); |
---|
203 | % if isempty(ii) |
---|
204 | % Nbegcol = [Nbegcol top]; |
---|
205 | % Nlencol = [Nlencol 0]; |
---|
206 | % else |
---|
207 | % Nbegcol = [Nbegcol top]; |
---|
208 | % Nrowndx = [Nrowndx ii(:)'-1]; |
---|
209 | % Nlencol = [Nlencol length(ii)]; |
---|
210 | % top = top + length(ii); |
---|
211 | % end |
---|
212 | % end |
---|
213 | % if isempty(Nrowndx) |
---|
214 | % Nrowndx = []; |
---|
215 | % end |
---|
216 | % |
---|
217 | % Nobjndx = find(oJacobian) - 1; |
---|
218 | % Nobjcnt = length(Nobjndx); |
---|
219 | % if isempty(Nobjndx) |
---|
220 | % Nobjndx = []; |
---|
221 | % end |
---|
222 | % |
---|
223 | % |
---|
224 | % function output = returnempty(problem) |
---|
225 | % output.Primal = []; |
---|
226 | % output.Dual = []; |
---|
227 | % output.Slack = []; |
---|
228 | % output.problem = problem; |
---|
229 | % output.infostr = yalmiperror(problem,'LINDO'); |
---|
230 | % output.solverinput = []; |
---|
231 | % output.solveroutput= []; |
---|
232 | % output.solvertime = 0; |
---|
233 | % |
---|
234 | % |
---|