source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/solvers/calllindo_geo.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 7.6 KB
Line 
1function output = calllindo_nlp(interfacedata)
2
3global MY_LICENSE_FILE
4
5persistent iEnv
6
7% Instead of calling lindo, we define the parameters we need. This is
8% needed to speed up repeated calls
9%lindo
10LSERR_NO_ERROR                                               = 0000;
11LS_IPARAM_NLP_PRINTLEVEL                                     = 203;
12LS_IPARAM_NLP_SOLVER                                         = 201;
13LS_IPARAM_NLP_MAXLOCALSEARCH                                 = 221;
14LS_STATUS_OPTIMAL                                            = 1;
15LS_STATUS_BASIC_OPTIMAL                                      = 2;
16LS_STATUS_INFEASIBLE                                         = 3;
17LS_STATUS_UNBOUNDED                                          = 4;
18LS_STATUS_FEASIBLE                                           = 5;
19LS_STATUS_INFORUNB                                           = 6;
20LS_STATUS_NEAR_OPTIMAL                                       = 7;
21LS_STATUS_LOCAL_OPTIMAL                                      = 8;
22LS_STATUS_LOCAL_INFEASIBLE                                   = 9;
23LS_STATUS_CUTOFF                                             = 10;
24LS_STATUS_NUMERICAL_ERROR                                    = 11;
25LS_STATUS_UNKNOWN                                            = 12;
26LS_STATUS_UNLOADED                                           = 13;
27LS_STATUS_LOADED                                             = 14;
28LS_METHOD_FREE                                               = 0;
29LS_METHOD_PSIMPLEX                                           = 1;
30LS_METHOD_DSIMPLEX                                           = 2;
31LS_METHOD_BARRIER                                            = 3;
32LS_METHOD_NLP                                                = 4;
33LS_NMETHOD_FREE                                              = 4;
34LS_NMETHOD_CONOPT                                            = 7;
35LS_NMETHOD_MSW_GRG                                           = 9;
36
37if isempty(iEnv)
38    % This call is mighty slow, so we do it only once, unless uses clears
39    % everything
40    [MY_LICENSE_KEY,Err] = mxlindo('LSloadLicenseString',MY_LICENSE_FILE);
41    [iEnv,nErr]=mxlindo('LScreateEnv',MY_LICENSE_KEY);
42    if nErr ~= LSERR_NO_ERROR;output = returnempty(-5); return; end;
43end
44
45% Retrieve needed data
46options = interfacedata.options;
47F_struc = interfacedata.F_struc;
48c       = interfacedata.c;
49K       = interfacedata.K;
50x0      = interfacedata.x0;
51Q       = interfacedata.Q;
52lb      = interfacedata.lb;
53ub      = interfacedata.ub;
54monomtable = interfacedata.monomtable;
55
56% Do some pre-calc to be used in callbacks
57nonlinearindicies = find(interfacedata.variabletype~=0);
58nonlinearindicies = unionstripped(nonlinearindicies,interfacedata.evalVariables);
59linearindicies    = find(interfacedata.variabletype==0);
60linearindicies    = setdiff1D(linearindicies,nonlinearindicies);
61interfacedata.nonlinearindicies = nonlinearindicies;
62interfacedata.linearindicies    = linearindicies;
63
64% Init model size
65m  = K.l + K.f;
66n  = length(c);
67
68% Specifying variable types...
69vtype = repmat('C',1,length(c(linearindicies)));
70vtype(interfacedata.integer_variables) = 'I';
71
72oshift = interfacedata.f;
73
74if m == 0
75    interfacedata.F_struc = [1e6 -ones(1,length(c))];
76    K.l = 1;
77    F_struc = [1e6 -ones(1,length(c))];
78    m = 1;
79    csense = [repmat('E',1,K.f) repmat('L',1,K.l)];
80end
81
82[Nbegcol,Nlencol,Nrowndx] = lindosparse(ones(m,length(linearindicies)));
83oJacobian = ones(length(linearindicies),1);
84Nobjndx = find(oJacobian) - 1;
85Nobjcnt = length(Nobjndx);
86if  isempty(Nobjndx)
87    Nobjndx = [];
88end
89
90%[Nbegcol,Nlencol,Nrowndx,Nobjcnt,Nobjndx,Apatt] = jacSparsityGeometric(interfacedata);
91% A = -F_struc(:,1+linearindicies);
92% b = full(F_struc(:,1));
93csense = [repmat('E',1,K.f) repmat('L',1,K.l)];
94% A = A.*(~Apatt);
95% b(any(Apatt,2)) = 0;
96
97[iModel,nErr]=mxlindo('LScreateModel',iEnv);
98if nErr ~= LSERR_NO_ERROR;output = returnempty(11); return; end;
99
100% SETUP data for callbacks
101mt      = interfacedata.monomtable;
102linear_variables = find((sum(abs(mt),2)==1) & (any(mt==1,2)));
103nonlinear_variables = setdiff((1:size(mt,1))',linear_variables);
104sigmonial_variables = find(any(0>mt,2) | any(mt-fix(mt),2));
105extended_variables = interfacedata.extended_variables;
106
107[prob,problem] = yalmip2geometric(options,F_struc,c,Q,K,ub,lb,mt,linear_variables,extended_variables);         
108prob.interfacedata = interfacedata;
109if problem   
110    output = createoutput([],[],[],problem,'LINDO',[],[],0);
111    return
112end
113lindo_fungp([],[],[],[],[],[],prob);
114
115[nErr] = mxlindo('LSsetFuncalc', iModel, 'lindo_fungp',prob);
116if nErr ~= LSERR_NO_ERROR;output = returnempty(11); return; end;
117
118[nErr] = mxlindo('LSsetModelIntParameter', iModel, LS_IPARAM_NLP_PRINTLEVEL, options.verbose+1);
119if nErr ~= LSERR_NO_ERROR;output = returnempty(11); return; end;
120
121% Set NLP solver
122[nErr] = mxlindo('LSsetModelIntParameter', iModel, LS_IPARAM_NLP_SOLVER, eval(options.lindo.LS_IPARAM_NLP_SOLVER));
123[nErr] = mxlindo('LSsetModelIntParameter', iModel, LS_IPARAM_NLP_MAXLOCALSEARCH,options.lindo.LS_IPARAM_NLP_MAXLOCALSEARCH);
124
125% Load the LP portion of  model
126if ~isempty(lb)
127    lb = lb(linear_variables);
128    ind = find(lb<1e-2);
129    lb(ind) = exp(log(1e-2)+(lb(ind)-1e-2)/1e-2);
130    lb = log(lb+sqrt(eps));
131end
132if ~isempty(ub)
133    ub = ub(linear_variables);
134    ind = find(ub<1e-2);
135    ub(ind) = exp(log(1e-2)+(ub(ind)-1e-2)/1e-2);
136    ub = log(ub+sqrt(eps));
137end
138b = zeros(m,1);
139A = spalloc(m,length(linearindicies),0);
140[nErr] = mxlindo('LSXloadLPData', iModel, 1, 0, zeros(length(linearindicies),1),b, csense,A, lb, ub);
141if nErr ~= LSERR_NO_ERROR;output = createoutput(11); return; end;
142
143nErr = mxlindo('LSloadVarType',iModel,vtype);
144if nErr ~= LSERR_NO_ERROR;output = createoutput(11); return; end;
145
146% Load the NLP portion of the model
147[nErr] = mxlindo('LSloadNLPData', iModel, Nbegcol, Nlencol,[], Nrowndx, Nobjcnt,Nobjndx,[]);
148if nErr ~= LSERR_NO_ERROR;output = createoutput(11); return; end;
149
150% Optimize model
151solvertime = clock;
152
153if isempty(interfacedata.integer_variables)
154    solver = 2;
155else
156    solver = 1;
157end
158solvertime = clock;
159switch solver
160    case 1
161        [solstat,nErr] = mxlindo('LSsolveMIP', iModel);
162        if ~ismember(solstat,[2009 LS_STATUS_INFEASIBLE])
163            [x,nErr] = mxlindo('LSgetMIPPrimalSolution',iModel);
164        else
165            x = zeros(length(linearindicies),1);
166        end
167    case 2
168        [solstat,nErr] = mxlindo('LSoptimize', iModel, eval(options.lindo.LS_METHOD));
169        if ~ismember(solstat,[2009 LS_STATUS_INFEASIBLE])
170            [x,nErr] = mxlindo('LSgetPrimalSolution',iModel);
171        else
172            x = zeros(length(linearindicies),1);
173        end
174    case 3
175        [solStatus,nErr] = mxlindo('LSsolveGOP', iModel);
176        [x,nErr] = mxlindo('LSgetPrimalSolution',iModel);
177    otherwise
178end
179if interfacedata.getsolvertime solvertime = etime(clock,solvertime);else solvertime = 0;end
180
181w = zeros(length(c),1);w(linearindicies) = exp(x);
182y = [];
183
184%[nErr]=mxlindo('LSdeleteEnv',iEnv);
185[nErr]=mxlindo('LSdeleteModel',iModel);
186
187switch solstat
188    case {LS_STATUS_OPTIMAL,LS_STATUS_BASIC_OPTIMAL,7,8}
189        problem = 0;
190    case {LS_STATUS_INFEASIBLE}
191        problem = 1;
192    case {LS_STATUS_UNBOUNDED}
193        problem = 2;
194    otherwise
195        problem = 11;
196end
197infostr = yalmiperror(problem,'LINDO-QP');
198
199% Save all data sent to solver?
200if options.savesolverinput
201    solverinput.solstat = solstat;
202    solverinput.nErr = nErr;
203    solverinput.x = x;
204else
205    solverinput = [];
206end
207
208% Save all data from the solver?
209if options.savesolveroutput
210    solveroutput.x = x;
211    solveroutput.fmin = fmin;
212    solveroutput.flag = flag;
213    solveroutput.output=output;
214    solveroutput.lambda=lambda;
215else
216    solveroutput = [];
217end
218
219% Standard interface
220output = createoutput(w,y,[],problem,'LINDO',solverinput,solveroutput,solvertime);
Note: See TracBrowser for help on using the repository browser.