BonFilterSolver.cpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines Corporation, Carnegie Mellon University 2006, 2008
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Pierre Bonami, International Business Machines Corporation
7 //
8 // Date : 10/02/2006
9 
10 #include "BonminConfig.h"
11 
12 #include "BonFilterSolver.hpp"
13 #include "BonFilterWarmStart.hpp"
14 
15 #include <fstream>
16 
17 #include "CoinTime.hpp"
18 #include<algorithm>
21 
22 //#define InitializeAll
23 
24 
25 typedef long ftnlen;
26 extern "C"
27 {
28  void F77_FUNC(filtersqp,FILTERSQP)(
32  real *x, real *c, real *f, real *fmin, real *bl,
33  real *bu, real *s, real *a, fint *la, real *ws,
34  fint *lws, real *lam, char *cstype, real *user,
37 }
38 
39 //Static variables
40 static Ipopt::TNLP * tnlpSolved = NULL;
41 static fint nnz_h = -1;
42 
43 static fint * hStruct = NULL;
44 
45 //Permutation to apply to jacobian in order to get it row ordered
46 static int * permutationJac = NULL;
47 static int * permutationHess = NULL;
48 //static int * cache = NULL;
49 
50 
51 extern "C"
52 {
53 //Access to filter common bloc
54  /* common block for problemname */
55  extern struct {
57  char pname[10];
58  }
59  F77_FUNC(cpname,CPNAME);
60 
61  /* common block for Hessian storage set to 0, i.e. NO Hessian */
62  extern struct {
64  }
65  F77_FUNC(hessc,HESSC);
66 
67  /* common block for upper bound on filter */
68  extern struct {
70  }
71  F77_FUNC(ubdc,UBDC);
72 
73  /* common block for infinity & epslon */
74  extern struct {
76  }
77  F77_FUNC_(nlp_eps_inf,NLP_EPS_INF);
78 
79  /* common block for prfinting from QP solver */
80  extern struct {
82  }
83  F77_FUNC_(bqpd_count,BQPD_COUNT);
84 
85  /* common for scaling: scale_mode = 0 (none), 1 (variables), 2 (vars+cons) */
86  extern struct {
88  }
89  F77_FUNC(scalec,SCALEC);
90 }
91 
92 extern "C"
93 {
94 
96  void F77_FUNC(objfun,OBJFUN)(real *x, fint *n, real * f, real *user, fint * iuser, fint * errflag) {
97  (*errflag) = !tnlpSolved->eval_f(*n, x, 1, *f);
98  }
99 
101  void
102  F77_FUNC(confun,CONFUN)(real * x, fint * n , fint *m, real *c, real *a, fint * la, real * user, fint * iuser,
103  fint * errflag) {
104  (*errflag) = !tnlpSolved->eval_g(*n, x, 1, *m, c);
105  }
106 
107  void
108  F77_FUNC(gradient,GRADIENT)(fint *n, fint *m, fint * mxa, real * x, real *a, fint * la,
109  fint * maxa, real * user, fint * iuser, fint * errflag) {
110  (*errflag) = !tnlpSolved->eval_grad_f(*n, x, 1, a);
112  int nnz = la[0] - *n - 1;
113  double * values = new double [nnz];
114  (*errflag) = !tnlpSolved->eval_jac_g(*n, x, 1, *m, nnz, NULL, NULL, values) || (*errflag);
115  a+= *n;
116  for (int i = 0 ; i < nnz ; i++) {
117  int indice = permutationJac[i];
118  if (indice > nnz) {
119 #ifndef NDEBUG
120  std::cout<<"Error in gradient computation, i: "<<i
121  <<" in row order "<<permutationJac[i]<<std::endl;
122 #endif
123  }
124  *a++ = values[indice];
125  }
126  delete [] values;
127  }
128 
129  /* evaluation of the Hessian of the Lagrangian */
130  void
131  F77_FUNC(hessian,HESSIAN)(real *x, fint *n, fint *m, fint *phase, real *lam,
132  real *ws, fint *lws, real *user, fint *iuser,
134  Ipopt::Number obj_factor = (*phase == 1)? 0. : 1.;
135  fint end = nnz_h + (*n) + 2;
136 
137  for (int i = 0 ; i < end ; i++) {
138  lws[i] = hStruct[i];
139  }
140  *l_hess = nnz_h;
141  *li_hess = nnz_h + *n + 3;
142  Ipopt::Number * mlam = NULL;
143  if (*m > 0) {
144  mlam = new Ipopt::Number[*m];
145  }
146  for (int i = 0; i<*m; i++) {
147  mlam[i] = -lam[*n+i];
148  }
149  Ipopt::Number * values = new Ipopt::Number [nnz_h];
150  (*errflag) = !tnlpSolved->eval_h(*n, x, 1, obj_factor, *m, mlam ,1, hStruct[0] - 1, NULL, NULL, values);
151  delete [] mlam;
152  for (int i = 0 ; i < nnz_h ; i++) ws[i] = values[permutationHess[i]];
153  delete [] values;
154  }
155 
156 }
157 
158 namespace Bonmin
159 {
160 
161  struct Transposer
162  {
163  const Ipopt::Index* rowIndices;
164  const Ipopt::Index* colIndices;
165  bool operator()(int i, int j)
166  {
167  return rowIndices[i]<rowIndices[j] ||
168  (rowIndices[i]==rowIndices[j] && colIndices[i] < colIndices[j]);
169  }
170  };
171 
172  // Convert a sparse matrix from triplet format to row ordered packed matrix
173  void FilterSolver::TMat2RowPMat(bool symmetric, fint n, fint m, int nnz,
174  const Ipopt::Index* iRow,
175  const Ipopt::Index* iCol, int * permutation2,
176  fint * lws, int nnz_offset, int n_offset,
177  Ipopt::TNLP::IndexStyleEnum index_style)
178  {
179  for (int i = 0 ; i < nnz ; i++)
180  permutation2[i] = i;
181 
182  Transposer lt;
183  if (symmetric) {
184  Ipopt::Index* tmpRow = new Ipopt::Index[nnz];
185  Ipopt::Index* tmpCol = new Ipopt::Index[nnz];
186  for (int i=0; i<nnz; i++) {
187  const Ipopt::Index& irow = iRow[i];
188  const Ipopt::Index& jcol = iCol[i];
189  if (irow > jcol) {
190  tmpRow[i] = irow;
191  tmpCol[i] = jcol;
192  }
193  else {
194  tmpRow[i] = jcol;
195  tmpCol[i] = irow;
196  }
197  }
198  lt.rowIndices = tmpRow;
199  lt.colIndices = tmpCol;
200  }
201  else {
202  lt.rowIndices = iRow;
203  lt.colIndices = iCol;
204  }
205 
206  std::sort(permutation2, permutation2 + nnz, lt);
207 
208  const int idx_offset = (index_style == Ipopt::TNLP::C_STYLE);
209  fint row = 1-idx_offset;
210  lws[0] = nnz + nnz_offset + 1;
211  fint * inds = lws + nnz_offset + 1;
212  fint * start = inds + nnz + n_offset;
213  *start++ = 1 + nnz_offset;
214  for (fint i = 0 ; i < nnz ; i++) {
215  inds[i] = lt.colIndices[permutation2[i]] + idx_offset;
216  //DBG_ASSERT(RowJac[permutation2[i]] >= row);
217  if (lt.rowIndices[permutation2[i]] > row) {
218  for (;row < lt.rowIndices[permutation2[i]] ; row++)
219  *start++ = i + nnz_offset + 1;
220  }
221  }
222  for (;row <= m-idx_offset ; row++)
223  *start++ = nnz + nnz_offset +1;
224 
225 #if 0
226  for (int i = 0; i<nnz_offset+1; i++)
227  printf("lws[%3d] = %3d\n", i, lws[i]);
228  for (int i = nnz_offset+1; i<nnz_offset+nnz+1; i++)
229  printf("lws[%3d] = %3d [%3d,%3d]\n", i, lws[i], lt.rowIndices[permutation2[i-nnz_offset-1]], lt.colIndices[permutation2[i-nnz_offset-1]]);
230  for (int i = nnz_offset+nnz+1; i<lws[0]+m+2; i++)
231  printf("lws[%3d] = %3d\n", i, lws[i]);
232 #endif
233 
234  if (symmetric) {
235  delete [] lt.rowIndices;
236  delete [] lt.colIndices;
237  }
238 
239 
240  }
241 
242 
243 
244  std::string FilterSolver::solverName_ = "filter SQP";
245 
246  void
248  {
249  roptions->SetRegisteringCategory("FilterSQP options", RegisteredOptions::FilterCategory);
250  roptions->AddLowerBoundedNumberOption("eps", "Tolerance for SQP solver",
251  0., 1, 1e-08, "");
252  roptions->AddLowerBoundedNumberOption("infty", "A large number",0.,1, 1e20, "");
253  roptions->AddBoundedIntegerOption("iprint", "Print level (0=silent, 3=verbose)", 0,6,0);
254  roptions->AddLowerBoundedIntegerOption("kmax", "Dimension of null-space",
255  -1, -1, "");
256  roptions->AddLowerBoundedIntegerOption("maxf","Maximum filter length",0,100);
257  roptions->AddLowerBoundedIntegerOption("maxiter", "Maximum number of iterations",0,1000);
258  roptions->AddLowerBoundedIntegerOption("mlp","Maximum level for degeneracy (bqpd)",0, 1000);
259  roptions->AddLowerBoundedIntegerOption("mxlws", "FINTEGER workspace increment", 0, 500000);
260  roptions->AddLowerBoundedIntegerOption("mxws", "REAL workspace increment",
261  0,2000000);
262  roptions->AddLowerBoundedNumberOption("rho_init", "Initial trust region size",0,1,10.);
263  // roption->AddLowerBoundedIntegerOption("timing", "whether to time evaluations (1 = yes)");
264  roptions->AddLowerBoundedNumberOption("tt", "Parameter for upper bound on filter",0,1, 125e-2);
265  roptions->AddLowerBoundedNumberOption("ubd", "Parameter for upper bound on filter", 0 , 1,1e2);
266 
267  }
268 
269 
270  FilterSolver::FilterSolver(bool createEmpty /* = false */)
271  :
272  TNLPSolver(),
273  warmF_(NULL),
274  cached_(NULL)
275  {}
276 
280  const std::string & prefix):
281  TNLPSolver(roptions, options, journalist, prefix),
282  warmF_(NULL),
283  cached_(NULL)
284  {}
285 
289  TNLPSolver(roptions, options, journalist, "bonmin."),
290  warmF_(NULL),
291  cached_(NULL)
292  {}
293 
294 
296  TNLPSolver(other),
297  warmF_(NULL),
298  cached_(NULL)
299  {
300  warmF_ = (other.warmF_.IsValid()) ? dynamic_cast<FilterWarmStart *>(other.warmF_->clone()):NULL;
301  }
302 
305  {
306  Ipopt::SmartPtr<FilterSolver> retval = new FilterSolver(*this);
307  return GetRawPtr(retval);
308  }
309 
311  {}
312 
313  bool
314  FilterSolver::Initialize(std::string optFile)
315  {
316  std::ifstream is;
317  if (optFile != "") {
318  try {
319  is.open(optFile.c_str());
320  }
321  catch (std::bad_alloc) {
322  journalist_->Printf(Ipopt::J_SUMMARY, Ipopt::J_MAIN, "\nEXIT: Not enough memory.\n");
323  return false;
324  }
325  catch (...) {
326  Ipopt::IpoptException E("Unknown Exception caught in ipopt", "Unknown File", -1);
327  E.ReportException(*journalist_);
328  return false;
329  }
330  }
331  bool retval = Initialize(is);
332  if (is) {
333  is.close();
334  }
335  if(!options_->GetIntegerValue("print_level",default_log_level_,""))
336  default_log_level_ = 1;
337  return retval;
338  }
339 
340  bool
341  FilterSolver::Initialize(std::istream &is)
342  {
343 
344  Ipopt::Index ivalue;
345  options_->GetIntegerValue("print_level", ivalue, "");
346  Ipopt::EJournalLevel print_level = (Ipopt::EJournalLevel)ivalue;
347  Ipopt::SmartPtr<Ipopt::Journal> stdout_jrnl = journalist_->GetJournal("console");
348  if (IsValid(stdout_jrnl)) {
349  // Set printlevel for stdout
350  stdout_jrnl->SetAllPrintLevels(print_level);
351  stdout_jrnl->SetPrintLevel(Ipopt::J_DBG, Ipopt::J_NONE);
352  }
353 
354  if (is.good()) {
355  options_->ReadFromStream(*journalist_, is);
356  }
357  return true;
358  }
359 
363  {
364  if (cached_.IsNull() || !cached_->use_warm_start_in_cache_) {
365  cached_ = new cachedInfo(tnlp, options_);
366  }
367  cached_->load_ws(warmF_);
368  return callOptimizer();
369  }
370 
374  {
375  assert(tnlp == cached_->tnlp_);
376  cached_->load_ws(warmF_);
377  //rescan bounds which may have changed
378  assert(cached_->bounds);
379  int n = cached_->n;
380  int m = cached_->m;
381  tnlp->get_bounds_info(n, cached_->bounds, &cached_->bounds[n+m],
382  m, &cached_->bounds[n], &cached_->bounds[2*n + m]);
383 
384  tnlpSolved = static_cast<Ipopt::TNLP *>(Ipopt::GetRawPtr(tnlp));
385  nnz_h = cached_->nnz_h_;
386 
387  hStruct = cached_->hStruct_;
388 
389 //Permutation to apply to jacobian in order to get it row ordered
390  permutationJac = cached_->permutationJac_;
391  permutationHess = cached_->permutationHess_;
392 
393 
394  return callOptimizer();
395  }
396 
397 
398 
399  void
402  {
403  // 1) Get some dimensions
404  // 1.a) First from ampl
405  int nnz_jac_g;
406 
407  Ipopt::TNLP::IndexStyleEnum index_style;
408  Ipopt::Index nv, nc, nnz_j, nnz_hess;
409  tnlp->get_nlp_info( nv, nc,
410  nnz_j, (Ipopt::Index&) nnz_hess,
411  index_style);
412  n = nv;
413  m = nc;
414  nnz_jac_g = nnz_j;
415  nnz_h_ = nnz_hess;
416 
417  nnz_h = nnz_h_;
418 
419 
420  // 1.b) then from options
421  Ipopt::Index kmax_ipt;
422  options->GetIntegerValue("kmax", kmax_ipt, "filter.");
423  if (kmax_ipt == -1) {
424  kmax = n;
425  }
426  else {
427  kmax = kmax_ipt;
428  kmax = std::min(kmax,n);
429  }
430  Ipopt::Index mlp_ipt;
431  options->GetIntegerValue("mlp", mlp_ipt,"filter.");
432  mlp = mlp_ipt;
433 
434  Ipopt::Index maxf_ipt;
435  options->GetIntegerValue("maxf", maxf_ipt,"filter.");
436  maxf = maxf_ipt;
437 
438  fint mxwk0;
439  Ipopt::Index mxwk0_ipt;
440  options->GetIntegerValue("mxws", mxwk0_ipt, "filter.");
441  mxwk0 = mxwk0_ipt;
442 
443  fint mxiwk0;
444  Ipopt::Index mxiwk0_ipt;
445  options->GetIntegerValue("mxlws", mxiwk0_ipt, "filter.");
446  mxiwk0 = mxiwk0_ipt;
447  // Setup storage for Filter
448  int nplusm = n + m;
449  //Starting point
450  x = new real [n];
451 
452  //tnlp->get_starting_point(n, 1, x, 0, NULL, NULL, m, 0, NULL);
453  use_warm_start_in_cache_ = false;
454  //for(int i = 0 ; i < n ; i++) x[i] = 0;
455  lam = new real [n+m];
456  //#ifdef InitializeAll // This should be initialized
457  for (int i = 0 ; i < n+m ; i++) lam[i] = 0.;
458  //#endif
459  //bounds
460  bounds = new real [2*n + 2*m];
461 
462  tnlp->get_bounds_info(n, bounds, bounds + nplusm, m, bounds + n, bounds + n + nplusm);
463 
464 #if 0
465  double infty = F77_FUNC_(nlp_eps_inf,NLP_EPS_INF).infty;
466  // AW: I don't think we need this, it isn't done for ReOptimize either
467  for (int i = 0 ; i < nplusm ; i++) {
468  if (bounds[i] < -infty) bounds[i] = - infty;
469  }
470 
471  real * ubounds = bounds + nplusm;
472  for (int i = 0 ; i < nplusm ; i++) {
473  if (ubounds[i] > infty) ubounds[i] = infty;
474  }
475 #endif
476  maxa = n + nnz_jac_g;
477  fint maxia = n + nnz_jac_g + m + 3;
478  a = new real[maxa];
479  la = new fint [maxia];
480 
481  int * RowJac = new int [nnz_jac_g];
482  int * ColJac = new int [nnz_jac_g];
483 
484  la[nnz_jac_g + n + 1] = 1;
485 
486  for (fint i = 1; i <= n ; i++)
487  la[i] = i;// - (index_style == Ipopt::TNLP::C_STYLE);
488  tnlp->eval_jac_g( nv, NULL, 0, nc , nnz_j, RowJac, ColJac, NULL);
489 
490  permutationJac = permutationJac_ = new int [nnz_jac_g];
491  TMat2RowPMat(false, n, m, nnz_jac_g, RowJac, ColJac, permutationJac,
492  la, n, 1, index_style);
493 
494  delete [] RowJac;
495  delete [] ColJac;
496 
497  // Now setup hessian
499  hStruct_ = new fint[nnz_h + n + 3];
500  int * cache = new int[2*nnz_h + 1];
501  F77_FUNC(hessc,HESSC).phl = 1;
502  tnlp->eval_h((Ipopt::Index&) n, NULL, 0, 1., (Ipopt::Index&) m, NULL, 0, (Ipopt::Index&) nnz_h, cache + nnz_h, cache , NULL);
503 
504  TMat2RowPMat(true, n, n, nnz_h, cache, cache + nnz_h, permutationHess,
505  hStruct_, 0, 0, index_style);
506 
507  delete [] cache;
508  // work arrays
509  fint lh1 = nnz_h + 8 + 2 * n + m;
510  maxWk = 21*n + 8*m + mlp + 8*maxf + lh1 + kmax*(kmax+9)/2 + mxwk0;
511  maxiWk = 13*n + 4*m + mlp + lh1 + kmax + 113 + mxiwk0;
512 
513  ws = new real[maxWk];
514  lws = new fint[maxiWk];
515 #ifdef InitializeAll // ToDo: This shouldn't have to be initialized
516  for (int i = 0 ; i < maxWk ; i++) ws[i] = 0;
517  for (int i = 0 ; i < maxiWk ; i++) lws[i] = 0;
518 #endif
519 
520  // Setup global variables and static variables
521  hStruct = hStruct_;
522  tnlpSolved = static_cast<Ipopt::TNLP *>(Ipopt::GetRawPtr(tnlp));
523 
524  options->GetNumericValue("ubd",F77_FUNC(ubdc,UBDC).ubd, "filter.");
525  options->GetNumericValue("tt", F77_FUNC(ubdc,UBDC).tt, "filter.");
526  options->GetNumericValue("eps", F77_FUNC_(nlp_eps_inf,NLP_EPS_INF).eps, "filter.");
527  options->GetNumericValue("infty", F77_FUNC_(nlp_eps_inf,NLP_EPS_INF).infty, "filter.");
528  rho = 10.;
529  maxiter = 1000;
530  options->GetIntegerValue("maxiter", (Ipopt::Index &) maxiter, "filter.");
531  options->GetNumericValue("rho_init",rho,"filter.");
532 
533 
534  // Set up scaling
535  F77_FUNC(scalec,SCALEC).scale_mode = 0;
536  s = new real [n+m];
537 
538  istat = new fint[14];
539  rstat = new real[7];
540  //#ifdef InitializeAll ToDo: He will do that later
541  for (int i=0; i<14; i++) {
542  istat[0] = 43;
543  }
544  for (int i=0; i<7; i++) {
545  rstat[0] = 42.;
546  }
547  //#endif
548 
549  fmin = -1e100;
550  Ipopt::Index bufy;
551  options->GetIntegerValue("iprint",bufy, "filter.");
552  iprint = bufy;
553  nout = 6;
554  cstype = new char[m];
555  Ipopt::TNLP::LinearityType * const_types =
556  new Ipopt::TNLP::LinearityType[m];
557  tnlp->get_constraints_linearity(m, const_types);
558  for (int i = 0 ; i < m ; i++) {
559  if (const_types[i] == Ipopt::TNLP::LINEAR) {
560  cstype[i] = 'L';
561  }
562  else
563  cstype[i] = 'N';
564  }
565  delete [] const_types;
566  c = new double[m];
567  tnlp_ = Ipopt::GetRawPtr(tnlp);
568  }
569 
573  {
574  cached_->optimize();
575 
576  TNLPSolver::ReturnStatus optimizationStatus = TNLPSolver::exception;
577  Ipopt::SolverReturn status = Ipopt::INTERNAL_ERROR;
578  fint ifail = cached_->ifail;
579  switch (ifail) {
580  case 0:
581  optimizationStatus = TNLPSolver::solvedOptimal;
582  status = Ipopt::SUCCESS;
583  break;
584  case 1:
585  optimizationStatus = TNLPSolver::unbounded;
586  status = Ipopt::DIVERGING_ITERATES;
587  case 2:
588  case 3:
589  case 4:
590  optimizationStatus = TNLPSolver::provenInfeasible;
591  status = Ipopt::LOCAL_INFEASIBILITY;
592  break;
593  case 5:
594  case 6:
595  case 8:
596  optimizationStatus = TNLPSolver::iterationLimit;
597  status = Ipopt::MAXITER_EXCEEDED;
598  break;
599  case 7:
600  optimizationStatus = TNLPSolver::externalException;
601  status = Ipopt::INTERNAL_ERROR;
602  break;
603  case 9:
604  case 10:
605  optimizationStatus = TNLPSolver::exception;
606  status = Ipopt::INTERNAL_ERROR;
607  break;
608  }
609 
610  Ipopt::Number* mlam = NULL;
611  if (cached_->m>0) {
612  mlam = new Ipopt::Number[cached_->m];
613  }
614  for (int i = 0; i<cached_->m; i++) {
615  mlam[i] = -cached_->lam[cached_->n+i];
616  }
617  Ipopt::Number* z_L = new Ipopt::Number[cached_->n];
618  Ipopt::Number* z_U = new Ipopt::Number[cached_->n];
619  const int os = cached_->n+cached_->m;
620  for (int i=0; i<cached_->n; i++) {
621  if (cached_->x[i] == cached_->bounds[i]) {
622  z_L[i] = std::max(0.,cached_->lam[i]);
623  }
624  else {
625  z_L[i] = 0.;
626  }
627  if (cached_->x[i] == cached_->bounds[os+i]) {
628  z_U[i] = std::max(0.,-cached_->lam[i]);
629  }
630  else {
631  z_U[i] = 0.;
632  }
633  }
634  cached_->tnlp_->finalize_solution(status, cached_->n,
635  cached_->x, z_L, z_U,
636  cached_->m, cached_->c, mlam,
637  cached_->f, NULL, NULL);
638  delete [] mlam;
639  delete [] z_L;
640  delete [] z_U;
641  return optimizationStatus;
642  }
644  void
645  FilterSolver::cachedInfo::load_ws(Coin::SmartPtr<FilterWarmStart> warmF){
646  if(!warmF.IsValid()) return;
647  const fint xsize = warmF->primalSize();
648  const real* xarray = warmF->primal();
649  for (int i = 0; i<xsize; i++) {
650  x[i] = xarray[i];
651  }
652  CoinCopyN(warmF->dual(), warmF->dualSize(), lam);
653  CoinCopyN(warmF->lwsArray(), warmF->lwsSize(), lws);
654  for (int i = 0 ; i < 14 ; i ++) {
655  istat[i] = warmF->istat()[i];
656  }
657  use_warm_start_in_cache_ = true;
658  }
660  void
662  {
663  if (use_warm_start_in_cache_) {
664  ifail = -1;
665  use_warm_start_in_cache_ = false;
666  }
667  else {
668  tnlp_->get_starting_point(n, 1, x, 0, NULL, NULL, m, 0, NULL);
669  ifail = 0;
670  }
671  cpuTime_ = - CoinCpuTime();
672  fint cstype_len = 1;
673  rho = 10;
674  // rho = 1e6;
675  // printf("rho = %e\n", rho);
676 #if 0
677  printf("========= 3333333333333333 =============\n");
678  for (int i=0; i<n; i++) {
679  printf("xL[%3d] = %15.8e xU[%3d] = %15.8e\n", i, bounds[i], i, bounds[m+n+i]);
680  }
681  for (int i=0; i<m; i++) {
682  printf("gL[%3d] = %15.8e gU[%3d] = %15.8e\n", i, bounds[n+i], i, bounds[m+2*n+i]);
683  }
684 #endif
685 #if 0
686  for (int i=0; i<n; i++) {
687  printf("fxstart[%2d] = %23.16e\n", i, x[i]);
688  }
689 #endif
690  F77_FUNC(filtersqp,FILTERSQP)(&n, &m, &kmax, & maxa, &maxf, &mlp, &maxWk,
691  &maxiWk, &iprint, &nout, &ifail, &rho, x,
692  c, &f, &fmin, bounds,
693  bounds + n + m,
694  s, a, la,
695  ws, lws, lam, cstype,
696  NULL, NULL,
697  &maxiter, istat, rstat,
698  cstype_len);
699 #if 0
700  for (int i=0; i<n; i++) {
701  printf("fxsol[%2d] = %23.16e\n", i, x[i]);
702  }
703 #endif
704 #if 0
705  printf("final f = %e\n", f);
706  printf("ifail = %d\n", ifail);
707 #endif
708  if(ifail == 3){
709  f = rstat[4];
710  }
711 
712  cpuTime_ += CoinCpuTime();
713  }
714 
715  std::string
717  {"Internal error in Filter SQP."};
718 
719  std::string
721  "filterSqp";
722 
723  const std::string&
725  {
726  return errorNames_[0];
727  }
728 
729  const std::string&
731  {
732  return solverName_;
733  }
734 
735  bool
736  FilterSolver::setWarmStart(const CoinWarmStart * warm,
738  {
739  if (warm == NULL || cached_.IsNull()) {
740  cached_ = new cachedInfo(GetRawPtr(tnlp), options_);
741  }
742  if(warm == NULL) return 1;
743  const FilterWarmStart * warmF = dynamic_cast<const FilterWarmStart *> (warm);
744  assert(warmF);
745  if (warmF->empty())//reset initial point and leave
746  {
747  warmF_ = NULL;
749  return 1;
750  }
751  enableWarmStart();
752  warmF_ = dynamic_cast<FilterWarmStart *> (warmF->clone());
753  return true;
754  }
755 
756  CoinWarmStart *
758  {
759  return new FilterWarmStart(cached_->n, cached_->x,
760  cached_->n+cached_->m, cached_->lam,
761  cached_->maxiWk, cached_->lws, cached_->istat);
762  }
763 
764  CoinWarmStart *
766  {
767  return new FilterWarmStart;
768  }
769 
770 
772  bool
773  FilterSolver::warmStartIsValid(const CoinWarmStart * ws) const{
774  const FilterWarmStart* fws = dynamic_cast<const FilterWarmStart*>(ws);
775  if (fws && ! fws->empty()) {
776  return true;
777  }
778  return false;
779  }
780 
781 
782 }//end namespace Bonmin
virtual const std::string & errorName() const
Get the string corresponding to error.
void fint fint fint real real fint real fint fint * l_hess
double * values
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint * lws
Coin::SmartPtr< FilterWarmStart > warmF_
void fint fint fint * kmax
TNLPSolver::ReturnStatus callOptimizer()
Perform optimization using data structure in cache.
Ipopt::SmartPtr< Ipopt::Journalist > journalist_
Storage of Journalist for output.
void fint fint fint real fint * la
const Ipopt::Index * rowIndices
Bonmin::BqpdSolver F77_FUNC
fint n_bqpd_calls
void fint fint fint real * a
int default_log_level_
To record default log level.
Ipopt::Number * mlam
void fint fint * mxa
static std::string solverName_
bool IsValid(const OSSmartPtr< U > &smart_ptr)
Definition: OSSmartPtr.hpp:465
void fint fint fint real fint real real * bl
fint phe
This is a generic class for calling an NLP solver to solve a TNLP.
Bonmin::BqpdSolver::fint fint
real eps
fint irow
void optimize()
Optimize problem described by cache with filter.
void fint fint fint fint * maxf
void fint fint fint real fint real real real real real real real real real fint real fint fint * mlp
const Ipopt::Index * colIndices
void initialize(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp, Ipopt::SmartPtr< Ipopt::OptionsList > &options)
Fill data structures for filter with info from tnlp.
static char * j
Definition: OSdtoa.cpp:3622
void fint fint fint real fint real real real real * f
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real char * cstype
virtual bool Initialize(std::string params_file)
Initialize the TNLPSolver (read options from params_file)
void fint fint fint fint fint fint fint fint fint fint real * rho
void fint fint fint real fint real real real real real real real real real * e
long ftnlen
Bonmin::BqpdSolver::real real
fint phl
struct @16 F77_FUNC_(nlp_eps_inf, NLP_EPS_INF)
fint lt
virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)
Solves a problem expresses as a TNLP.
fint end
real ubd
virtual void enableWarmStart()
Solves a problem expresses as a TNLP.
void fint fint fint * phase
FilterSolver(bool createEmpty=false)
Default constructor.
Warm start for filter interface.
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real char real fint fint fint real ftnlen cstype_len
FilterTypes::real real
Fortran type for double.used in filter.
void fint fint fint real fint real real real real real * fmin
static void TMat2RowPMat(bool symmetric, fint n, fint m, int nnz, const Ipopt::Index *iRow, const Ipopt::Index *iCol, int *permutation2, fint *lws, int nnz_offset, int n_offset, Ipopt::TNLP::IndexStyleEnum index_style)
Converting TMatrices into row-ordered matrices.
real tt
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real * s
virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const
Get the warm start form the solver.
Cached information for reoptimizing.
virtual bool setWarmStart(const CoinWarmStart *warm, Ipopt::SmartPtr< TMINLP2TNLP > tnlp)
Set the warm start in the solver.
void load_ws(Coin::SmartPtr< FilterWarmStart >)
Load warm-start info into cache with filter.
virtual void disableWarmStart()
Solves a problem expresses as a TNLP.
Coin::SmartPtr< cachedInfo > cached_
Cached information on last problem optimized for reoptimization.
U * GetRawPtr(const OSSmartPtr< U > &smart_ptr)
Definition: OSSmartPtr.hpp:452
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real * ws
virtual Ipopt::SmartPtr< TNLPSolver > clone()
Virtual copy constructor.
fint phc
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real char real fint * iuser
ReturnStatus
Standard return statuses for a solver.
fint char_l
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real char real fint fint fint * istat
bool use_warm_start_in_cache_
flag remembering if warm start information has been put into cache
bool empty() const
Is this an empty warm start?
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real char real fint fint fint real * rstat
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint fint * ifail
bool operator()(int i, int j)
fint scale_mode
void fint fint fint fint fint fint * mxwk
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real * lam
static int * permutationHess
virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)
Resolves a problem expresses as a TNLP.
static fint nnz_h
void registerOptions()
Register this solver options into passed roptions.
virtual CoinWarmStart * clone() const
virtual copy
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real char real * user
void fint real real fint fint *errflag errflag
virtual CoinWarmStart * getEmptyWarmStart() const
Solves a problem expresses as a TNLP.
static char prefix[100]
Definition: BM_lp.cpp:26
virtual const std::string & solverName() const
Return the name of the solver.
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint fint fint fint fint * nout
static int * permutationJac
void fint * m
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real char real fint fint * maxiter
char pname[10]
int nnz
ATTENTION: Filter expect the jacobian to be ordered by row.
static fint * hStruct
fint phr
void fint fint fint real real fint real fint fint fint * li_hess
Ipopt::SmartPtr< Ipopt::OptionsList > options_
List of Options.
void fint * n
fint n_bqpd_prfint
static Ipopt::TNLP * tnlpSolved
real c
void fint fint fint fint fint fint fint * mxiwk
void fint fint fint * maxa
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint fint fint fint * iprint
real infty
void fint fint fint real fint real * x
virtual ~FilterSolver()
destructor
virtual bool warmStartIsValid(const CoinWarmStart *ws) const
Check that warm start object is valid.
void fint fint fint real fint real real real * bu
FilterTypes::fint fint
Fortran type for integer used in filter.