My Project
OSIpoptSolver.cpp
Go to the documentation of this file.
1 /* $Id$ */
18 #include "OSIpoptSolver.h"
19 #include "OSGeneral.h"
20 #include "OSParameters.h"
21 #include "OSMathUtil.h"
22 #include "CoinFinite.hpp"
23 #include "OSOutput.h"
24 
25 
26 using std::cout;
27 using std::endl;
28 using std::ostringstream;
29 using namespace Ipopt;
30 
31 
33 {
34 #ifndef NDEBUG
36  "inside IpoptSolver constructor\n");
37 #endif
38  osrlwriter = new OSrLWriter();
39  osresult = new OSResult();
40  m_osilreader = NULL;
41  m_osolreader = NULL;
42  ipoptErrorMsg = new std::string("");
43 }
44 
46 {
47 #ifndef NDEBUG
49  "inside IpoptSolver destructor\n");
50 #endif
51  if(m_osilreader != NULL) delete m_osilreader;
52  m_osilreader = NULL;
53  if(m_osolreader != NULL) delete m_osolreader;
54  m_osolreader = NULL;
55  delete osresult;
56  osresult = NULL;
57  delete osrlwriter;
58  osrlwriter = NULL;
59  //delete osinstance;
60  //osinstance = NULL;
61  delete ipoptErrorMsg;
62 #ifndef NDEBUG
64  "Leaving IpoptSolver destructor\n");
65 #endif
66 }
67 
68 // returns the size of the problem
69 bool IpoptProblem::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
70  Index& nnz_h_lag, IndexStyleEnum& index_style)
71 {
72  std::ostringstream outStr;
73  try
74  {
75  //if(osinstance->getObjectiveNumber() <= 0) throw ErrorClass("Ipopt NEEDS AN OBJECTIVE FUNCTION");
76  if( (osinstance->getNumberOfIntegerVariables() + osinstance->getNumberOfBinaryVariables()) > 0 )
77  throw ErrorClass("Ipopt does not solve integer programs -- please try Bonmin or Couenne");
78  // number of variables
79  n = osinstance->getVariableNumber();
80  // number of constraints
81  m = osinstance->getConstraintNumber();
82 #ifndef NDEBUG
83  outStr.str("");
84  outStr.clear();
85  outStr << "number variables !!!!!!!!!!!!!!!!!!!!!!!!!!!" << n << endl;
86  outStr << "number constraints !!!!!!!!!!!!!!!!!!!!!!!!!!!" << m << endl;
88 #endif
89  try
90  {
91  osinstance->initForAlgDiff( );
92  }
93  catch(const ErrorClass& eclass)
94  {
95  outStr.str("");
96  outStr.clear();
97  outStr << "error in OSIpoptSolver, AD initialization failed:\n" << eclass.errormsg << endl;
99  *ipoptErrorMsg = eclass.errormsg;
100  throw;
101  }
102  // use the OS Expression tree for function evaluations instead of CppAD
103  osinstance->bUseExpTreeForFunEval = true;
104  SparseJacobianMatrix *sparseJacobian = NULL;
105  try
106  {
107  sparseJacobian = osinstance->getJacobianSparsityPattern();
108  }
109  catch(const ErrorClass& eclass)
110  {
111  outStr.str("");
112  outStr.clear();
113  outStr << "error in OSIpoptSolver, Jacobian sparsity:\n" << eclass.errormsg << endl;
115  *ipoptErrorMsg = eclass.errormsg;
116  throw;
117  }
118  if (sparseJacobian != NULL)
119  {
120  nnz_jac_g = sparseJacobian->valueSize;
121  }
122  else
123  {
124  nnz_jac_g = 0;
125  }
126 
127 #ifndef NDEBUG
128  outStr.str("");
129  outStr.clear();
130  outStr << "nnz_jac_g !!!!!!!!!!!!!!!!!!!!!!!!!!!" << nnz_jac_g << endl;
132 #endif
133  // nonzeros in upper hessian
134 
135  if( (osinstance->getNumberOfNonlinearExpressions() == 0) &&
136  (osinstance->getNumberOfQuadraticTerms() == 0) )
137  {
138 #ifndef NDEBUG
139  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_debug, "This is a linear program\n");
140 #endif
141  nnz_h_lag = 0;
142  }
143  else
144  {
145  SparseHessianMatrix *sparseHessian = osinstance->getLagrangianHessianSparsityPattern();
146  if(sparseHessian != NULL)
147  {
148  nnz_h_lag = sparseHessian->hessDimension;
149  }
150  else
151  {
152  nnz_h_lag = 0;
153  }
154  }
155 #ifndef NDEBUG
156  outStr.str("");
157  outStr.clear();
158  outStr << "print nnz_h_lag (OSIpoptSolver.cpp)" << endl;
159  outStr << "nnz_h_lag !!!!!!!!!!!!!!!!!!!!!!!!!!!" << nnz_h_lag << endl;
160  outStr << "set index_style (OSIpoptSolver.cpp)" << endl;
162 #endif
163  // use the C style indexing (0-based)
164  index_style = TNLP::C_STYLE;
165 #ifndef NDEBUG
166  outStr.str("");
167  outStr.clear();
168  outStr << "return from get_nlp_info (OSIpoptSolver.cpp)" << nnz_h_lag << endl;
170 #endif
171 
173 
174  return true;
175  }
176  catch(const ErrorClass& eclass)
177  {
178  *ipoptErrorMsg = eclass.errormsg;
179  throw;
180  }
181 
182 }//get_nlp_info
183 
184 
185 bool IpoptProblem::get_bounds_info(Index n, Number* x_l, Number* x_u,
186  Index m, Number* g_l, Number* g_u)
187 {
188  int i;
189  double * mdVarLB = osinstance->getVariableLowerBounds();
190  // variables upper bounds
191  double * mdVarUB = osinstance->getVariableUpperBounds();
192 
193  for(i = 0; i < n; i++)
194  {
195  x_l[ i] = mdVarLB[ i];
196  x_u[ i] = mdVarUB[ i];
197  }
198  // Ipopt interprets any number greater than nlp_upper_bound_inf as
199  // infinity. The default value of nlp_upper_bound_inf and nlp_lower_bound_inf
200  // is 1e19 and can be changed through ipopt options.
201  // e.g. g_u[0] = 2e19;
202 
203  //constraint lower bounds
204  double * mdConLB = osinstance->getConstraintLowerBounds();
205  //constraint upper bounds
206  double * mdConUB = osinstance->getConstraintUpperBounds();
207 
208  for(int i = 0; i < m; i++)
209  {
210  g_l[ i] = mdConLB[ i];
211  g_u[ i] = mdConUB[ i];
212  }
213  return true;
214 }//get_bounds_info
215 
216 
217 // returns the initial point for the problem
218 bool IpoptProblem::get_starting_point(Index n, bool init_x, Number* x,
219  bool init_z, Number* z_L, Number* z_U, Index m, bool init_lambda,
220  Number* lambda)
221 {
222  std::ostringstream outStr;
223 
224  // Here, we assume we only have starting values for x, if you code
225  // your own NLP, you can provide starting values for the dual variables
226  // if you wish
227  assert(init_x == true);
228  assert(init_z == false);
229  assert(init_lambda == false);
230  int i, m1, n1;
231 
232 #ifndef NDEBUG
233  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_debug, "get initial values !!!!!!!!!!!!!!!!!!!!!!!!!!\n");
234 #endif
235 
236  //now set initial values
237 #ifndef NDEBUG
238  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_debug, "get number of initial values !!!!!!!!!!!!!!!!!!!!!!!!!!\n");
239 #endif
240  int k;
241  if (osoption != NULL)
243  else
244  m1 = 0;
245 #ifndef NDEBUG
246  outStr.str("");
247  outStr.clear();
248  outStr << "number of variables initialed: " << m1 << endl;
250 #endif
251 
252  n1 = osinstance->getVariableNumber();
253  bool* initialed;
254  initialed = new bool[n1];
255 #ifndef NDEBUG
256  outStr.str("");
257  outStr.clear();
258  outStr << "number of variables in total: " << n1 << endl;
260 #endif
261 
262  for(k = 0; k < n1; k++)
263  initialed[k] = false;
264 
265  if (m1 > 0)
266  {
267 #ifndef NDEBUG
269  "get initial values\n");
270 #endif
271 
272  InitVarValue** initVarVector = osoption->getInitVarValuesSparse();
273 #ifndef NDEBUG
275 #endif
276  try
277  {
278  double initval;
279  for(k = 0; k < m1; k++)
280  {
281  i = initVarVector[k]->idx;
282  if (initVarVector[k]->idx > n1)
283  throw ErrorClass ("Illegal index value in variable initialization");
284 
285  initval = initVarVector[k]->value;
286  if (osinstance->instanceData->variables->var[k]->ub == OSDBL_MAX)
287  {
288  if (osinstance->instanceData->variables->var[k]->lb > initval)
289  throw ErrorClass ("Initial value outside of bounds");
290  }
291  else if (osinstance->instanceData->variables->var[k]->lb == -OSDBL_MAX)
292  {
293  if (osinstance->instanceData->variables->var[k]->ub < initval)
294  throw ErrorClass ("Initial value outside of bounds");
295  }
296  else
297  {
298  if ((osinstance->instanceData->variables->var[k]->lb > initval) ||
299  (osinstance->instanceData->variables->var[k]->ub < initval))
300  throw ErrorClass ("Initial value outside of bounds");
301  }
302 
303  x[initVarVector[k]->idx] = initval;
304  initialed[initVarVector[k]->idx] = true;
305  }
306  }
307  catch(const ErrorClass& eclass)
308  {
310  "Error in IpoptProblem::get_starting_point (see OSIpoptSolver.cpp)\n"+eclass.errormsg+"\n\n");
311  }
312  } // end if (m1 > 0)
313 
314  double default_initval;
315  default_initval = 1.7171;
316  //default_initval = 0;
317 
318  for(k = 0; k < n1; k++)
319  {
320  if (!initialed[k])
321  {
322  if (osinstance->instanceData->variables->var[k]->ub == OSDBL_MAX)
323  if (osinstance->instanceData->variables->var[k]->lb <= default_initval)
324  x[k] = default_initval;
325  else
326  x[k] = osinstance->instanceData->variables->var[k]->lb;
327  else if (osinstance->instanceData->variables->var[k]->lb == -OSDBL_MAX)
328  if (osinstance->instanceData->variables->var[k]->ub >= default_initval)
329  x[k] = default_initval;
330  else
331  x[k] = osinstance->instanceData->variables->var[k]->ub;
332  else if ((osinstance->instanceData->variables->var[k]->lb <= default_initval) &&
333  (osinstance->instanceData->variables->var[k]->ub >= default_initval))
334  x[k] = default_initval;
335  else if (osinstance->instanceData->variables->var[k]->lb > default_initval)
336  x[k] = osinstance->instanceData->variables->var[k]->lb;
337  else
338  x[k] = osinstance->instanceData->variables->var[k]->ub;
339  }
340  }
341 
342 #ifndef NDEBUG
343  outStr.str("");
344  outStr.clear();
345  for(i = 0; i < n1; i++)
346  {
347  outStr << "INITIAL VALUE !!!!!!!!!!!!!!!!!!!! " << x[ i] << std::endl;
348  }
350 #endif
351  //make sure objvalue is initialized
352  osinstance->calculateAllObjectiveFunctionValues( x, true);
353  delete[] initialed;
354 
355  return true;
356 }//get_starting_point
357 
358 // returns the value of the objective function
359 bool IpoptProblem::eval_f(Index n, const Number* x, bool new_x, Number& obj_value)
360 {
361  try
362  {
363  if(osinstance->getObjectiveNumber() > 0)
364  {
365  //the following is a kludge for ipopt, new_x does not seem to get initialized if there are no constraints.
366  //if(osinstance->getConstraintNumber() <= 0) new_x = true;
367  if (new_x == false)
368  obj_value = osinstance->calculateAllObjectiveFunctionValues( const_cast<double*>(x), false)[ 0];
369  else
370  obj_value = osinstance->calculateAllObjectiveFunctionValues( const_cast<double*>(x), NULL, NULL, true, 0 )[ 0];
371  //if( CoinIsnan( (double)obj_value) ) return false;
372  //if( CoinIsnan( obj_value ) )return false;
373  }
374  }
375  catch(const ErrorClass& eclass)
376  {
377  *ipoptErrorMsg = eclass.errormsg;
378  throw;
379  }
380 
381  return true;
382 }
383 
384 bool IpoptProblem::eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f)
385 {
386  std::ostringstream outStr;
387  int i;
388  double *objGrad = NULL;
389  if(osinstance->getObjectiveNumber() > 0)
390  {
391  try
392  {
393  //objGrad = osinstance->calculateAllObjectiveFunctionGradients( const_cast<double*>(x), NULL, NULL, new_x, 1)[ 0];
394  objGrad = osinstance->calculateObjectiveFunctionGradient( const_cast<double*>(x), NULL, NULL, -1, new_x, 1);
395  }
396  catch(const ErrorClass& eclass)
397  {
398 #ifndef NDEBUG
399  outStr.str("");
400  outStr.clear();
401  outStr << "error in IpoptProblem::eval_grad_f (see OSIpoptSolver.cpp)\n" << eclass.errormsg << endl;
403 #endif
404  *ipoptErrorMsg = eclass.errormsg;
405  throw;
406  }
407  for(i = 0; i < n; i++)
408  {
409  grad_f[ i] = objGrad[ i];
410  }
411  }
412  return true;
413 }//eval_grad_f
414 
415 // return the value of the constraints: g(x)
416 bool IpoptProblem::eval_g(Index n, const Number* x, bool new_x, Index m, Number* g)
417 {
418  std::ostringstream outStr;
419  try
420  {
421  double *conVals = osinstance->calculateAllConstraintFunctionValues( const_cast<double*>(x), NULL, NULL, new_x, 0 );
422  int i;
423  for(i = 0; i < m; i++)
424  {
425  if( CoinIsnan( (double)conVals[ i] ) ) return false;
426  g[i] = conVals[ i] ;
427  }
428  return true;
429  }
430  catch(const ErrorClass& eclass)
431  {
432 #ifndef NDEBUG
433  outStr.str("");
434  outStr.clear();
435  outStr << "error in IpoptProblem::eval_grad_g (see OSIpoptSolver.cpp)\n" << eclass.errormsg << endl;
437 #endif
438  *ipoptErrorMsg = eclass.errormsg;
439  throw;
440  }
441 }//eval_g
442 
443 
444 // return the structure or values of the jacobian
445 bool IpoptProblem::eval_jac_g(Index n, const Number* x, bool new_x,
446  Index m, Index nele_jac, Index* iRow, Index *jCol,
447  Number* values)
448 {
449  std::ostringstream outStr;
450  SparseJacobianMatrix *sparseJacobian;
451  if (values == NULL)
452  {
453  // return the structure of the jacobian
454  try
455  {
456  sparseJacobian = osinstance->getJacobianSparsityPattern();
457  }
458  catch(const ErrorClass& eclass)
459  {
460 #ifndef NDEBUG
461  outStr.str("");
462  outStr.clear();
463  outStr << "error in IpoptProblem::eval_jac_g (see OSIpoptSolver.cpp)\n" << eclass.errormsg << endl;
465 #endif
466  *ipoptErrorMsg = eclass.errormsg;
467  throw;
468  }
469  int i = 0;
470  int k, idx;
471  for(idx = 0; idx < m; idx++)
472  {
473  for(k = *(sparseJacobian->starts + idx); k < *(sparseJacobian->starts + idx + 1); k++)
474  {
475  iRow[i] = idx;
476  jCol[i] = *(sparseJacobian->indexes + k);
477  i++;
478  }
479  }
480  }
481  else
482  {
483  try
484  {
485  sparseJacobian = osinstance->calculateAllConstraintFunctionGradients( const_cast<double*>(x), NULL, NULL, new_x, 1);
486  }
487  catch(const ErrorClass& eclass)
488  {
489 #ifndef NDEBUG
490  outStr.str("");
491  outStr.clear();
492  outStr << "error in IpoptProblem::eval_jac_g (see OSIpoptSolver.cpp)\n" << eclass.errormsg << endl;
494 #endif
495  *ipoptErrorMsg = eclass.errormsg;
496  throw;
497  }
498  //osinstance->getIterateResults( (double*)x, 0.0, NULL, -1, new_x, 1);
499  for(int i = 0; i < nele_jac; i++)
500  {
501  values[ i] = sparseJacobian->values[i];
502  }
503  }
504  return true;
505 }//eval_jac_g
506 
507 //return the structure or values of the hessian
508 bool IpoptProblem::eval_h(Index n, const Number* x, bool new_x,
509  Number obj_factor, Index m, const Number* lambda,
510  bool new_lambda, Index nele_hess, Index* iRow,
511  Index* jCol, Number* values)
512 {
513  std::ostringstream outStr;
514 
516  SparseHessianMatrix *sparseHessian;
517 
518  int i;
519  if (values == NULL)
520  {
521  // return the structure. This is a symmetric matrix, fill the lower left triangle only.
522  try
523  {
524  sparseHessian = osinstance->getLagrangianHessianSparsityPattern( );
525  }
526  catch(const ErrorClass& eclass)
527  {
528 
529  *ipoptErrorMsg = eclass.errormsg;
530  throw;
531  }
532  for(i = 0; i < nele_hess; i++)
533  {
534  iRow[i] = *(sparseHessian->hessColIdx + i);
535  jCol[i] = *(sparseHessian->hessRowIdx + i);
536  }
537  }
538  else
539  {
540  // return the values. This is a symmetric matrix, fill the lower left triangle only
541  double* objMultipliers = new double[1];
542  objMultipliers[0] = obj_factor;
543  try
544  {
545  sparseHessian = osinstance->calculateLagrangianHessian( const_cast<double*>(x), objMultipliers, const_cast<double*>(lambda) , new_x, 2);
546  delete[] objMultipliers;
547  }
548  catch(const ErrorClass& eclass)
549  {
550 #ifndef NDEBUG
551  outStr.str("");
552  outStr.clear();
553  outStr << "error in OSIpoptSolver, line 444:\n" << eclass.errormsg << endl;
555 #endif
556  *ipoptErrorMsg = eclass.errormsg;
557  delete[] objMultipliers;
558  throw;
559  }
560  for(i = 0; i < nele_hess; i++)
561  {
562  values[ i] = *(sparseHessian->hessValues + i);
563  }
564  }
566  return true;
567 }//eval_h
568 
569 bool IpoptProblem::get_scaling_parameters(Number& obj_scaling,
570  bool& use_x_scaling, Index n,
571  Number* x_scaling,
572  bool& use_g_scaling, Index m,
573  Number* g_scaling)
574 {
575  if( osinstance->instanceData->objectives->obj[ 0]->maxOrMin.compare("min") != 0)
576  {
577  obj_scaling = -1;
578  }
579  else obj_scaling = 1;
580  use_x_scaling = false;
581  use_g_scaling = false;
582  return true;
583 }//get_scaling_parameters
584 
585 void IpoptProblem::finalize_solution(SolverReturn status,
586  Index n, const Number* x, const Number* z_L, const Number* z_U,
587  Index m, const Number* g, const Number* lambda, Number obj_value,
588  const IpoptData* ip_data, IpoptCalculatedQuantities* ip_cq)
589 {
590  // here is where we would store the solution to variables, or write to a file, etc
591  // so we could use the solution.
592  if(osinstance->getObjectiveNumber() > 0)
593  obj_value = osinstance->calculateAllObjectiveFunctionValues( const_cast<double*>(x), true)[ 0];
594  OSrLWriter *osrlwriter ;
595  osrlwriter = new OSrLWriter();
596 
597  ostringstream outStr;
598 #ifdef DEBUG
599 
600  outStr << std::endl << std::endl << "Solution of the primal variables, x" << std::endl;
601  for (Index i=0; i<n; i++)
602  {
603  outStr << "x[" << i << "] = " << x[i] << std::endl;
604  }
605 
606  outStr << std::endl << std::endl << "Solution of the bound multipliers, z_L and z_U" << std::endl;
607  for (Index i=0; i<n; i++)
608  {
609  outStr << "z_L[" << i << "] = " << z_L[i] << std::endl;
610  }
611  for (Index i=0; i<n; i++)
612  {
613  outStr << "z_U[" << i << "] = " << z_U[i] << std::endl;
614  }
616  outStr.str("");
617  outStr.clear();
618 #endif
619  if(osinstance->getObjectiveNumber() > 0)
620  {
621  outStr << std::endl << "Objective value f(x*) = " << os_dtoa_format(obj_value) << std::endl;
623  }
624  int solIdx = 0;
625  int numberOfOtherVariableResults;
626  int otherIdx;
627  int numCon = osinstance->getConstraintNumber();
628 
629  //make sure the sign on the dual values is correct
630  double *dualValue = NULL;
631  std::string *rcost = NULL;
632  int* idx = NULL;
633  double* mdObjValues = NULL;
634  if(osinstance->getObjectiveNumber() > 0)
635  {
636  mdObjValues = new double[1];
637  }
638 
639  std::string message = "Ipopt solver finishes to the end.";
640  std::string solutionDescription = "";
641 
642  try
643  {
644  // resultHeader information
645  if(osresult->setSolverInvoked( "COIN-OR Ipopt") != true)
646  throw ErrorClass("OSResult error: setSolverInvoked");
647  if(osresult->setServiceName( OSgetVersionInfo()) != true)
648  throw ErrorClass("OSResult error: setServiceName");
649  if(osresult->setInstanceName( osinstance->getInstanceName()) != true)
650  throw ErrorClass("OSResult error: setInstanceName");
651 
652  //if(osresult->setJobID( osoption->jobID) != true)
653  // throw ErrorClass("OSResult error: setJobID");
654 
655  // set basic problem parameters
656  if(osresult->setVariableNumber( osinstance->getVariableNumber()) != true)
657  throw ErrorClass("OSResult error: setVariableNumer");
658  if(osresult->setObjectiveNumber( 1) != true)
659  throw ErrorClass("OSResult error: setObjectiveNumber");
660  if(osresult->setConstraintNumber( osinstance->getConstraintNumber()) != true)
661  throw ErrorClass("OSResult error: setConstraintNumber");
662  if(osresult->setSolutionNumber( 1) != true)
663  throw ErrorClass("OSResult error: setSolutionNumer");
664  if(osresult->setGeneralMessage( message) != true)
665  throw ErrorClass("OSResult error: setGeneralMessage");
666 
667  switch( status)
668  {
669  case SUCCESS:
670  solutionDescription = "SUCCESS[IPOPT]: Algorithm terminated normally at a locally optimal point, satisfying the convergence tolerances.";
671  osresult->setSolutionStatus(solIdx, "locallyOptimal", solutionDescription);
672 
673  if(osinstance->getVariableNumber() > 0) osresult->setPrimalVariableValuesDense(solIdx, const_cast<double*>(x));
674 
675  if(numCon > 0)
676  {
677  dualValue = new double[ numCon];
678  for (Index i=0; i < numCon; i++)
679  {
680  dualValue[ i] = -lambda[ i];
681  }
682  //osresult->setDualVariableValuesDense(solIdx, const_cast<double*>(lambda));
683  osresult->setDualVariableValuesDense(solIdx, dualValue);
684  }
685 
686  if(osinstance->getObjectiveNumber() > 0)
687  {
688  mdObjValues[0] = obj_value ;
689  osresult->setObjectiveValuesDense(solIdx, mdObjValues);
690  }
691  // set other
692 
693  if(osinstance->getVariableNumber() > 0)
694  {
695  numberOfOtherVariableResults = 1;
696  osresult->setNumberOfOtherVariableResults(solIdx, numberOfOtherVariableResults);
697  rcost = new std::string[ osinstance->getVariableNumber()];
698  idx = new int[ osinstance->getVariableNumber()];
699  for (Index i = 0; i < n; i++)
700  {
701  rcost[ i] = os_dtoa_format( z_L[i] - z_U[i]);
702  idx[ i] = i;
703  }
704  otherIdx = 0;
705  osresult->setAnOtherVariableResultSparse(solIdx, otherIdx, "reduced_costs", "",
706  "the variable reduced costs", idx, rcost, osinstance->getVariableNumber(), "",
707  "double", "");
708  }
709  //set dual values on variable upper and lower bounds
710  /*
711  for (Index i = 0; i < n; i++) {
712  rcost[ i] = os_dtoa_format( z_L[i]);
713  idx[ i] = i;
714  }
715  otherIdx = 0;
716  osresult->setAnOtherVariableResultSparse(solIdx, otherIdx, "varL", "", "Lagrange Multiplier on the Variable Lower Bound", idx, rcost, osinstance->getVariableNumber() );
717 
718 
719  for (Index i = 0; i < n; i++) {
720  rcost[ i] = os_dtoa_format( z_U[i]);
721  }
722  otherIdx = 1;
723  osresult->setAnOtherVariableResultSparse(solIdx, otherIdx, "varU", "", "Lagrange Multiplier on the Variable Upper Bound", idx, rcost, osinstance->getVariableNumber() );
724  */
725  if(osinstance->getVariableNumber() > 0) delete[] rcost;
726  if(osinstance->getVariableNumber() > 0) delete[] idx;
727  if(osinstance->getConstraintNumber() > 0) delete[] dualValue;
728  break;
729 
730  case MAXITER_EXCEEDED:
731  solutionDescription = "MAXITER_EXCEEDED[IPOPT]: Maximum number of iterations exceeded.";
732  osresult->setSolutionStatus(solIdx, "stoppedByLimit", solutionDescription);
733  if(x != NULL) osresult->setPrimalVariableValuesDense(solIdx, const_cast<double*>(x));
734  if(lambda != NULL) osresult->setDualVariableValuesDense(solIdx, const_cast<double*>( lambda));
735  if(osinstance->getObjectiveNumber() > 0)
736  {
737  mdObjValues[0] = obj_value ;
738  osresult->setObjectiveValuesDense(solIdx, mdObjValues);
739  }
740  break;
741 
742  case STOP_AT_TINY_STEP:
743  solutionDescription = "STOP_AT_TINY_STEP[IPOPT]: Algorithm proceeds with very little progress.";
744  osresult->setSolutionStatus(solIdx, "stoppedByLimit", solutionDescription);
745  if(x != NULL) osresult->setPrimalVariableValuesDense(solIdx, const_cast<double*>( x));
746  if(lambda != NULL) osresult->setDualVariableValuesDense(solIdx, const_cast<double*>( lambda));
747  if(osinstance->getObjectiveNumber() > 0)
748  {
749  mdObjValues[0] = obj_value ;
750  osresult->setObjectiveValuesDense(solIdx, mdObjValues);
751  }
752  break;
753 
754  case STOP_AT_ACCEPTABLE_POINT:
755  solutionDescription = "STOP_AT_ACCEPTABLE_POINT[IPOPT]: Algorithm stopped at a point that was converged, not to _desired_ tolerances, but to _acceptable_ tolerances";
756  osresult->setSolutionStatus(solIdx, "IpoptAccetable", solutionDescription);
757  if(lambda != NULL) osresult->setDualVariableValuesDense(solIdx, const_cast<double*>( lambda));
758  if(x != NULL)osresult->setPrimalVariableValuesDense(solIdx, const_cast<double*>(x));
759  if(osinstance->getObjectiveNumber() > 0)
760  {
761  mdObjValues[0] = obj_value ;
762  osresult->setObjectiveValuesDense(solIdx, mdObjValues);
763  }
764  break;
765 
766  case LOCAL_INFEASIBILITY:
767  solutionDescription = "LOCAL_INFEASIBILITY[IPOPT]: Algorithm converged to a point of local infeasibility. Problem may be infeasible.";
768  osresult->setSolutionStatus(solIdx, "infeasible", solutionDescription);
769  if( osinstance->getVariableNumber() == 0)
770  osresult->setSolutionMessage(solIdx, "Warning: this problem has zero decision variables!");
771  break;
772 
773  case USER_REQUESTED_STOP:
774  solutionDescription = "USER_REQUESTED_STOP[IPOPT]: The user call-back function intermediate_callback returned false, i.e., the user code requested a premature termination of the optimization.";
775  osresult->setSolutionStatus(solIdx, "error", solutionDescription);
776  if( osinstance->getVariableNumber() == 0)
777  osresult->setSolutionMessage(solIdx, "Warning: this problem has zero decision variables!");
778  break;
779 
780  case DIVERGING_ITERATES:
781  solutionDescription = "DIVERGING_ITERATES[IPOPT]: It seems that the iterates diverge.";
782  osresult->setSolutionStatus(solIdx, "unbounded", solutionDescription);
783  if( osinstance->getVariableNumber() == 0)
784  osresult->setSolutionMessage(solIdx, "Warning: this problem has zero decision variables!");
785  break;
786 
787  case RESTORATION_FAILURE:
788  solutionDescription = "RESTORATION_FAILURE[IPOPT]: Restoration phase failed, algorithm doesn't know how to proceed.";
789  osresult->setSolutionStatus(solIdx, "error", solutionDescription);
790  if( osinstance->getVariableNumber() == 0)
791  osresult->setSolutionMessage(solIdx, "Warning: this problem has zero decision variables!");
792  break;
793 
794  case ERROR_IN_STEP_COMPUTATION:
795  solutionDescription = "ERROR_IN_STEP_COMPUTATION[IPOPT]: An unrecoverable error occurred while IPOPT tried to compute the search direction.";
796  osresult->setSolutionStatus(solIdx, "error", solutionDescription);
797  if( osinstance->getVariableNumber() == 0)
798  osresult->setSolutionMessage(solIdx, "Warning: this problem has zero decision variables!");
799  break;
800 
801  case INVALID_NUMBER_DETECTED:
802  solutionDescription = "INVALID_NUMBER_DETECTED[IPOPT]: Algorithm received an invalid number (such as NaN or Inf) from the NLP; see also option check_derivatives_for_naninf.";
803  osresult->setSolutionStatus(solIdx, "error", solutionDescription);
804  if( osinstance->getVariableNumber() == 0)
805  osresult->setSolutionMessage(solIdx, "Warning: this problem has zero decision variables!");
806  break;
807 
808  case INTERNAL_ERROR:
809  solutionDescription = "INTERNAL_ERROR[IPOPT]: An unknown internal error occurred. Please contact the IPOPT authors through the mailing list.";
810  osresult->setSolutionStatus(solIdx, "error", solutionDescription);
811  if( osinstance->getVariableNumber() == 0)
812  osresult->setSolutionMessage(solIdx, "Warning: this problem has zero decision variables!");
813  break;
814 
815  default:
816  solutionDescription = "OTHER[IPOPT]: other unknown solution status from Ipopt solver";
817  osresult->setSolutionStatus(solIdx, "other", solutionDescription);
818  if( osinstance->getVariableNumber() == 0)
819  osresult->setSolutionMessage(solIdx, "Warning: this problem has zero decision variables!");
820  }
821 
822  osresult->setGeneralStatusType("normal");
823  delete osrlwriter;
824  osrlwriter = NULL;
825  if(osinstance->getObjectiveNumber() > 0)
826  {
827  delete[] mdObjValues;
828  }
829 
830  return;
831  }
832  catch(const ErrorClass& eclass)
833  {
834 #ifndef NDEBUG
835  outStr.str("");
836  outStr.clear();
837  outStr << "error trap in OSIpoptSolver:\n" << eclass.errormsg << endl;
839 #endif
841  osresult->setGeneralStatusType( "error");
842  std::string osrl = osrlwriter->writeOSrL( osresult);
843  delete osrlwriter;
844  osrlwriter = NULL;
845  if(osinstance->getObjectiveNumber() > 0)
846  {
847  delete[] mdObjValues;
848  }
849  mdObjValues = NULL;
850  throw ErrorClass( osrl) ;
851  }
853 }
854 
855 
857 {
858  std::ostringstream outStr;
859  try
860  {
861  if(osil.length() == 0 && osinstance == NULL) throw ErrorClass("there is no instance");
862  if(osinstance == NULL)
863  {
864  m_osilreader = new OSiLReader();
865  osinstance = m_osilreader->readOSiL( osil);
866  }
867 
868  // Can't handle multiobjective problems properly --- especially nonlinear ones
869  if (osinstance->getObjectiveNumber() > 1)
870  throw ErrorClass("Solver cannot handle multiple objectives --- please delete all but one");
871 
872  // Create a new instance of your nlp
873  nlp = new IpoptProblem( osinstance, osoption, osresult, ipoptErrorMsg);
874  app = new IpoptApplication();
875 
876  this->bCallbuildSolverInstance = true;
877  return;
878  }
879  catch(const ErrorClass& eclass)
880  {
881 #ifndef NDEBUG
882  outStr.str("");
883  outStr.clear();
884  outStr << "error in OSIpoptSolver, line 722:\n" << eclass.errormsg << endl;
886 #endif
888  osresult->setGeneralStatusType( "error");
889  osrl = osrlwriter->writeOSrL( osresult);
890  throw ErrorClass( osrl) ;
891  }
892 }//end buildSolverInstance()
893 
894 
896 {
897  std::ostringstream outStr;
898  try
899  {
900  if(osinstance->getObjectiveNumber() <= 0)
901  throw ErrorClass("Ipopt NEEDS AN OBJECTIVE FUNCTION\n(For pure feasibility problems, use zero function.)");
902  this->bSetSolverOptions = true;
903  /* set the default options */
904  //app->Options()->SetNumericValue("tol", 1e-9);
905  app->Options()->SetIntegerValue("print_level", 0);
906  app->Options()->SetIntegerValue("max_iter", 20000);
907  app->Options()->SetNumericValue("bound_relax_factor", 0, true, true);
908  app->Options()->SetStringValue("mu_strategy", "adaptive", true, true);
909  //app->Options()->SetStringValue("output_file", "ipopt.out");
910  app->Options()->SetStringValue("check_derivatives_for_naninf", "yes");
911  // hessian constant for an LP
912  if( (osinstance->getNumberOfNonlinearExpressions() <= 0) &&
913  (osinstance->getNumberOfQuadraticTerms() <= 0) )
914  {
915  app->Options()->SetStringValue("hessian_constant", "yes", true, true);
916  }
917  if(osinstance->getObjectiveNumber() > 0)
918  {
919  if( osinstance->instanceData->objectives->obj[ 0]->maxOrMin.compare("min") != 0)
920  {
921  app->Options()->SetStringValue("nlp_scaling_method", "user-scaling");
922  }
923  }
924  /* end of the default options, now get options from OSoL */
925 
926 
927  if(osoption == NULL && osol.length() > 0)
928  {
929  m_osolreader = new OSoLReader();
930  osoption = m_osolreader->readOSoL( osol);
931  }
932 
933  if( osoption != NULL && osoption->getNumberOfSolverOptions() > 0 )
934  {
935 #ifndef NDEBUG
936  outStr.str("");
937  outStr.clear();
938  outStr << "number of solver options ";
939  outStr << osoption->getNumberOfSolverOptions();
940  outStr << std::endl;
942 #endif
943  std::vector<SolverOption*> optionsVector;
944  optionsVector = osoption->getSolverOptions( "ipopt",true);
945  char *pEnd;
946  int i;
947  int num_ipopt_options = optionsVector.size();
948  for(i = 0; i < num_ipopt_options; i++)
949  {
950 #ifndef NDEBUG
951  outStr.str("");
952  outStr.clear();
953  outStr << "ipopt solver option ";
954  outStr << optionsVector[ i]->name;
955  outStr << std::endl;
957 #endif
958  if(optionsVector[ i]->type == "numeric" )
959  {
960 #ifndef NDEBUG
961  outStr.str("");
962  outStr.clear();
963  outStr << "FOUND A NUMERIC OPTION ";
964  outStr << os_strtod( optionsVector[ i]->value.c_str(), &pEnd );
965  outStr << std::endl;
967 #endif
968  app->Options()->SetNumericValue(optionsVector[ i]->name, os_strtod( optionsVector[ i]->value.c_str(), &pEnd ) );
969  }
970  else if(optionsVector[ i]->type == "integer" )
971  {
972 #ifndef NDEBUG
973  outStr.str("");
974  outStr.clear();
975  outStr << "FOUND AN INTEGER OPTION ";
976  outStr << atoi( optionsVector[ i]->value.c_str() );
977  outStr << std::endl;
979 #endif
980  app->Options()->SetIntegerValue(optionsVector[ i]->name, atoi( optionsVector[ i]->value.c_str() ) );
981  }
982  else if(optionsVector[ i]->type == "string" )
983  {
984 #ifndef NDEBUG
985  outStr.str("");
986  outStr.clear();
987  outStr << "FOUND A STRING OPTION ";
988  outStr << optionsVector[ i]->value.c_str();
989  outStr << std::endl;
991 #endif
992  app->Options()->SetStringValue(optionsVector[ i]->name, optionsVector[ i]->value);
993  }
994  }
995  }
996  return;
997  }
998  catch(const ErrorClass& eclass)
999  {
1000  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_error, "Error while setting options in IpoptSolver\n");
1002  osresult->setGeneralStatusType( "error");
1003  osrl = osrlwriter->writeOSrL( osresult);
1004  throw ErrorClass( osrl) ;
1005  }
1006 }//end setSolverOptions()
1007 
1008 
1009 
1011 {
1012  std::ostringstream outStr;
1013 
1014  if( this->bCallbuildSolverInstance == false) buildSolverInstance();
1015  if( this->bSetSolverOptions == false) setSolverOptions();
1016  try
1017  {
1018  app->Initialize();
1019  ApplicationReturnStatus status = app->OptimizeTNLP( nlp);
1020  osrl = osrlwriter->writeOSrL( osresult);
1021  if (status < -2)
1022  {
1023  throw ErrorClass("Ipopt FAILED TO SOLVE THE PROBLEM: " + *ipoptErrorMsg);
1024  }
1025  return;
1026  }
1027  catch(const ErrorClass& eclass)
1028  {
1029  outStr.str("");
1030  outStr.clear();
1031  outStr << "error in OSIpoptSolver routine solve():\n" << eclass.errormsg << endl;
1033 
1035  osresult->setGeneralStatusType( "error");
1036  osrl = osrlwriter->writeOSrL( osresult);
1037  throw ErrorClass( osrl) ;
1038  }
1039 }//solve
1040 
1042 {
1043 #ifndef NDEBUG
1044  int i;
1045  ostringstream outStr;
1046 
1047  // print out problem parameters
1048  outStr << "This is problem: " << osinstance->getInstanceName() << endl;
1049  outStr << "The problem source is: " << osinstance->getInstanceSource() << endl;
1050  outStr << "The problem description is: " << osinstance->getInstanceDescription() << endl;
1051  outStr << "number of variables = " << osinstance->getVariableNumber() << endl;
1052  outStr << "number of Rows = " << osinstance->getConstraintNumber() << endl;
1053 
1054  // print out the variable information
1055  if(osinstance->getVariableNumber() > 0)
1056  {
1057  for(i = 0; i < osinstance->getVariableNumber(); i++)
1058  {
1059  if(osinstance->getVariableNames() != NULL)
1060  outStr << "variable Names " << osinstance->getVariableNames()[i] << endl;
1061  if(osinstance->getVariableTypes() != NULL)
1062  outStr << "variable Types " << osinstance->getVariableTypes()[i] << endl;
1063  if(osinstance->getVariableLowerBounds() != NULL)
1064  outStr << "variable Lower Bounds " << osinstance->getVariableLowerBounds()[i] << endl;
1065  if(osinstance->getVariableUpperBounds() != NULL)
1066  outStr << "variable Upper Bounds " << osinstance->getVariableUpperBounds()[i] << endl;
1067  }
1068  }
1069 
1070  // print out objective function information
1071  if(osinstance->getVariableNumber() > 0 || osinstance->instanceData->objectives->obj != NULL || osinstance->instanceData->objectives->numberOfObjectives > 0)
1072  {
1073  if( osinstance->getObjectiveMaxOrMins()[0] == "min")
1074  outStr << "problem is a minimization" << endl;
1075  else
1076  outStr << "problem is a maximization" << endl;
1077  for(i = 0; i < osinstance->getVariableNumber(); i++)
1078  {
1079  outStr << "OBJ COEFFICIENT = " << osinstance->getDenseObjectiveCoefficients()[0][i] << endl;
1080  }
1081  }
1082  // print out constraint information
1083  if(osinstance->getConstraintNumber() > 0)
1084  {
1085  for(i = 0; i < osinstance->getConstraintNumber(); i++)
1086  {
1087  if(osinstance->getConstraintNames() != NULL)
1088  outStr << "row name = " << osinstance->getConstraintNames()[i] << endl;
1089  if(osinstance->getConstraintLowerBounds() != NULL)
1090  outStr << "row lower bound = " << osinstance->getConstraintLowerBounds()[i] << endl;
1091  if(osinstance->getConstraintUpperBounds() != NULL)
1092  outStr << "row upper bound = " << osinstance->getConstraintUpperBounds()[i] << endl;
1093  }
1094  }
1095 
1096  // print out linear constraint data
1097  outStr << endl;
1098  outStr << "number of nonzeros = " << osinstance->getLinearConstraintCoefficientNumber() << endl;
1099  for(i = 0; i <= osinstance->getVariableNumber(); i++)
1100  {
1101  outStr << "Start Value = "
1102  << osinstance->getLinearConstraintCoefficientsInColumnMajor()->starts[ i] << endl;
1103  }
1104  outStr << endl;
1105  for(i = 0; i < osinstance->getLinearConstraintCoefficientNumber(); i++)
1106  {
1107  outStr << "Index Value = "
1108  << osinstance->getLinearConstraintCoefficientsInColumnMajor()->indexes[i] << endl;
1109  outStr << "Nonzero Value = "
1110  << osinstance->getLinearConstraintCoefficientsInColumnMajor()->values[i] << endl;
1111  }
1112 
1113  // print out quadratic data
1114  outStr << "number of qterms = " << osinstance->getNumberOfQuadraticTerms() << endl;
1115  for(int i = 0; i < osinstance->getNumberOfQuadraticTerms(); i++)
1116  {
1117  outStr << "Row Index = " << osinstance->getQuadraticTerms()->rowIndexes[i] << endl;
1118  outStr << "Var Index 1 = " << osinstance->getQuadraticTerms()->varOneIndexes[i] << endl;
1119  outStr << "Var Index 2 = " << osinstance->getQuadraticTerms()->varTwoIndexes[i] << endl;
1120  outStr << "Coefficient = " << osinstance->getQuadraticTerms()->coefficients[i] << endl;
1121  }
1123 #endif
1124  return;
1125 } // end dataEchoCheck
1126 
1127 
1128 IpoptProblem::IpoptProblem(OSInstance *osinstance_, OSOption *osoption_, OSResult *osresult_, std::string* ipoptErrorMsg_)
1129 {
1130  osinstance = osinstance_;
1131  osoption = osoption_;
1132  osresult = osresult_;
1133  ipoptErrorMsg = ipoptErrorMsg_;
1134 }
1135 
1137 {
1138 
1139 }
1140 
const OSSmartPtr< OSOutput > osoutput
Definition: OSOutput.cpp:39
std::string os_dtoa_format(double x)
Definition: OSMathUtil.cpp:154
std::string OSgetVersionInfo()
OSOption * osoption
double os_strtod(const char *s00, char **se)
Definition: OSdtoa.cpp:2541
used for throwing exceptions.
Definition: OSErrorClass.h:32
std::string errormsg
errormsg is the error that is causing the exception to be thrown
Definition: OSErrorClass.h:42
the InitVarValue class.
Definition: OSOption.h:1160
double value
initial value
Definition: OSOption.h:1170
int idx
variable index
Definition: OSOption.h:1164
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.
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)
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.
IpoptProblem(OSInstance *osinstance_, OSOption *osoption_, OSResult *osresult_, std::string *ipoptErrorMsg_)
the IpoptProblemclass constructor
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.
virtual ~IpoptProblem()
the IpoptProblem class destructor
virtual bool get_nlp_info(Ipopt::Index &n, Ipopt::Index &m, Ipopt::Index &nnz_jac_g, Ipopt::Index &nnz_h_lag, IndexStyleEnum &index_style)
IPOpt specific methods for defining the nlp problem.
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 "values" is NULL) 2) The values of the jacobia...
virtual bool eval_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number &obj_value)
Method to return the objective value.
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)
Method to return the bounds for my problem.
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 "values" is NULL) 2) The valu...
virtual void finalize_solution(Ipopt::SolverReturn status, Ipopt::Index n, const Ipopt::Number *x, const Ipopt::Number *z_L, const Ipopt::Number *z_U, Ipopt::Index m, const Ipopt::Number *g, const Ipopt::Number *lambda, Ipopt::Number obj_value, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq)
This method is called when the algorithm is complete so the TNLP can store/write the solution.
virtual void setSolverOptions()
The implementation of the virtual functions.
virtual void solve()
solve results in an instance being read into the Ipopt data structures and optimize
IpoptSolver()
the IpoptSolver class constructor
~IpoptSolver()
the IpoptSolver class destructor
void dataEchoCheck()
use this for debugging, print out the instance that the solver thinks it has and compare this with th...
virtual void buildSolverInstance()
The implementation of the virtual functions.
The in-memory representation of an OSiL instance..
Definition: OSInstance.h:2263
The Option Class.
Definition: OSOption.h:3565
InitVarValue ** getInitVarValuesSparse()
Get the initial values associated with the variables in sparse form.
Definition: OSOption.cpp:2719
int getNumberOfInitVarValues()
Get the number of initial variable values.
Definition: OSOption.cpp:2051
std::vector< SolverOption * > getSolverOptions(std::string solver_name)
Get the options associated with a given solver.
Definition: OSOption.cpp:4508
int getNumberOfSolverOptions()
Get the number of solver options.
Definition: OSOption.cpp:2207
The Result Class.
Definition: OSResult.h:2549
bool setGeneralMessage(std::string message)
Set the general message.
bool setSolutionNumber(int number)
set the number of solutions.
Definition: OSResult.cpp:4740
bool setInstanceName(std::string instanceName)
Set instance name.
bool setObjectiveValuesDense(int solIdx, double *objectiveValues)
Set the [i]th optimization solution's objective values, where i equals the given solution index.
Definition: OSResult.cpp:5824
bool setNumberOfOtherVariableResults(int solIdx, int numberOfOtherVariableResults)
Set the [i]th optimization solution's other (non-standard/solver specific) variable-related results,...
Definition: OSResult.cpp:5236
bool setGeneralStatusType(std::string type)
Set the general status type, which can be: success, error, warning.
bool setObjectiveNumber(int objectiveNumber)
Set the objective number.
Definition: OSResult.cpp:4721
bool setPrimalVariableValuesDense(int solIdx, double *x)
Set the [i]th optimization solution's primal variable values, where i equals the given solution index...
Definition: OSResult.cpp:5001
bool setServiceName(std::string serviceName)
Set service name.
bool setSolverInvoked(std::string solverInvoked)
Set solver invoked.
Definition: OSResult.cpp:4155
bool setVariableNumber(int variableNumber)
Set the variable number.
Definition: OSResult.cpp:4712
bool setDualVariableValuesDense(int solIdx, double *y)
Set the [i]th optimization solution's dual variable values, where i equals the given solution index.
Definition: OSResult.cpp:6291
bool setSolutionMessage(int solIdx, std::string msg)
Set the [i]th optimization solution's message, where i equals the given solution index.
Definition: OSResult.cpp:4917
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 setAnOtherVariableResultSparse(int solIdx, int otherIdx, std::string name, std::string value, std::string description, int *idx, std::string *s, int n)
Set the [i]th optimization solution's other (non-standard/solver specific)variable-related results,...
bool setConstraintNumber(int constraintNumber)
Set the constraint number.
Definition: OSResult.cpp:4731
Used to read an OSiL string.
Definition: OSiLReader.h:38
Used to read an OSoL string.
Definition: OSoLReader.h:38
Take an OSResult object and write a string that validates against OSrL.
Definition: OSrLWriter.h:31
std::string writeOSrL(OSResult *theosresult)
create an osrl string from an OSResult object
Definition: OSrLWriter.cpp:45
The in-memory representation of a SparseHessianMatrix..
Definition: OSGeneral.h:377
int * hessRowIdx
hessRowIdx is an integer array of row indices in the range 0, ..., n - 1.
Definition: OSGeneral.h:394
int hessDimension
hessDimension is the number of nonzeros in each array.
Definition: OSGeneral.h:389
double * hessValues
hessValues is a double array of the Hessian values.
Definition: OSGeneral.h:404
int * hessColIdx
hessColIdx is an integer array of column indices in the range 0, ..., n - 1.
Definition: OSGeneral.h:399
a sparse Jacobian matrix data structure
Definition: OSGeneral.h:301
int * indexes
indexes holds an integer array of variable indices.
Definition: OSGeneral.h:335
int valueSize
valueSize is the dimension of the values array
Definition: OSGeneral.h:318
int * starts
starts holds an integer array of start elements, each start element points to the start of partials f...
Definition: OSGeneral.h:324
double * values
values holds a double array of nonzero partial derivatives
Definition: OSGeneral.h:340
const double OSDBL_MAX
Definition: OSParameters.h:93
@ ENUM_OUTPUT_LEVEL_debug
Definition: OSParameters.h:114
@ ENUM_OUTPUT_LEVEL_trace
Definition: OSParameters.h:115
@ ENUM_OUTPUT_LEVEL_error
Definition: OSParameters.h:110
@ ENUM_OUTPUT_LEVEL_summary
Definition: OSParameters.h:111
@ ENUM_OUTPUT_AREA_OSSolverInterfaces
Definition: OSParameters.h:145
OSResult * osresult