OSBonminSolver.cpp
Go to the documentation of this file.
1 /* $Id: OSBonminSolver.cpp 4940 2015-02-03 22:19:22Z Gassmann $ */
18 #include <iostream>
19 
20 #include "OSBonminSolver.h"
21 #include "OSGeneral.h"
22 #include "OSOutput.h"
23 #include "OSParameters.h"
24 #include "OSMathUtil.h"
25 #include "CoinFinite.hpp"
26 #include "CoinTime.hpp"
28 #include "BonTMINLP.hpp"
29 
30 using namespace Bonmin;
31 using namespace Ipopt;
32 
33 using std::endl;
34 using std::ostringstream;
35 
37 {
38  osrlwriter = new OSrLWriter();
39  osresult = new OSResult();
40  m_osilreader = NULL;
41  m_osolreader = NULL;
42  bonminErrorMsg = "";
43 }
44 
46 {
47 #ifndef NDEBUG
48  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_debug, "inside BonminSolver destructor\n");
49 #endif
50  if(m_osilreader != NULL) delete m_osilreader;
51  m_osilreader = NULL;
52  if(m_osolreader != NULL) delete m_osolreader;
53  m_osolreader = NULL;
54 
55  if(osrlwriter != NULL )delete osrlwriter;
56  osrlwriter = NULL;
57  if(osresult != NULL )
58  {
59  delete osresult;
60  osresult = NULL;
61  }
62 #ifndef NDEBUG
63  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_debug, "leaving BonminSolver destructor\n");
64 #endif
65 }
66 
67 
69 {
70  int i = 0;
71  char *varType;
72  varType = osinstance->getVariableTypes();
74  for(i = 0; i < n; i++)
75  {
76  if( varType[i] == 'B')
77  {
78  var_types[i] = BINARY;
79  }
80  else
81  {
82  if( varType[i] == 'I')
83  {
84  var_types[i] = INTEGER;
85  }
86  else
87  {
88  if( varType[i] == 'C')
89  {
90  var_types[i] = CONTINUOUS;
91  }
92  else
93  {
94  throw ErrorClass("variable type not yet implemented");
95  }
96  }
97  }
98  }
99  return true;
100 }
101 
102 
103 bool BonminProblem::get_variables_linearity(Index n, Ipopt::TNLP::LinearityType* var_types)
104 {
105  std::ostringstream outStr;
106  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_info, "Initialize Nonlinear Structures\n");
107  try
108  {
110  }
111  catch(const ErrorClass& eclass)
112  {
113  bonminErrorMsg = eclass.errormsg;
114  throw;
115  }
121  std::map<int, int> varIndexMap;
122  std::map<int, int>::iterator posVarIndexMap;
124  /* first make all continuous */
125 
126  int i;
127 
128  for(i = 0; i < n; i++)
129  {
130  var_types[ i] = Ipopt::TNLP::LINEAR;
131  }
136  outStr.str("");
137  outStr.clear();
138  for(posVarIndexMap = varIndexMap.begin(); posVarIndexMap != varIndexMap.end(); ++posVarIndexMap)
139  {
140  outStr << "Variable Index = " << posVarIndexMap->first << std::endl ;
141  var_types[ posVarIndexMap->first] = Ipopt::TNLP::NON_LINEAR;
142  }
143  outStr << "Number of nonlinear variables = " << varIndexMap.size() << std::endl;
145 
146  return true;
147 }
148 
149 bool BonminProblem::get_constraints_linearity(Index m, Ipopt::TNLP::LinearityType* const_types)
150 {
151  std::ostringstream outStr;
152  int i;
153 
154  for(i = 0; i < m; i++)
155  {
156  const_types[ i] = Ipopt::TNLP::LINEAR;
157  }
158 
160 
161  outStr.str("");
162  outStr.clear();
163  for(i = 0; i < mm; i++)
164  {
166  {
167  outStr << osinstance->getNonlinearExpressionTreeModIndexes()[ i] << std::endl;
168  const_types[ osinstance->getNonlinearExpressionTreeModIndexes()[ i] ] = Ipopt::TNLP::NON_LINEAR;
169  }
170  }
172 
173  return true;
174 }
175 
176 // returns the size of the problem
177 bool BonminProblem::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
178  Index& nnz_h_lag, TNLP::IndexStyleEnum& index_style)
179 {
180  std::ostringstream outStr;
181  //if(osinstance->getObjectiveNumber() <= 0) throw ErrorClass("Bonmin NEEDS AN OBJECTIVE FUNCTION");
182  // number of variables
184  // number of constraints
186 #ifndef NDEBUG
187  outStr.str("");
188  outStr.clear();
189  outStr << "Bonmin number variables !!!!!!!!!!!!!!!!!!!!!!!!!!!" << n << endl;
190  outStr << "Bonmin number constraints !!!!!!!!!!!!!!!!!!!!!!!!!!!" << m << endl;
192 #endif
193  try
194  {
196  }
197  catch(const ErrorClass& eclass)
198  {
199  bonminErrorMsg = eclass.errormsg;
200  throw;
201  }
202  // use the OS Expression tree for function evaluations instead of CppAD
204  SparseJacobianMatrix *sparseJacobian = NULL;
205  try
206  {
207  sparseJacobian = osinstance->getJacobianSparsityPattern();
208  }
209  catch(const ErrorClass& eclass)
210  {
211  bonminErrorMsg = eclass.errormsg;
212  throw;
213  }
214  nnz_jac_g = sparseJacobian->valueSize;
215 #ifndef NDEBUG
216  outStr.str("");
217  outStr.clear();
218  outStr << "nnz_jac_g !!!!!!!!!!!!!!!!!!!!!!!!!!!" << nnz_jac_g << endl;
220 #endif
221  // nonzeros in upper hessian
222 
224  {
225  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_warning, "This is a linear program\n");
226  nnz_h_lag = 0;
227  }
228  else
229  {
231  nnz_h_lag = sparseHessian->hessDimension;
232  }
233 #ifndef NDEBUG
234  outStr.str("");
235  outStr.clear();
236  outStr << "nnz_h_lag !!!!!!!!!!!!!!!!!!!!!!!!!!!" << nnz_h_lag << endl;
238 #endif
239  // use the C style indexing (0-based)
240  index_style = TNLP::C_STYLE;
241 
242  return true;
243 }//get_nlp_info
244 
245 
246 bool BonminProblem::get_bounds_info(Index n, Number* x_l, Number* x_u,
247  Index m, Number* g_l, Number* g_u)
248 {
249  std::ostringstream outStr;
250  int i;
251 
252  double * mdVarLB = osinstance->getVariableLowerBounds();
253  // variables upper bounds
254  double * mdVarUB = osinstance->getVariableUpperBounds();
255 
256  for(i = 0; i < n; i++)
257  {
258  x_l[ i] = mdVarLB[ i];
259  x_u[ i] = mdVarUB[ i];
260 #ifndef NDEBUG
261  outStr.str("");
262  outStr.clear();
263  outStr << "x_l !!!!!!!!!!!!!!!!!!!!!!!!!!!" << x_l[i] << endl;
264  outStr << "x_u !!!!!!!!!!!!!!!!!!!!!!!!!!!" << x_u[i] << endl;
266 #endif
267  }
268  // Bonmin interprets any number greater than nlp_upper_bound_inf as
269  // infinity. The default value of nlp_upper_bound_inf and nlp_lower_bound_inf
270  // is 1e19 and can be changed through bonmin options.
271  // e.g. g_u[0] = 2e19;
272 
273  //constraint lower bounds
274  double * mdConLB = osinstance->getConstraintLowerBounds();
275  //constraint upper bounds
276  double * mdConUB = osinstance->getConstraintUpperBounds();
277 
278  for(int i = 0; i < m; i++)
279  {
280  g_l[ i] = mdConLB[ i];
281  g_u[ i] = mdConUB[ i];
282 #ifndef NDEBUG
283  outStr.str("");
284  outStr.clear();
285  outStr << "lower !!!!!!!!!!!!!!!!!!!!!!!!!!!" << g_l[i] << endl;
286  outStr << "upper !!!!!!!!!!!!!!!!!!!!!!!!!!!" << g_u[i] << endl;
288 #endif
289  }
290  return true;
291 }//get_bounds_info
292 
293 
294 // returns the initial point for the problem
295 bool BonminProblem::get_starting_point(Index n, bool init_x, Number* x,
296  bool init_z, Number* z_L, Number* z_U, Index m, bool init_lambda,
297  Number* lambda)
298 {
299  std::ostringstream outStr;
300  // Here, we assume we only have starting values for x, if you code
301  // your own NLP, you can provide starting values for the dual variables
302  // if you wish
303  assert(init_x == true);
304  assert(init_z == false);
305  assert(init_lambda == false);
306  int i, m1, n1;
307 
308 
309 #ifndef NDEBUG
311  "get initial values !!!!!!!!!!!!!!!!!!!!!!!!!!\n");
312 #endif
313 
314  //now set initial values
315 #ifndef NDEBUG
317  "get number of initial values !!!!!!!!!!!!!!!!!!!!!!!!!!\n");
318 #endif
319  int k;
320  if (osoption != NULL)
322  else
323  m1 = 0;
324 #ifndef NDEBUG
325  outStr.str("");
326  outStr.clear();
327  outStr << "number of variables initialed: " << m1 << endl;
329 #endif
330 
332  bool* initialed;
333  initialed = new bool[n1];
334 #ifndef NDEBUG
335  outStr.str("");
336  outStr.clear();
337  outStr << "number of variables in total: " << n1 << endl;
339 #endif
340 
341 
342  for(k = 0; k < n1; k++)
343  initialed[k] = false;
344 
345  if (m1 > 0)
346  {
347 #ifndef NDEBUG
348  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_debug, "get initial values\n");
349 #endif
350 
351  InitVarValue** initVarVector = osoption->getInitVarValuesSparse();
352 #ifndef NDEBUG
354 #endif
355 
356  double initval;
357  try
358  {
359  for(k = 0; k < m1; k++)
360  {
361  i = initVarVector[k]->idx;
362  if (initVarVector[k]->idx > n1)
363  throw ErrorClass ("Illegal index value in variable initialization");
364 
365  initval = initVarVector[k]->value;
367  {
368  if (osinstance->instanceData->variables->var[i]->lb > initval)
369  throw ErrorClass ("Initial value outside of bounds");
370  }
371  else if (osinstance->instanceData->variables->var[i]->lb == -OSDBL_MAX)
372  {
373  if (osinstance->instanceData->variables->var[i]->ub < initval)
374  throw ErrorClass ("Initial value outside of bounds");
375  }
376  else
377  {
378  if ((osinstance->instanceData->variables->var[i]->lb > initval) ||
379  (osinstance->instanceData->variables->var[i]->ub < initval))
380  throw ErrorClass ("Initial value outside of bounds");
381  }
382 
383  x[initVarVector[k]->idx] = initval;
384  initialed[initVarVector[k]->idx] = true;
385  }
386  }
387  catch(const ErrorClass& eclass)
388  {
390  "Error in BonminProblem::get_starting_point (OSBonminSolver.cpp)\n\n\n");
391  }
392  } // end if (m1 > 0)
393 
394  double default_initval;
395  default_initval = 1.7171;
396 
397 
398  for(k = 0; k < n1; k++)
399  {
400  if (!initialed[k])
401  {
403  if (osinstance->instanceData->variables->var[k]->lb <= default_initval)
404  x[k] = default_initval;
405  else
407  else if (osinstance->instanceData->variables->var[k]->lb == -OSDBL_MAX)
408  if (osinstance->instanceData->variables->var[k]->ub >= default_initval)
409  x[k] = default_initval;
410  else
412  else if ((osinstance->instanceData->variables->var[k]->lb <= default_initval) &&
413  (osinstance->instanceData->variables->var[k]->ub >= default_initval))
414  x[k] = default_initval;
415  else if (osinstance->instanceData->variables->var[k]->lb > default_initval)
417  else
419  }
420  }
421 
422 #ifndef NDEBUG
423  outStr.str("");
424  outStr.clear();
425  for(i = 0; i < n1; i++)
426  {
427  outStr << "INITIAL VALUE !!!!!!!!!!!!!!!!!!!! " << x[ i] << std::endl;
428  }
430 #endif
431 
433  delete[] initialed;
434  return true;
435 }//get_starting_point
436 
437 
438 // returns the value of the objective function
439 bool BonminProblem::eval_f(Index n, const Number* x, bool new_x, Number& obj_value)
440 {
441 
442  try
443  {
444  if(osinstance->getObjectiveNumber() > 0)
445  {
446  if( osinstance->instanceData->objectives->obj[ 0]->maxOrMin.compare("min") == 0)
447  {
448  obj_value = osinstance->calculateAllObjectiveFunctionValues( const_cast<double*>(x), NULL, NULL, new_x, 0 )[ 0];
449  }
450  else // we have a max
451  {
452  obj_value = -osinstance->calculateAllObjectiveFunctionValues( const_cast<double*>(x), NULL, NULL, new_x, 0 )[ 0];
453  }
454  }
455  }
456  catch(const ErrorClass& eclass)
457  {
458  bonminErrorMsg = eclass.errormsg;
459  throw;
460  }
461  if( CoinIsnan( (double)obj_value) ) return false;
462  return true;
463 }
464 
465 bool BonminProblem::eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f)
466 {
467  int i;
468  double *objGrad = NULL;
469  if(osinstance->getObjectiveNumber() > 0)
470  {
471  try
472  {
473  // we assume we are doing the objective function indexed by -1
474  objGrad = osinstance->calculateObjectiveFunctionGradient( const_cast<double*>(x), NULL, NULL, -1, new_x, 1);
475  }
476  catch(const ErrorClass& eclass)
477  {
478  bonminErrorMsg = eclass.errormsg;
479  throw;
480  }
481 
482  for(i = 0; i < n; i++)
483  {
484  if( osinstance->instanceData->objectives->obj[ 0]->maxOrMin.compare("min") == 0)
485  {
486  grad_f[ i] = objGrad[ i];
487  }
488  else
489  {
490  grad_f[ i] = -objGrad[ i];
491  }
492  }
493  }
494  return true;
495 }//eval_grad_f
496 
497 // return the value of the constraints: g(x)
498 bool BonminProblem::eval_g(Index n, const Number* x, bool new_x, Index m, Number* g)
499 {
500  try
501  {
502  double *conVals = osinstance->calculateAllConstraintFunctionValues( const_cast<double*>(x), NULL, NULL, new_x, 0 );
503  int i;
504  for(i = 0; i < m; i++)
505  {
506  if( CoinIsnan( (double)conVals[ i] ) ) return false;
507  g[i] = conVals[ i] ;
508  }
509  return true;
510  }
511  catch(const ErrorClass& eclass)
512  {
513  bonminErrorMsg = eclass.errormsg;
514  throw;
515  }
516 }//eval_g
517 
518 
519 // return the structure or values of the jacobian
520 bool BonminProblem::eval_jac_g(Index n, const Number* x, bool new_x,
521  Index m, Index nele_jac, Index* iRow, Index *jCol,
522  Number* values)
523 {
524  SparseJacobianMatrix *sparseJacobian;
525  if (values == NULL)
526  {
527  // return the structure of the jacobian
528  try
529  {
530  sparseJacobian = osinstance->getJacobianSparsityPattern();
531  }
532  catch(const ErrorClass& eclass)
533  {
534  bonminErrorMsg = eclass.errormsg;
535  throw;
536  }
537  int i = 0;
538  int k, idx;
539  for(idx = 0; idx < m; idx++)
540  {
541  for(k = *(sparseJacobian->starts + idx); k < *(sparseJacobian->starts + idx + 1); k++)
542  {
543  iRow[i] = idx;
544  jCol[i] = *(sparseJacobian->indexes + k);
545  i++;
546  }
547  }
548  }
549  else
550  {
551  try
552  {
553  sparseJacobian = osinstance->calculateAllConstraintFunctionGradients( const_cast<double*>(x), NULL, NULL, new_x, 1);
554  }
555  catch(const ErrorClass& eclass)
556  {
557  bonminErrorMsg = eclass.errormsg;
558  throw;
559  }
560  //osinstance->getIterateResults( (double*)x, 0.0, NULL, -1, new_x, 1);
561  for(int i = 0; i < nele_jac; i++)
562  {
563  values[ i] = sparseJacobian->values[i];
564  //values[ i] = osinstance->m_mdJacValue[ i];
565  }
566  }
567  return true;
568 }//eval_jac_g
569 
570 //return the structure or values of the hessian
571 bool BonminProblem::eval_h(Index n, const Number* x, bool new_x,
572  Number obj_factor, Index m, const Number* lambda,
573  bool new_lambda, Index nele_hess, Index* iRow,
574  Index* jCol, Number* values)
575 {
576 
577  SparseHessianMatrix *sparseHessian;
578 
579  int i;
580  if (values == NULL)
581  {
582  // return the structure. This is a symmetric matrix, fill the lower left triangle only.
583  try
584  {
586  }
587  catch(const ErrorClass& eclass)
588  {
589  bonminErrorMsg = eclass.errormsg;
590  throw;
591  }
592  for(i = 0; i < nele_hess; i++)
593  {
594  iRow[i] = *(sparseHessian->hessColIdx + i);
595  jCol[i] = *(sparseHessian->hessRowIdx + i);
596  }
597  }
598  else
599  {
600  // return the values. This is a symmetric matrix, fill the lower left triangle only
601  double* objMultipliers = new double[1];
602  objMultipliers[0] = obj_factor;
603  try
604  {
605  sparseHessian = osinstance->calculateLagrangianHessian( const_cast<double*>(x), objMultipliers, const_cast<double*>(lambda) , new_x, 2);
606  delete[] objMultipliers;
607  }
608  catch(const ErrorClass& eclass)
609  {
610  bonminErrorMsg = eclass.errormsg;
611  delete[] objMultipliers;
612  throw;
613  }
614  for(i = 0; i < nele_hess; i++)
615  {
616  values[ i] = *(sparseHessian->hessValues + i);
617  }
618  }
620  return true;
621 }//eval_h
622 
623 bool BonminProblem::get_scaling_parameters(Number& obj_scaling,
624  bool& use_x_scaling, Index n,
625  Number* x_scaling,
626  bool& use_g_scaling, Index m,
627  Number* g_scaling)
628 {
629  /*
630  * Bonmin assumes problems cast as a min
631  * if( osinstance->instanceData->objectives->obj[ 0]->maxOrMin.compare("min") != 0){
632  obj_scaling = -1;
633  }
634  else obj_scaling = 1;
635  use_x_scaling = false;
636  use_g_scaling = false;
637  */
638  return true;
639 }//get_scaling_parameters
640 
641 
642 
643 
645  Index n, const Number* x, Number obj_value)
646 {
647  std::ostringstream outStr;
648 
649  status = status_;
650 #ifndef NDEBUG
651  outStr.str("");
652  outStr.clear();
653  outStr << "FINALIZE OBJ SOLUTION VALUE = " << obj_value << std::endl;
655 #endif
656 
657 }
658 
659 
661 {
662  try
663  {
664  if(osil.length() == 0 && osinstance == NULL) throw ErrorClass("there is no instance");
665  if(osinstance == NULL)
666  {
667  m_osilreader = new OSiLReader();
668  osinstance = m_osilreader->readOSiL( osil);
669  }
670 
671  // Can't handle multiobjective problems properly --- especially nonlinear ones
672  if (osinstance->getObjectiveNumber() > 1)
673  throw ErrorClass("Solver cannot handle multiple objectives --- please delete all but one");
674 
675  // Create a new instance of your nlp
676  tminlp = new BonminProblem( osinstance, osoption);
677  this->bCallbuildSolverInstance = true;
678  //Now initialize from tminlp
679  //bonminSetup.initialize( GetRawPtr(tminlp) );
680  }
681  catch(const ErrorClass& eclass)
682  {
683  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_error, "THERE IS AN ERROR\n");
685  osresult->setGeneralStatusType( "error");
686  osrl = osrlwriter->writeOSrL( osresult);
687  throw ErrorClass( osrl) ;
688  }
689 }//end buildSolverInstance()
690 
691 
692 
694 {
695  std::ostringstream outStr;
696  try
697  {
698  this->bSetSolverOptions = true;
699  bonminSetup.initializeOptionsAndJournalist();
700  //Register an additional option -- just an example
701  bonminSetup.roptions()->AddStringOption2("print_solution","Do we print the solution or not?",
702  "yes",
703  "no", "No, we don't.",
704  "yes", "Yes, we do.",
705  "A longer comment can be put here");
706 
707  // Here we can change the default value of some Bonmin or Ipopt option
708  bonminSetup.options()->SetNumericValue("bonmin.time_limit", 5000); //changes bonmin's time limit
709  //bonminSetup.options()->SetIntegerValue("bonmin.num_resolve_at_node", 3);
710  //bonminSetup.options()->SetIntegerValue("bonmin.num_resolve_at_root", 3);
711  //bonminSetup.options()->SetIntegerValue("bonmin.num_retry_unsolved_random_point", 30);
712  //bonminSetup.options()->SetIntegerValue("print_level", 12);
713  //bonminSetup.options()->SetIntegerValue("bonmin.bb_log_level", 4);
714  //bonminSetup.options()->SetStringValue("bonmin.nlp_failure_behavior", "fathom");
715  //bonminSetup.options()->SetNumericValue("bonmin.allowable_gap", -1);
716  //bonminSetup.options()->SetNumericValue("bonmin.allowable_fraction_gap", -.1);
717  //bonminSetup.options()->SetNumericValue("bonmin.cutoff_decr", -1);
718  //bonminSetup.options()->SetStringValue("mu_oracle","loqo");
719 
720 
721  //Here we read several option files
722  //bonminSetup.readOptionsFile("Mybonmin.opt");
723  //bonminSetup.readOptionsFile();// This reads the default file "bonmin.opt"
724 
725  // Options can also be set by using a string with a format similar to the bonmin.opt file
726  bonminSetup.readOptionsString("bonmin.algorithm B-BB\n");
727 
728  //turn off a lot of output -- this can be overridden by using OSOptions
729  bonminSetup.options()->SetIntegerValue("bonmin.bb_log_level", 0 );
730  bonminSetup.options()->SetIntegerValue("bonmin.nlp_log_level", 0 );
731 
732  // Now we can obtain the value of the new option
733  int printSolution;
734  bonminSetup.options()->GetEnumValue("print_solution", printSolution,"");
735  if(printSolution == 1)
736  {
737  tminlp->printSolutionAtEndOfAlgorithm();
738  }
739  //
740  if(osoption == NULL && osol.length() > 0)
741  {
742  m_osolreader = new OSoLReader();
743  osoption = m_osolreader->readOSoL( osol);
744  }
745 
746  if(osoption != NULL && osoption->getNumberOfSolverOptions() > 0 )
747  {
748  char *pEnd;
749  int i;
750  std::vector<SolverOption*> optionsVector;
751  optionsVector = osoption->getSolverOptions( "bonmin",true);
752  int num_bonmin_options = optionsVector.size();
753  for(i = 0; i < num_bonmin_options; i++)
754  {
755  if(optionsVector[ i]->type == "numeric" )
756  {
757  outStr.str("");
758  outStr.clear();
759  outStr << "FOUND A NUMERIC OPTION "
760  << os_strtod( optionsVector[ i]->value.c_str(), &pEnd )
761  << std::endl;
763  if(optionsVector[ i]->category == "ipopt")
764  {
765  bonminSetup.options()->SetNumericValue(optionsVector[ i]->name, os_strtod( optionsVector[ i]->value.c_str(), &pEnd ) );
766  }
767  else
768  {
769  if(optionsVector[ i]->category == "cbc" )
770  {
771  bonminSetup.options()->SetNumericValue("milp_solver."+optionsVector[ i]->name, os_strtod( optionsVector[ i]->value.c_str(), &pEnd ) );
772  }
773  else
774  {
775  bonminSetup.options()->SetNumericValue("bonmin."+optionsVector[ i]->name, os_strtod( optionsVector[ i]->value.c_str(), &pEnd ) );
776  }
777  }
778  }
779  else if(optionsVector[ i]->type == "integer" )
780  {
781  outStr.str("");
782  outStr.clear();
783  outStr << "FOUND AN INTEGER OPTION " << optionsVector[ i]->name << std::endl;
785  if(optionsVector[ i]->category == "ipopt")
786  {
787  bonminSetup.options()->SetIntegerValue(optionsVector[ i]->name, atoi( optionsVector[ i]->value.c_str() ) );
788  }
789  else
790  {
791  if(optionsVector[ i]->category == "cbc" )
792  {
794  "SETTING INTEGER CBC OPTION\n");
795  bonminSetup.options()->SetIntegerValue("milp_solver."+optionsVector[ i]->name, atoi( optionsVector[ i]->value.c_str() ));
796  }
797  else
798  {
799  bonminSetup.options()->SetIntegerValue("bonmin."+optionsVector[ i]->name, atoi( optionsVector[ i]->value.c_str() ) );
800  }
801  }
802  }
803  else if(optionsVector[ i]->type == "string" )
804  {
805  outStr.str("");
806  outStr.clear();
807  outStr << "FOUND A STRING OPTION " << optionsVector[ i]->name << std::endl;
809  if(optionsVector[ i]->category == "ipopt")
810  {
811  bonminSetup.options()->SetStringValue(optionsVector[ i]->name, optionsVector[ i]->value );
812  }
813  else
814  {
815  if(optionsVector[ i]->category == "cbc" )
816  {
817  bonminSetup.options()->SetStringValue("milp_solver."+optionsVector[ i]->name, optionsVector[ i]->value);
818  }
819  else
820  {
821  bonminSetup.options()->SetStringValue("bonmin."+optionsVector[ i]->name, optionsVector[ i]->value);
822  }
823  }
824  }
825  }
826  }
827  }
828 
829  catch(const ErrorClass& eclass)
830  {
831  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_error, "THERE IS AN ERROR\n");
833  osresult->setGeneralStatusType( "error");
834  osrl = osrlwriter->writeOSrL( osresult);
835  throw ErrorClass( osrl) ;
836  }
837 }//end setSolverOptions()
838 
839 
840 //void BonminSolver::solve() throw (ErrorClass) {
842 {
843  if( this->bCallbuildSolverInstance == false) buildSolverInstance();
844  if( this->bSetSolverOptions == false) setSolverOptions();
845  try
846  {
847  try
848  {
849  bonminSetup.initialize( GetRawPtr(tminlp) );
850  // bb is a Bonmin BonCbc object;;
851  bb( bonminSetup); //process parameter file using Ipopt and do branch and bound using Cbc
852  }
853  catch(TNLPSolver::UnsolvedError *E)
854  {
855  //There has been a failure to solve a problem with Ipopt.
856  osresult->setGeneralMessage("Ipopt has failed to solve a problem");
857  osresult->setGeneralStatusType( "error");
858  osrl = osrlwriter->writeOSrL( osresult);
859  throw ErrorClass( osrl) ;
860  }
862  {
863  ostringstream outStr;
864  outStr << E.className() << "::"<< E.methodName() << std::endl << E.message() << std::endl;
865 
866  osresult->setGeneralMessage(outStr.str());
867  osresult->setGeneralStatusType( "error");
868  osrl = osrlwriter->writeOSrL( osresult);
869  throw ErrorClass( osrl) ;
870  }
871  catch(CoinError &E)
872  {
873  ostringstream outStr;
874  outStr << E.className() << "::"<< E.methodName() << std::endl << E.message() << std::endl;
875 
876  osresult->setGeneralMessage(outStr.str());
877  osresult->setGeneralStatusType( "error");
878  osrl = osrlwriter->writeOSrL( osresult);
879  throw ErrorClass( osrl);
880  }
881 
882  if(( bb.model().isContinuousUnbounded() == true) && (osinstance->getNumberOfIntegerVariables() + osinstance->getNumberOfBinaryVariables() <= 0) )
883  {
884  std::string solutionDescription = "";
885  std::string message = "Success";
886  int solIdx = 0;
887 
888  if(osresult->setServiceName( "Bonmin solver service") != true)
889  throw ErrorClass("OSResult error: setServiceName");
891  throw ErrorClass("OSResult error: setInstanceName");
893  throw ErrorClass("OSResult error: setVariableNumber");
894  if(osresult->setObjectiveNumber( 1) != true)
895  throw ErrorClass("OSResult error: setObjectiveNumber");
897  throw ErrorClass("OSResult error: setConstraintNumber");
898  if(osresult->setSolutionNumber( 1) != true)
899  throw ErrorClass("OSResult error: setSolutionNumer");
900  if(osresult->setGeneralMessage( message) != true)
901  throw ErrorClass("OSResult error: setGeneralMessage");
902  solutionDescription = "The problem is unbounded";
903  osresult->setSolutionStatus(solIdx, "error", solutionDescription);
904  osresult->setGeneralStatusType("normal");
905  if( osinstance->getVariableNumber() == 0) osresult->setSolutionMessage(solIdx, "Warning: this problem has zero decision variables!");
906  osrl = osrlwriter->writeOSrL( osresult);
907  return;
908  }
909 
910 
911  if(( bb.model().isProvenInfeasible() == true) )
912  {
913  std::string solutionDescription = "";
914  std::string message = "Success";
915  int solIdx = 0;
916 
917 
918  if(osresult->setServiceName( "Bonmin solver service") != true)
919  throw ErrorClass("OSResult error: setServiceName");
921  throw ErrorClass("OSResult error: setInstanceName");
923  throw ErrorClass("OSResult error: setVariableNumer");
924  if(osresult->setObjectiveNumber( 1) != true)
925  throw ErrorClass("OSResult error: setObjectiveNumber");
927  throw ErrorClass("OSResult error: setConstraintNumber");
928  if(osresult->setSolutionNumber( 1) != true)
929  throw ErrorClass("OSResult error: setSolutionNumber");
930  if(osresult->setGeneralMessage( message) != true)
931  throw ErrorClass("OSResult error: setGeneralMessage");
932  solutionDescription = "The problem is infeasible";
933  osresult->setSolutionStatus(solIdx, "error", solutionDescription);
934 
935  osresult->setGeneralStatusType("normal");
936  if( osinstance->getVariableNumber() == 0) osresult->setSolutionMessage(solIdx, "Warning: this problem has zero decision variables!");
937  osrl = osrlwriter->writeOSrL( osresult);
938  return;
939  }
940  status = tminlp->status;
941  writeResult();
942 
943  }
944  catch(const ErrorClass& eclass)
945  {
947  osresult->setGeneralStatusType( "error");
948  osrl = osrlwriter->writeOSrL( osresult);
949  throw ErrorClass( osrl) ;
950  }
951 }//solve
952 
953 
955 {
956  double *x = NULL;
957  double *z = NULL;
958  int i = 0;
959  int solIdx = 0;
960  std::string solutionDescription = "";
961  std::string message = "Bonmin solver finishes to the end.";
962  if( osinstance->getVariableNumber() == 0) osresult->setSolutionMessage(0, "Warning: this problem has zero decision variables!");
963 
964 
965  try
966  {
967  if(osinstance->getVariableNumber() > 0) x = new double[osinstance->getVariableNumber() ];
968  z = new double[1];
969  // resultHeader information
970  if(osresult->setServiceName( OSgetVersionInfo()) != true)
971  throw ErrorClass("OSResult error: setServiceName");
972  if(osresult->setSolverInvoked( "COIN-OR Bonmin") != true)
973  throw ErrorClass("OSResult error: setSolverInvoked");
975  throw ErrorClass("OSResult error: setInstanceName");
976  //if(osresult->setJobID( osoption->jobID) != true)
977  // throw ErrorClass("OSResult error: setJobID");
978  // set basic problem parameters
979 
981  throw ErrorClass("OSResult error: setVariableNumer");
982  if(osresult->setObjectiveNumber( 1) != true)
983  throw ErrorClass("OSResult error: setObjectiveNumber");
985  throw ErrorClass("OSResult error: setConstraintNumber");
986  if(osresult->setSolutionNumber( 1) != true)
987  throw ErrorClass("OSResult error: setSolutionNumer");
988  if(osresult->setGeneralMessage( message) != true)
989  throw ErrorClass("OSResult error: setGeneralMessage");
990 
991  switch( status)
992  {
993  case TMINLP::SUCCESS:
994  solutionDescription = "SUCCESS[BONMIN]: Algorithm terminated normally at a locally optimal point, satisfying the convergence tolerances.";
995  osresult->setSolutionStatus(solIdx, "locallyOptimal", solutionDescription);
996  /* Retrieve the solution */
997  if(osinstance->getObjectiveNumber() > 0)
998  {
999  *(z + 0) = osinstance->calculateAllObjectiveFunctionValues( const_cast<double*>(bb.bestSolution()), true)[ 0];
1000  osresult->setObjectiveValuesDense(solIdx, z);
1001  }
1002  if( osinstance->getVariableNumber() > 0)
1003  {
1004  for(i=0; i < osinstance->getVariableNumber(); i++)
1005  {
1006  *(x + i) = bb.bestSolution()[i];
1007  }
1009  }
1010  break;
1011 
1013  solutionDescription = "LIMIT_EXCEEDED[BONMIN]: A resource limit was exceeded, we provide the current solution.";
1014  osresult->setSolutionStatus(solIdx, "other", solutionDescription);
1015  //osresult->setPrimalVariableValuesDense(solIdx, const_cast<double*>(x));
1016  //osresult->setDualVariableValuesDense(solIdx, const_cast<double*>( lambda));
1017  /* Retrieve the solution */
1018  if(osinstance->getObjectiveNumber() > 0)
1019  {
1020  *(z + 0) = osinstance->calculateAllObjectiveFunctionValues( const_cast<double*>(bb.bestSolution()), true)[ 0];
1021  osresult->setObjectiveValuesDense(solIdx, z);
1022  }
1023  if( osinstance->getVariableNumber() > 0)
1024  {
1025  for(i=0; i < osinstance->getVariableNumber(); i++)
1026  {
1027  *(x + i) = bb.bestSolution()[i];
1028  }
1030  }
1031  break;
1032 
1033  case TMINLP::MINLP_ERROR:
1034  solutionDescription = "MINLP_ERROR [BONMIN]: Algorithm stopped with unspecified error.";
1035  osresult->setSolutionStatus(solIdx, "error", solutionDescription);
1036 
1037  break;
1038 
1040  solutionDescription = "CONTINUOUS_UNBOUNDED [BONMIN]: The continuous relaxation is unbounded, the MINLP may or may not be unbounded.";
1041  osresult->setSolutionStatus(solIdx, "error", solutionDescription);
1042 
1043  break;
1044 
1045 
1046  case TMINLP::INFEASIBLE:
1047  solutionDescription = "INFEASIBLE [BONMIN]: Problem may be infeasible.";
1048  osresult->setSolutionStatus(solIdx, "infeasible", solutionDescription);
1049  break;
1050 
1051 
1052  default:
1053  solutionDescription = "OTHER[BONMIN]: other unknown solution status from Bonmin solver";
1054  osresult->setSolutionStatus(solIdx, "other", solutionDescription);
1055  }//switch end
1056  osresult->setGeneralStatusType("normal");
1057  osrl = osrlwriter->writeOSrL( osresult);
1058  if(osinstance->getVariableNumber() > 0 ) delete[] x;
1059  x = NULL;
1060  delete[] z;
1061  z = NULL;
1062  }//end try
1063 
1064 
1065  catch(const ErrorClass& eclass)
1066  {
1067  if(osinstance->getVariableNumber() > 0) delete[] x;
1068  x = NULL;
1069  delete[] z;
1070  z = NULL;
1072  osresult->setGeneralStatusType( "error");
1073  osrl = osrlwriter->writeOSrL( osresult);
1074  throw ErrorClass( osrl) ;
1075  }
1076 }// end writeResult()
1077 
1078 
1080 {
1081  std::ostringstream outStr;
1082 
1083  int i;
1084 
1085  // print out problem parameters
1086  outStr << "This is problem: " << osinstance->getInstanceName() << endl;
1087  outStr << "The problem source is: " << osinstance->getInstanceSource() << endl;
1088  outStr << "The problem description is: " << osinstance->getInstanceDescription() << endl;
1089  outStr << "number of variables = " << osinstance->getVariableNumber() << endl;
1090  outStr << "number of Rows = " << osinstance->getConstraintNumber() << endl;
1091 
1092  // print out the variable information
1093  if(osinstance->getVariableNumber() > 0)
1094  {
1095  for(i = 0; i < osinstance->getVariableNumber(); i++)
1096  {
1097  if(osinstance->getVariableNames() != NULL) outStr << "variable Names " << osinstance->getVariableNames()[ i] << endl;
1098  if(osinstance->getVariableTypes() != NULL) outStr << "variable Types " << osinstance->getVariableTypes()[ i] << endl;
1099  if(osinstance->getVariableLowerBounds() != NULL) outStr << "variable Lower Bounds " << osinstance->getVariableLowerBounds()[ i] << endl;
1100  if(osinstance->getVariableUpperBounds() != NULL) outStr << "variable Upper Bounds " << osinstance->getVariableUpperBounds()[i] << endl;
1101  }
1102  }
1103 
1104  // print out objective function information
1106  {
1107  if( osinstance->getObjectiveMaxOrMins()[0] == "min") outStr << "problem is a minimization" << endl;
1108  else outStr << "problem is a maximization" << endl;
1109  for(i = 0; i < osinstance->getVariableNumber(); i++)
1110  {
1111  outStr << "OBJ COEFFICIENT = " << osinstance->getDenseObjectiveCoefficients()[0][i] << endl;
1112  }
1113  }
1114  // print out constraint information
1115  if(osinstance->getConstraintNumber() > 0)
1116  {
1117  for(i = 0; i < osinstance->getConstraintNumber(); i++)
1118  {
1119  if(osinstance->getConstraintNames() != NULL) outStr << "row name = " << osinstance->getConstraintNames()[i] << endl;
1120  if(osinstance->getConstraintLowerBounds() != NULL) outStr << "row lower bound = " << osinstance->getConstraintLowerBounds()[i] << endl;
1121  if(osinstance->getConstraintUpperBounds() != NULL) outStr << "row upper bound = " << osinstance->getConstraintUpperBounds()[i] << endl;
1122  }
1123  }
1124 
1125  // print out linear constraint data
1126  outStr << endl;
1127  outStr << "number of nonzeros = " << osinstance->getLinearConstraintCoefficientNumber() << endl;
1128  for(i = 0; i <= osinstance->getVariableNumber(); i++)
1129  {
1130  outStr << "Start Value = " << osinstance->getLinearConstraintCoefficientsInColumnMajor()->starts[ i] << endl;
1131  }
1132  outStr << endl;
1133  for(i = 0; i < osinstance->getLinearConstraintCoefficientNumber(); i++)
1134  {
1135  outStr << "Index Value = " << osinstance->getLinearConstraintCoefficientsInColumnMajor()->indexes[i] << endl;
1136  outStr << "Nonzero Value = " << osinstance->getLinearConstraintCoefficientsInColumnMajor()->values[i] << endl;
1137  }
1138 
1139  // print out quadratic data
1140  outStr << "number of qterms = " << osinstance->getNumberOfQuadraticTerms() << endl;
1141  for(int i = 0; i < osinstance->getNumberOfQuadraticTerms(); i++)
1142  {
1143  outStr << "Row Index = " << osinstance->getQuadraticTerms()->rowIndexes[i] << endl;
1144  outStr << "Var Index 1 = " << osinstance->getQuadraticTerms()->varOneIndexes[ i] << endl;
1145  outStr << "Var Index 2 = " << osinstance->getQuadraticTerms()->varTwoIndexes[ i] << endl;
1146  outStr << "Coefficient = " << osinstance->getQuadraticTerms()->coefficients[ i] << endl;
1148  }
1149 } // end dataEchoCheck
1150 
1151 
1153 {
1154  osinstance = osinstance_;
1155  osoption = osoption_;
1156  printSol_ = false;
1157 }
1158 
1160 {
1161 
1162 }
1163 
1164 
1165 
double * getConstraintLowerBounds()
Get constraint lower bounds.
double * getVariableLowerBounds()
Get variable lower bounds.
double * getConstraintUpperBounds()
Get constraint upper bounds.
double * values
std::string OSgetVersionInfo()
double os_strtod(const char *s00, char **se)
Definition: OSdtoa.cpp:2541
int getNumberOfInitVarValues()
Get the number of initial variable values.
Definition: OSOption.cpp:2051
int getNumberOfIntegerVariables()
getNumberOfIntegerVariables
char * getVariableTypes()
Get variable initial values.
std::string value
value holds the text of the value attribute of the OtherVariableResult element
bool setSolutionStatus(int solIdx, std::string type, std::string description)
Set the [i]th optimization solution status, where i equals the given solution index.
bool setPrimalVariableValuesDense(int solIdx, double *x)
Set the [i]th optimization solution&#39;s primal variable values, where i equals the given solution index...
Definition: OSResult.cpp:5001
SparseHessianMatrix * calculateLagrangianHessian(double *x, double *objLambda, double *conLambda, bool new_x, int highestOrder)
Calculate the Hessian of the Lagrangian Expression Tree This method will build the CppAD expression t...
const OSSmartPtr< OSOutput > osoutput
Definition: OSOutput.cpp:39
virtual void setSolverOptions()
The implementation of the virtual functions.
double * values
values holds a double array of nonzero partial derivatives
Definition: OSGeneral.h:340
bool bUseExpTreeForFunEval
bUseExpTreeForFunEval is set to true if you wish to use the OS Expression Tree for function evaluatio...
Definition: OSInstance.h:4899
BonminSolver()
the BonminSolver class constructor
int getVariableNumber()
Get number of variables.
void dataEchoCheck()
use this for debugging, print out the instance that the solver thinks it has and compare this with th...
bool setServiceName(std::string serviceName)
Set service name.
bool setVariableNumber(int variableNumber)
Set the variable number.
Definition: OSResult.cpp:4712
virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number *grad_f)
Method to return the gradient of the objective.
std::string errormsg
errormsg is the error that is causing the exception to be thrown
Definition: OSErrorClass.h:42
int getLinearConstraintCoefficientNumber()
Get number of specified (usually nonzero) linear constraint coefficient values.
virtual void buildSolverInstance()
buildSolverInstance is a virtual function – the actual solvers will implement their own buildSolverIn...
int * getNonlinearExpressionTreeModIndexes()
Get all the nonlinear expression tree indexes, i.e., indexes of rows (objectives or constraints) that...
std::string maxOrMin
declare the objective function to be a max or a min
Definition: OSInstance.h:157
the InitVarValue class.
Definition: OSOption.h:1159
std::vector< SolverOption * > getSolverOptions(std::string solver_name)
Get the options associated with a given solver.
Definition: OSOption.cpp:4508
The Result Class.
Definition: OSResult.h:2548
OSOption * osoption
virtual bool eval_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number &obj_value)
Method to return the objective value.
bool setSolverInvoked(std::string solverInvoked)
Set solver invoked.
Definition: OSResult.cpp:4155
SparseJacobianMatrix * calculateAllConstraintFunctionGradients(double *x, double *objLambda, double *conLambda, bool new_x, int highestOrder)
Calculate the gradient of all constraint functions.
std::string name
name holds the text of the name attribute of the OtherVariableResult element
void writeResult()
use this to write the solution information to an OSResult object
Take an OSResult object and write a string that validates against OSrL.
Definition: OSrLWriter.h:30
int getNumberOfNonlinearExpressionTreeModIndexes()
Get the number of unique nonlinear expression tree indexes after modifying the expression tree to con...
int * hessColIdx
hessColIdx is an integer array of column indices in the range 0, ..., n - 1.
Definition: OSGeneral.h:399
int getObjectiveNumber()
Get number of objectives.
bool setObjectiveNumber(int objectiveNumber)
Set the objective number.
Definition: OSResult.cpp:4721
bool setInstanceName(std::string instanceName)
Set instance name.
virtual bool get_variables_types(Ipopt::Index n, VariableType *var_types)
Pass the type of the variables (INTEGER, BINARY, CONTINUOUS) to the optimizer.
bool setSolutionMessage(int solIdx, std::string msg)
Set the [i]th optimization solution&#39;s message, where i equals the given solution index.
Definition: OSResult.cpp:4917
std::map< int, int > getAllNonlinearVariablesIndexMap()
std::string * getVariableNames()
Get variable names.
int * hessRowIdx
hessRowIdx is an integer array of row indices in the range 0, ..., n - 1.
Definition: OSGeneral.h:394
int getNumberOfNonlinearExpressions()
Get number of nonlinear expressions.
int numberOfObjectives
numberOfObjectives is the number of objective functions in the instance
Definition: OSInstance.h:201
virtual bool get_constraints_linearity(Ipopt::Index m, Ipopt::TNLP::LinearityType *const_types)
Pass the type of the constraints (LINEAR, NON_LINEAR) to the optimizer.
The Option Class.
Definition: OSOption.h:3564
int idx
variable index
Definition: OSOption.h:1164
int * indexes
indexes holds an integer array of rowIdx (or colIdx) elements in coefMatrix (AMatrix).
Definition: OSGeneral.h:258
bool setSolutionNumber(int number)
set the number of solutions.
Definition: OSResult.cpp:4740
double ** getDenseObjectiveCoefficients()
getDenseObjectiveCoefficients.
SparseJacobianMatrix * getJacobianSparsityPattern()
Error class to throw exceptions from OsiTMINLPInterface.
virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number *x_l, Ipopt::Number *x_u, Ipopt::Index m, Ipopt::Number *g_l, Ipopt::Number *g_u)
Bonmin specific methods for defining the nlp problem.
virtual void solve()
solve results in an instance being read into the Bonmin data structrues and optimized ...
virtual void finalize_solution(Bonmin::TMINLP::SolverReturn status_, Ipopt::Index n, const Ipopt::Number *x, Ipopt::Number obj_value)
Method called by Ipopt at the end of optimization.
int valueSize
valueSize is the dimension of the values array
Definition: OSGeneral.h:318
Used to read an OSiL string.
Definition: OSiLReader.h:37
int * indexes
indexes holds an integer array of variable indices.
Definition: OSGeneral.h:335
double * calculateAllConstraintFunctionValues(double *x, double *objLambda, double *conLambda, bool new_x, int highestOrder)
Calculate all of the constraint function values.
SolverReturn
Return statuses of algorithm.
Definition: BonTMINLP.hpp:64
double lb
lb corresponds to the optional attribute that holds the variable lower bound.
Definition: OSInstance.h:56
Variable ** var
Here we define a pointer to an array of var pointers.
Definition: OSInstance.h:97
int hessDimension
hessDimension is the number of nonzeros in each array.
Definition: OSGeneral.h:389
int * varOneIndexes
varOneIndexes holds an integer array of the first variable indexes of all the quadratic terms...
Definition: OSGeneral.h:445
double value
initial value
Definition: OSOption.h:1170
virtual bool get_nlp_info(Ipopt::Index &n, Ipopt::Index &m, Ipopt::Index &nnz_jac_g, Ipopt::Index &nnz_h_lag, Ipopt::TNLP::IndexStyleEnum &index_style)
Method to pass the main dimensions of the problem to Ipopt.
SparseHessianMatrix * getLagrangianHessianSparsityPattern()
OSResult * osresult
void fint fint * k
const double OSDBL_MAX
Definition: OSParameters.h:93
std::string * getObjectiveMaxOrMins()
Get objective maxOrMins.
BonminProblem(OSInstance *osinstance_, OSOption *osoption_)
the BonminProblemclass constructor
double ub
ub corresponds to the optional attribute that holds the variable upper bound.
Definition: OSInstance.h:61
double * hessValues
hessValues is a double array of the Hessian values.
Definition: OSGeneral.h:404
virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number *x, bool init_z, Ipopt::Number *z_L, Ipopt::Number *z_U, Ipopt::Index m, bool init_lambda, Ipopt::Number *lambda)
Method to return the starting point for the algorithm.
Variables * variables
variables is a pointer to a Variables object
Definition: OSInstance.h:2185
virtual bool eval_h(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number *lambda, bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
Method to return: 1) The structure of the hessian of the lagrangian (if &quot;values&quot; is NULL) 2) The valu...
SparseMatrix * getLinearConstraintCoefficientsInColumnMajor()
Get linear constraint coefficients in column major.
bool setGeneralMessage(std::string message)
Set the general message.
virtual bool get_variables_linearity(Ipopt::Index n, Ipopt::TNLP::LinearityType *var_types)
Pass info about linear and nonlinear variables.
double * values
values holds a double array of value elements in coefMatrix (AMatrix), which contains nonzero element...
Definition: OSGeneral.h:264
#define INTEGER
fint m1
bool setGeneralStatusType(std::string type)
Set the general status type, which can be: success, error, warning.
U * GetRawPtr(const OSSmartPtr< U > &smart_ptr)
Definition: OSSmartPtr.hpp:452
a sparse Jacobian matrix data structure
Definition: OSGeneral.h:300
std::string getInstanceName()
Get instance name.
InstanceData * instanceData
A pointer to an InstanceData object.
Definition: OSInstance.h:2278
virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
Method to return: 1) The structure of the jacobian (if &quot;values&quot; is NULL) 2) The values of the jacobia...
int * starts
starts holds an integer array of start elements, each start element points to the start of partials f...
Definition: OSGeneral.h:324
int getConstraintNumber()
Get number of constraints.
Objective ** obj
coef is pointer to an array of ObjCoef object pointers
Definition: OSInstance.h:205
bool setConstraintNumber(int constraintNumber)
Set the constraint number.
Definition: OSResult.cpp:4731
int getNumberOfSolverOptions()
Get the number of solver options.
Definition: OSOption.cpp:2207
int getNumberOfQuadraticTerms()
Get the number of specified (usually nonzero) qTerms in the quadratic coefficients.
Used to read an OSoL string.
Definition: OSoLReader.h:37
Objectives * objectives
objectives is a pointer to a Objectives object
Definition: OSInstance.h:2188
std::string getInstanceSource()
Get instance source.
InitVarValue ** getInitVarValuesSparse()
Get the initial values associated with the variables in sparse form.
Definition: OSOption.cpp:2719
bool initForAlgDiff()
This should be called by nonlinear solvers using callback functions.
virtual bool eval_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Number *g)
Method to return the constraint residuals.
int * rowIndexes
rowIndexes holds an integer array of row indexes of all the quadratic terms.
Definition: OSGeneral.h:440
int * starts
starts holds an integer array of start elements in coefMatrix (AMatrix), which points to the start of...
Definition: OSGeneral.h:252
double * calculateAllObjectiveFunctionValues(double *x, double *objLambda, double *conLambda, bool new_x, int highestOrder)
Calculate all of the objective function values.
virtual bool get_scaling_parameters(Ipopt::Number &obj_scaling, bool &use_x_scaling, Ipopt::Index n, Ipopt::Number *x_scaling, bool &use_g_scaling, Ipopt::Index m, Ipopt::Number *g_scaling)
overload this method to return scaling parameters.
QuadraticTerms * getQuadraticTerms()
Get all the quadratic terms in the instance.
We will throw this error when a problem is not solved.
virtual ~BonminProblem()
the BonminProblem class destructor
double * getVariableUpperBounds()
Get variable upper bounds.
void fint fint fint real fint real real real real real real * g
bool setObjectiveValuesDense(int solIdx, double *objectiveValues)
Set the [i]th optimization solution&#39;s objective values, where i equals the given solution index...
Definition: OSResult.cpp:5824
~BonminSolver()
the IpoptSolver class destructor
void fint * m
The in-memory representation of an OSiL instance..
Definition: OSInstance.h:2262
OSInstance * osinstance
double * coefficients
coefficients holds a double array all the quadratic term coefficients.
Definition: OSGeneral.h:455
int * varTwoIndexes
varTwoIndexes holds an integer array of the second variable indexes of all the quadratic terms...
Definition: OSGeneral.h:450
The in-memory representation of a SparseHessianMatrix..
Definition: OSGeneral.h:376
std::string * getConstraintNames()
Get constraint names.
used for throwing exceptions.
Definition: OSErrorClass.h:31
void fint * n
VariableType
Type of the variables.
Definition: BonTMINLP.hpp:192
int getNumberOfBinaryVariables()
getNumberOfBinaryVariables
std::string getInstanceDescription()
Get instance description.
double * calculateObjectiveFunctionGradient(double *x, double *objLambda, double *conLambda, int objIdx, bool new_x, int highestOrder)
Calculate the gradient of the objective function indexed by objIdx.
void fint fint fint real fint real * x