44 #pragma GCC diagnostic ignored "-Wshadow" 46 #include "IpoptConfig.h" 47 #include "IpIpoptApplication.hpp" 48 #include "IpIpoptCalculatedQuantities.hpp" 49 #include "IpSolveStatistics.hpp" 50 #include "IpJournalist.hpp" 51 #include "IpIpoptData.hpp" 52 #include "IpTNLPAdapter.hpp" 53 #include "IpOrigIpoptNLP.hpp" 54 #include "IpLapack.hpp" 56 #pragma GCC diagnostic warning "-Wshadow" 59 using namespace Ipopt;
61 #define NLPI_NAME "ipopt" 62 #define NLPI_DESC "Ipopt interface" 63 #define NLPI_PRIORITY 0 66 #define DEFAULT_PRINTLEVEL J_WARNING 68 #define DEFAULT_PRINTLEVEL J_STRONGWARNING 70 #define DEFAULT_MAXITER 3000 72 #define MAXPERTURB 0.01 73 #define FEASTOLFACTOR 0.05 75 #define DEFAULT_RANDSEED 71 115 std::string defoptions;
118 explicit SCIP_NlpiData(
154 storeintermediate(false), fastfail(false),
157 lastsolprimals(
NULL), lastsoldualcons(
NULL), lastsoldualvarlb(
NULL), lastsoldualvarub(
NULL),
158 lastniter(-1), lasttime(-1.0)
163 class ScipNLP :
public TNLP 172 int conv_lastrestoiter;
183 : nlpiproblem(nlpiproblem_), randnumgen(
NULL), approxhessian(
false)
185 assert(blkmem !=
NULL);
192 assert(randnumgen !=
NULL);
199 assert(nlpiproblem_ !=
NULL);
200 nlpiproblem = nlpiproblem_;
209 IndexStyleEnum& index_style
213 bool get_bounds_info(
223 bool get_starting_point(
236 bool get_variables_linearity(
238 LinearityType* var_types
242 bool get_constraints_linearity(
244 LinearityType* const_types
248 Index get_number_of_nonlinear_variables();
251 bool get_list_of_nonlinear_variables(
252 Index num_nonlin_vars,
253 Index* pos_nonlin_vars
257 bool get_var_con_metadata(
259 StringMetaDataMapType& var_string_md,
260 IntegerMetaDataMapType& var_integer_md,
261 NumericMetaDataMapType& var_numeric_md,
263 StringMetaDataMapType& con_string_md,
264 IntegerMetaDataMapType& con_integer_md,
265 NumericMetaDataMapType& con_numeric_md
321 const Number* lambda,
335 bool intermediate_callback(
343 Number regularization_size,
347 const IpoptData* ip_data,
348 IpoptCalculatedQuantities* ip_cq
352 void finalize_solution(
360 const Number* lambda,
362 const IpoptData* data,
363 IpoptCalculatedQuantities* cq
368 class ScipJournal :
public Ipopt::Journal {
376 Ipopt::EJournalLevel default_level,
379 : Ipopt::Journal(name, default_level),
380 messagehdlr(messagehdlr_)
387 Ipopt::EJournalCategory category,
388 Ipopt::EJournalLevel level,
392 if( level == J_ERROR )
403 Ipopt::EJournalCategory category,
404 Ipopt::EJournalLevel level,
409 if( level == J_ERROR )
419 void FlushBufferImpl() { }
428 assert(problem !=
NULL);
454 nlpiproblem->
ipopt->Options()->SetNumericValue(
"constr_viol_tol",
FEASTOLFACTOR * feastol);
456 nlpiproblem->
ipopt->Options()->SetNumericValue(
"acceptable_tol", feastol);
457 nlpiproblem->
ipopt->Options()->SetNumericValue(
"acceptable_constr_viol_tol", feastol);
480 assert(sourcenlpi !=
NULL);
481 assert(targetnlpi !=
NULL);
484 assert(sourcedata !=
NULL);
487 assert(*targetnlpi !=
NULL);
493 assert(targetdata !=
NULL);
495 targetdata->defoptions = sourcedata->defoptions;
510 assert(nlpi !=
NULL);
513 assert(data !=
NULL);
530 assert(nlpi !=
NULL);
547 assert(nlpi !=
NULL);
548 assert(problem !=
NULL);
551 assert(data !=
NULL);
554 if( *problem ==
NULL )
564 (*problem)->ipopt =
new IpoptApplication(
false);
565 if( IsNull((*problem)->ipopt) )
566 throw std::bad_alloc();
569 SmartPtr<Journal> jrnl =
new ScipJournal(
"console", J_ITERSUMMARY, data->messagehdlr);
571 throw std::bad_alloc();
572 jrnl->SetPrintLevel(J_DBG, J_NONE);
573 if( !(*problem)->ipopt->Jnlst()->AddJournal(jrnl) )
579 (*problem)->nlp =
new ScipNLP(*problem, data->blkmem);
580 if( IsNull((*problem)->nlp) )
581 throw std::bad_alloc();
583 catch( std::bad_alloc )
590 (*problem)->ipopt->RegOptions()->AddStringOption2(
"store_intermediate",
"whether to store the most feasible intermediate solutions",
"no",
"yes",
"",
"no",
"",
"useful when Ipopt looses a once found feasible solution and then terminates with an infeasible point");
593 (*problem)->ipopt->Options()->SetStringValue(
"mu_strategy",
"adaptive");
594 (*problem)->ipopt->Options()->SetStringValue(
"expect_infeasible_problem",
"yes");
595 (*problem)->ipopt->Options()->SetIntegerValue(
"max_iter",
DEFAULT_MAXITER);
596 (*problem)->ipopt->Options()->SetNumericValue(
"nlp_lower_bound_inf", -data->infinity,
false);
597 (*problem)->ipopt->Options()->SetNumericValue(
"nlp_upper_bound_inf", data->infinity,
false);
598 (*problem)->ipopt->Options()->SetNumericValue(
"diverging_iterates_tol", data->infinity,
false);
602 (*problem)->ipopt->Options()->SetStringValue(
"derivative_test",
"second-order");
607 if( data->defoptions.length() > 0 )
609 std::istringstream is(data->defoptions);
611 #if (IPOPT_VERSION_MAJOR > 3) || (IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR > 12) || (IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR == 12 && IPOPT_VERSION_RELEASE >= 5) 612 if( !(*problem)->ipopt->Options()->ReadFromStream(*(*problem)->ipopt->Jnlst(), is,
true) )
614 if( !(*problem)->ipopt->Options()->ReadFromStream(*(*problem)->ipopt->Jnlst(), is) )
617 SCIPerrorMessage(
"Error when modifiying Ipopt options using options string\n%s\n", data->defoptions.c_str());
623 if( (*problem)->ipopt->Initialize((*problem)->optfile) != Solve_Succeeded )
625 SCIPerrorMessage(
"Error during initialization of Ipopt using optionfile \"%s\"\n", (*problem)->optfile.c_str());
642 assert(nlpi !=
NULL);
643 assert(problem !=
NULL);
644 assert(*problem !=
NULL);
646 if( (*problem)->oracle !=
NULL )
673 assert(nlpi !=
NULL);
674 assert(problem !=
NULL);
676 return GetRawPtr(problem->nlp);
692 assert(nlpi !=
NULL);
693 assert(problem !=
NULL);
694 assert(problem->oracle !=
NULL);
698 problem->firstrun =
TRUE;
737 assert(nlpi !=
NULL);
738 assert(problem !=
NULL);
739 assert(problem->oracle !=
NULL);
743 nlininds, lininds, linvals,
744 nquadelems, quadelems,
745 exprvaridxs, exprtrees, names) );
747 problem->firstrun =
TRUE;
777 assert(nlpi !=
NULL);
778 assert(problem !=
NULL);
779 assert(problem->oracle !=
NULL);
782 constant, nlins, lininds, linvals,
783 nquadelems, quadelems,
784 exprvaridxs, exprtree) );
786 problem->firstrun =
TRUE;
807 assert(nlpi !=
NULL);
808 assert(problem !=
NULL);
809 assert(problem->oracle !=
NULL);
815 for( i = 0; i < nvars && !problem->firstrun; ++i )
817 problem->firstrun =
TRUE;
839 assert(nlpi !=
NULL);
840 assert(problem !=
NULL);
841 assert(problem->oracle !=
NULL);
864 assert(nlpi !=
NULL);
865 assert(problem !=
NULL);
866 assert(problem->oracle !=
NULL);
870 problem->firstrun =
TRUE;
891 assert(nlpi !=
NULL);
892 assert(problem !=
NULL);
893 assert(problem->oracle !=
NULL);
897 problem->firstrun =
TRUE;
919 assert(nlpi !=
NULL);
920 assert(problem !=
NULL);
921 assert(problem->oracle !=
NULL);
943 assert(nlpi !=
NULL);
944 assert(problem !=
NULL);
945 assert(problem->oracle !=
NULL);
964 assert(nlpi !=
NULL);
965 assert(problem !=
NULL);
966 assert(problem->oracle !=
NULL);
988 assert(nlpi !=
NULL);
989 assert(problem !=
NULL);
990 assert(problem->oracle !=
NULL);
1008 assert(nlpi !=
NULL);
1009 assert(problem !=
NULL);
1010 assert(problem->oracle !=
NULL);
1030 assert(nlpi !=
NULL);
1031 assert(problem !=
NULL);
1032 assert(problem->oracle !=
NULL);
1034 if( primalvalues !=
NULL )
1036 if( !problem->initguess )
1063 ApplicationReturnStatus status;
1065 assert(nlpi !=
NULL);
1066 assert(problem !=
NULL);
1067 assert(problem->oracle !=
NULL);
1069 assert(IsValid(problem->ipopt));
1070 assert(IsValid(problem->nlp));
1072 problem->nlp->setNLPIPROBLEM(problem);
1074 problem->lastniter = -1;
1075 problem->lasttime = -1.0;
1080 SmartPtr<SolveStatistics> stats;
1082 if( problem->firstrun )
1098 SCIPerrorMessage(
"Do not have expression interpreter that can compute function values and gradients. Cannot solve NLP with Ipopt.\n");
1107 problem->ipopt->Options()->SetStringValue(
"hessian_approximation",
"limited-memory");
1108 problem->nlp->approxhessian =
true;
1111 problem->nlp->approxhessian =
false;
1114 status = problem->ipopt->OptimizeTNLP(GetRawPtr(problem->nlp));
1118 status = problem->ipopt->ReOptimizeTNLP(GetRawPtr(problem->nlp));
1123 case Invalid_Problem_Definition:
1124 case Invalid_Option:
1125 case Unrecoverable_Exception:
1126 case NonIpopt_Exception_Thrown:
1127 case Internal_Error:
1128 SCIPerrorMessage(
"Ipopt returned with application return status %d\n", status);
1130 case Insufficient_Memory:
1133 case Invalid_Number_Detected:
1134 SCIPdebugMessage(
"Ipopt failed because of an invalid number in function or derivative value\n");
1141 stats = problem->ipopt->Statistics();
1142 if( IsValid(stats) )
1144 problem->lastniter = stats->IterationCount();
1145 problem->lasttime = stats->TotalCPUTime();
1148 catch( IpoptException& except )
1150 SCIPerrorMessage(
"Ipopt returned with exception: %s\n", except.Message().c_str());
1154 problem->firstrun =
FALSE;
1170 assert(nlpi !=
NULL);
1171 assert(problem !=
NULL);
1173 return problem->lastsolstat;
1187 assert(nlpi !=
NULL);
1188 assert(problem !=
NULL);
1190 return problem->lasttermstat;
1206 assert(nlpi !=
NULL);
1207 assert(problem !=
NULL);
1209 if( primalvalues !=
NULL )
1210 *primalvalues = problem->lastsolprimals;
1212 if( consdualvalues !=
NULL )
1213 *consdualvalues = problem->lastsoldualcons;
1215 if( varlbdualvalues !=
NULL )
1216 *varlbdualvalues = problem->lastsoldualvarlb;
1218 if( varubdualvalues !=
NULL )
1219 *varubdualvalues = problem->lastsoldualvarub;
1237 assert(nlpi !=
NULL);
1238 assert(problem !=
NULL);
1313 assert(nlpi !=
NULL);
1314 assert(ival !=
NULL);
1315 assert(problem !=
NULL);
1316 assert(IsValid(problem->ipopt));
1330 problem->ipopt->Options()->GetIntegerValue(
"print_level", printlevel,
"");
1331 if( printlevel <= J_STRONGWARNING )
1333 else if( printlevel >= J_DETAILED )
1334 *ival = printlevel - J_ITERSUMMARY + 1;
1348 SCIPerrorMessage(
"relative objective tolerance parameter is of type real.\n");
1366 problem->ipopt->Options()->GetIntegerValue(
"max_iter", *ival,
"");
1384 *ival = problem->fastfail ? 1 : 0;
1409 assert(nlpi !=
NULL);
1410 assert(problem !=
NULL);
1411 assert(IsValid(problem->ipopt));
1417 if( ival == 0 || ival == 1 )
1422 assert(data !=
NULL);
1424 SCIPmessagePrintWarning(data->messagehdlr,
"from scratch parameter not supported by Ipopt interface yet. Ignored.\n");
1428 SCIPerrorMessage(
"Value %d for parameter from scratch out of range {0, 1}\n", ival);
1439 problem->ipopt->Options()->SetIntegerValue(
"print_level", J_STRONGWARNING);
1442 problem->ipopt->Options()->SetIntegerValue(
"print_level", J_ITERSUMMARY);
1445 problem->ipopt->Options()->SetIntegerValue(
"print_level", J_DETAILED);
1450 problem->ipopt->Options()->SetIntegerValue(
"print_level",
MIN(J_ITERSUMMARY + (ival-1), J_ALL));
1455 SCIPerrorMessage(
"Value %d for parameter from verbosity level out of range {0, 1, 2}\n", ival);
1470 SCIPerrorMessage(
"relative objective tolerance parameter is of type real.\n");
1490 problem->ipopt->Options()->SetIntegerValue(
"max_iter", ival);
1494 SCIPerrorMessage(
"Value %d for parameter iteration limit is negative\n", ival);
1514 if( ival == 0 || ival == 1 )
1516 problem->fastfail = (bool)ival;
1517 problem->storeintermediate = (bool)ival;
1521 SCIPerrorMessage(
"Value %d for parameter fastfail out of range {0, 1}\n", ival);
1551 assert(nlpi !=
NULL);
1552 assert(dval !=
NULL);
1572 problem->ipopt->Options()->GetNumericValue(
"acceptable_constr_viol_tol", *dval,
"");
1578 problem->ipopt->Options()->GetNumericValue(
"dual_inf_tol", *dval,
"");
1597 assert(data !=
NULL);
1598 *dval = data->infinity;
1611 problem->ipopt->Options()->GetNumericValue(
"max_cpu_time", *dval,
"");
1648 assert(nlpi !=
NULL);
1674 SCIPerrorMessage(
"Value %g for parameter feasibility tolerance is negative\n", dval);
1684 problem->ipopt->Options()->SetNumericValue(
"dual_inf_tol", dval);
1688 SCIPerrorMessage(
"Value %g for parameter relative objective tolerance is negative\n", dval);
1699 assert(data !=
NULL);
1701 SCIPmessagePrintWarning(data->messagehdlr,
"Parameter lower objective limit not supported by Ipopt interface yet. Ignored.\n");
1711 problem->ipopt->Options()->SetNumericValue(
"diverging_iterates_tol", dval);
1712 problem->ipopt->Options()->SetNumericValue(
"nlp_lower_bound_inf", -dval);
1713 problem->ipopt->Options()->SetNumericValue(
"nlp_upper_bound_inf", dval);
1719 assert(data !=
NULL);
1720 data->infinity = dval;
1735 problem->ipopt->Options()->SetNumericValue(
"max_cpu_time", dval);
1781 assert(nlpi !=
NULL);
1782 assert(problem !=
NULL);
1836 if( !problem->optfile.empty() )
1837 *sval = problem->optfile.c_str();
1870 assert(nlpi !=
NULL);
1871 assert(problem !=
NULL);
1926 problem->optfile = sval;
1928 problem->optfile.clear();
1930 if( problem->ipopt->Initialize(problem->optfile) != Solve_Succeeded )
1932 SCIPerrorMessage(
"Error initializing Ipopt using optionfile \"%s\"\n", problem->optfile.c_str());
1935 problem->ipopt->Options()->GetBoolValue(
"store_intermediate", problem->storeintermediate,
"");
1936 problem->firstrun =
TRUE;
1968 assert(nlpi !=
NULL);
1971 assert(nlpidata !=
NULL);
1973 nlpidata->messagehdlr = messagehdlr;
1986 assert(blkmem !=
NULL);
1987 assert(nlpi !=
NULL);
1993 nlpiCopyIpopt, nlpiFreeIpopt, nlpiGetSolverPointerIpopt,
1994 nlpiCreateProblemIpopt, nlpiFreeProblemIpopt, nlpiGetProblemPointerIpopt,
1995 nlpiAddVarsIpopt, nlpiAddConstraintsIpopt, nlpiSetObjectiveIpopt,
1996 nlpiChgVarBoundsIpopt, nlpiChgConsSidesIpopt, nlpiDelVarSetIpopt, nlpiDelConstraintSetIpopt,
1997 nlpiChgLinearCoefsIpopt, nlpiChgQuadraticCoefsIpopt, nlpiChgExprtreeIpopt, nlpiChgNonlinCoefIpopt,
1998 nlpiChgObjConstantIpopt, nlpiSetInitialGuessIpopt, nlpiSolveIpopt, nlpiGetSolstatIpopt, nlpiGetTermstatIpopt,
1999 nlpiGetSolutionIpopt, nlpiGetStatisticsIpopt,
2000 nlpiGetWarmstartSizeIpopt, nlpiGetWarmstartMemoIpopt, nlpiSetWarmstartMemoIpopt,
2001 nlpiGetIntParIpopt, nlpiSetIntParIpopt, nlpiGetRealParIpopt, nlpiSetRealParIpopt,
2002 nlpiGetStringParIpopt, nlpiSetStringParIpopt, nlpiSetMessageHdlrIpopt,
2011 return "Ipopt " IPOPT_VERSION;
2017 return "Interior Point Optimizer developed by A. Waechter et.al. (www.coin-or.org/Ipopt)";
2031 assert(nlpiproblem !=
NULL);
2033 return (
void*)GetRawPtr(nlpiproblem->
ipopt);
2041 assert(nlpiproblem !=
NULL);
2043 return nlpiproblem->
oracle;
2052 const char* optionsstring
2057 assert(nlpi !=
NULL);
2060 assert(data !=
NULL);
2062 data->defoptions = optionsstring;
2066 bool ScipNLP::get_nlp_info(
2071 IndexStyleEnum& index_style
2077 assert(nlpiproblem !=
NULL);
2078 assert(nlpiproblem->oracle !=
NULL);
2086 assert(offset !=
NULL);
2087 nnz_jac_g = offset[m];
2089 if( !approxhessian )
2094 assert(offset !=
NULL);
2095 nnz_h_lag = offset[n];
2102 index_style = TNLP::C_STYLE;
2108 bool ScipNLP::get_bounds_info(
2117 assert(nlpiproblem !=
NULL);
2118 assert(nlpiproblem->oracle !=
NULL);
2129 for(
int i = 0; i < n; ++i )
2130 assert(x_l[i] <= x_u[i]);
2133 for(
int i = 0; i < m; ++i )
2137 assert(g_l[i] <= g_u[i]);
2144 bool ScipNLP::get_starting_point(
2156 assert(nlpiproblem !=
NULL);
2157 assert(nlpiproblem->oracle !=
NULL);
2164 if( nlpiproblem->initguess )
2172 SCIPdebugMessage(
"Ipopt started without intial primal values; make up starting guess by projecting 0 onto variable bounds\n");
2174 for(
int i = 0; i < n; ++i )
2187 if( init_z || init_lambda )
2194 bool ScipNLP::get_variables_linearity(
2196 LinearityType* var_types
2199 assert(nlpiproblem !=
NULL);
2200 assert(nlpiproblem->oracle !=
NULL);
2204 for(
int i = 0; i < n; ++i )
2211 bool ScipNLP::get_constraints_linearity(
2213 LinearityType* const_types
2218 assert(nlpiproblem !=
NULL);
2219 assert(nlpiproblem->oracle !=
NULL);
2223 for( i = 0; i < m; ++i )
2230 Index ScipNLP::get_number_of_nonlinear_variables()
2235 assert(nlpiproblem !=
NULL);
2236 assert(nlpiproblem->oracle !=
NULL);
2241 for(
int i = 0; i < n; ++i )
2249 bool ScipNLP::get_list_of_nonlinear_variables(
2250 Index num_nonlin_vars,
2251 Index* pos_nonlin_vars
2257 assert(nlpiproblem !=
NULL);
2258 assert(nlpiproblem->oracle !=
NULL);
2263 for(
int i = 0; i < n; ++i )
2266 assert(count < num_nonlin_vars);
2267 pos_nonlin_vars[count++] = i;
2270 assert(count == num_nonlin_vars);
2276 bool ScipNLP::get_var_con_metadata(
2278 StringMetaDataMapType& var_string_md,
2279 IntegerMetaDataMapType& var_integer_md,
2280 NumericMetaDataMapType& var_numeric_md,
2282 StringMetaDataMapType& con_string_md,
2283 IntegerMetaDataMapType& con_integer_md,
2284 NumericMetaDataMapType& con_numeric_md
2287 assert(nlpiproblem !=
NULL);
2288 assert(nlpiproblem->oracle !=
NULL);
2293 if( varnames !=
NULL )
2295 std::vector<std::string>& varnamesvec(var_string_md[
"idx_names"]);
2296 varnamesvec.reserve(n);
2297 for(
int i = 0; i < n; ++i )
2299 if( varnames[i] !=
NULL )
2301 varnamesvec.push_back(varnames[i]);
2306 sprintf(buffer,
"nlpivar%8d", i);
2307 varnamesvec.push_back(buffer);
2312 std::vector<std::string>& consnamesvec(con_string_md[
"idx_names"]);
2313 consnamesvec.reserve(m);
2314 for(
int i = 0; i < m; ++i )
2323 sprintf(buffer,
"nlpicons%8d", i);
2324 consnamesvec.push_back(buffer);
2332 bool ScipNLP::eval_f(
2339 assert(nlpiproblem !=
NULL);
2340 assert(nlpiproblem->oracle !=
NULL);
2348 bool ScipNLP::eval_grad_f(
2357 assert(nlpiproblem !=
NULL);
2358 assert(nlpiproblem->oracle !=
NULL);
2366 bool ScipNLP::eval_g(
2374 assert(nlpiproblem !=
NULL);
2375 assert(nlpiproblem->oracle !=
NULL);
2386 bool ScipNLP::eval_jac_g(
2397 assert(nlpiproblem !=
NULL);
2398 assert(nlpiproblem->oracle !=
NULL);
2403 if( values ==
NULL )
2405 const int* jacoffset;
2410 assert(iRow !=
NULL);
2411 assert(jCol !=
NULL);
2416 assert(jacoffset[0] == 0);
2417 assert(jacoffset[m] == nele_jac);
2419 for( i = 0; i < m; ++i )
2420 for( ; j < jacoffset[i+1]; ++j )
2438 bool ScipNLP::eval_h(
2444 const Number* lambda,
2452 assert(nlpiproblem !=
NULL);
2453 assert(nlpiproblem->oracle !=
NULL);
2458 if( values ==
NULL )
2460 const int* heslagoffset;
2461 const int* heslagcol;
2465 assert(iRow !=
NULL);
2466 assert(jCol !=
NULL);
2471 assert(heslagoffset[0] == 0);
2472 assert(heslagoffset[n] == nele_hess);
2473 j = heslagoffset[0];
2474 for( i = 0; i < n; ++i )
2475 for( ; j < heslagoffset[i+1]; ++j )
2493 bool ScipNLP::intermediate_callback(
2501 Number regularization_size,
2505 const IpoptData* ip_data,
2506 IpoptCalculatedQuantities* ip_cq
2509 if( nlpiproblem->storeintermediate && mode == RegularMode && inf_pr < nlpiproblem->lastsolinfeas )
2511 Ipopt::TNLPAdapter* tnlp_adapter;
2513 tnlp_adapter =
NULL;
2516 Ipopt::OrigIpoptNLP* orignlp;
2518 orignlp =
dynamic_cast<OrigIpoptNLP*
>(GetRawPtr(ip_cq->GetIpoptNLP()));
2519 if( orignlp !=
NULL )
2520 tnlp_adapter =
dynamic_cast<TNLPAdapter*
>(GetRawPtr(orignlp->nlp()));
2523 if( tnlp_adapter !=
NULL && ip_data !=
NULL && IsValid(ip_data->curr()) )
2525 SCIPdebugMessage(
"update lastsol: inf_pr old = %g -> new = %g\n", nlpiproblem->lastsolinfeas, inf_pr);
2527 if( nlpiproblem->lastsolprimals ==
NULL )
2529 assert(nlpiproblem->lastsoldualcons ==
NULL);
2530 assert(nlpiproblem->lastsoldualvarlb ==
NULL);
2531 assert(nlpiproblem->lastsoldualvarub ==
NULL);
2542 assert(IsValid(ip_data->curr()->x()));
2543 tnlp_adapter->ResortX(*ip_data->curr()->x(), nlpiproblem->lastsolprimals);
2544 nlpiproblem->lastsolinfeas = inf_pr;
2546 assert(IsValid(ip_data->curr()->y_c()));
2547 assert(IsValid(ip_data->curr()->y_d()));
2548 tnlp_adapter->ResortG(*ip_data->curr()->y_c(), *ip_data->curr()->y_d(), nlpiproblem->lastsoldualcons);
2553 assert(IsValid(ip_data->curr()->z_L()));
2554 assert(IsValid(ip_data->curr()->z_U()));
2555 tnlp_adapter->ResortBnds(*ip_data->curr()->z_L(), nlpiproblem->lastsoldualvarlb, *ip_data->curr()->z_U(), nlpiproblem->lastsoldualvarub);
2561 if( nlpiproblem->fastfail )
2567 conv_lastrestoiter = -1;
2569 else if( mode == RestorationPhaseMode )
2571 conv_lastrestoiter = iter;
2573 else if( conv_lastrestoiter == iter-1 )
2595 if( inf_pr <= conv_prtarget[i] )
2604 else if( iter >= conv_iterlim[i] )
2607 SCIPdebugMessage(
"convcheck %d: inf_pr = %e > target %e; inf_du = %e target %e: ",
2608 i, inf_pr, conv_prtarget[i], inf_du, conv_dutarget[i]);
2614 SCIPdebugPrintf(
"continue, because restoration phase only %d iters ago\n", iter - conv_lastrestoiter);
2616 else if( mode == RegularMode && inf_du <= conv_dutarget[i] && iter < conv_iterlim[i] +
convcheck_maxiter[i] )
2619 SCIPdebugPrintf(
"continue, because dual infeas. red. sufficient and only %d iters above limit\n", iter - conv_iterlim[i]);
2635 void ScipNLP::finalize_solution(
2636 SolverReturn status,
2643 const Number* lambda,
2645 const IpoptData* data,
2646 IpoptCalculatedQuantities* cq
2649 assert(nlpiproblem !=
NULL);
2650 assert(nlpiproblem->oracle !=
NULL);
2655 bool check_feasibility =
false;
2664 case STOP_AT_ACCEPTABLE_POINT:
2666 case FEASIBLE_POINT_FOUND:
2672 case MAXITER_EXCEEDED:
2673 check_feasibility =
true;
2678 case CPUTIME_EXCEEDED:
2679 check_feasibility =
true;
2684 case STOP_AT_TINY_STEP:
2685 case RESTORATION_FAILURE:
2686 case ERROR_IN_STEP_COMPUTATION:
2687 check_feasibility =
true;
2692 case LOCAL_INFEASIBILITY:
2694 check_feasibility =
true;
2699 case DIVERGING_ITERATES:
2704 case INVALID_NUMBER_DETECTED:
2709 case USER_REQUESTED_STOP:
2710 check_feasibility =
true;
2715 case TOO_FEW_DEGREES_OF_FREEDOM:
2716 case INTERNAL_ERROR:
2717 case INVALID_OPTION:
2728 SCIPerrorMessage(
"Ipopt returned with unknown solution status %d\n", status);
2738 assert(nlpiproblem->lastsolprimals !=
NULL);
2739 assert(nlpiproblem->lastsoldualcons !=
NULL);
2740 assert(nlpiproblem->lastsoldualvarlb !=
NULL);
2741 assert(nlpiproblem->lastsoldualvarub !=
NULL);
2744 Number constrvioltol;
2745 nlpiproblem->ipopt->Options()->GetNumericValue(
"acceptable_constr_viol_tol", constrvioltol,
"");
2746 if( nlpiproblem->lastsolinfeas <= constrvioltol )
2751 SCIPdebugMessage(
"drop Ipopt's final point and report intermediate locally %sfeasible solution with infeas %g instead (acceptable: %g)\n",
2757 assert(lambda !=
NULL);
2758 assert(z_L !=
NULL);
2759 assert(z_U !=
NULL);
2761 if( nlpiproblem->lastsolprimals ==
NULL )
2763 assert(nlpiproblem->lastsoldualcons ==
NULL);
2764 assert(nlpiproblem->lastsoldualvarlb ==
NULL);
2765 assert(nlpiproblem->lastsoldualvarub ==
NULL);
2771 if( nlpiproblem->lastsolprimals ==
NULL || nlpiproblem->lastsoldualcons ==
NULL ||
2772 nlpiproblem->lastsoldualvarlb ==
NULL || nlpiproblem->lastsoldualvarub ==
NULL )
2785 if( check_feasibility && cq !=
NULL )
2788 Number constrvioltol;
2790 constrviol = cq->curr_constraint_violation();
2792 nlpiproblem->ipopt->Options()->GetNumericValue(
"acceptable_constr_viol_tol", constrvioltol,
"");
2793 if( constrviol <= constrvioltol )
2814 IpLapackDsyev(computeeigenvectors, N, a, N, w, info);
2818 SCIPerrorMessage(
"There was an error when calling DSYEV. INFO = %d\n", info);
2843 assert(success !=
NULL);
2849 IpLapackDgetrf(N, Acopy, pivotcopy, N, info);
2853 SCIPerrorMessage(
"There was an error when calling Dgetrf. INFO = %d\n", info);
2861 IpLapackDgetrs(N, 1, Acopy, N, pivotcopy, bcopy, N);
2893 assert(success !=
NULL);
2911 IpLapackDgetrf(N, Acopy, pivotcopy, N, info);
2915 SCIPerrorMessage(
"There was an error when calling Dgetrf. INFO = %d\n", info);
2923 IpLapackDgetrs(N, 1, Acopy, N, pivotcopy, bcopy, N);
SCIP_Bool SCIPisIpoptAvailableIpopt(void)
SCIP_RETCODE SCIPrandomCreate(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem, unsigned int initialseed)
SCIP_RETCODE SCIPnlpiOracleEvalConstraintValues(SCIP_NLPIORACLE *oracle, const SCIP_Real *x, SCIP_Real *convals)
enum SCIP_NlpTermStat SCIP_NLPTERMSTAT
void * SCIPgetNlpiOracleIpopt(SCIP_NLPIPROBLEM *nlpiproblem)
SCIP_Real * lastsoldualvarlb
const SCIP_Real * SCIPnlpiOracleGetVarUbs(SCIP_NLPIORACLE *oracle)
#define BMSfreeMemoryArrayNull(ptr)
methods to interpret (evaluate) an expression tree "fast"
SCIP_RETCODE SCIPnlpiOracleGetJacobianSparsity(SCIP_NLPIORACLE *oracle, const int **offset, const int **col)
SCIP_EXPRINTCAPABILITY SCIPnlpiOracleGetEvalCapability(SCIP_NLPIORACLE *oracle)
void SCIPsetModifiedDefaultSettingsIpopt(SCIP_NLPI *nlpi, const char *optionsstring)
SCIP_RETCODE SCIPnlpiOracleGetHessianLagSparsity(SCIP_NLPIORACLE *oracle, const int **offset, const int **col)
SCIP_NLPSOLSTAT lastsolstat
static SCIP_DECL_NLPICREATEPROBLEM(nlpiCreateProblemIpopt)
int SCIPnlpiOracleGetNVars(SCIP_NLPIORACLE *oracle)
static SCIP_DECL_NLPIGETWARMSTARTMEMO(nlpiGetWarmstartMemoIpopt)
static SCIP_DECL_NLPIFREEPROBLEM(nlpiFreeProblemIpopt)
struct SCIP_NlpiProblem SCIP_NLPIPROBLEM
internal methods for NLPI solver interfaces
SCIP_RETCODE SCIPnlpiOracleSetObjective(SCIP_NLPIORACLE *oracle, const SCIP_Real constant, int nlin, const int *lininds, const SCIP_Real *linvals, int nquadelems, const SCIP_QUADELEM *quadelems, const int *exprvaridxs, const SCIP_EXPRTREE *exprtree)
methods to store an NLP and request function, gradient, and hessian values
SCIP_Real SCIPnlpiOracleGetConstraintLhs(SCIP_NLPIORACLE *oracle, int considx)
static SCIP_DECL_NLPIFREE(nlpiFreeIpopt)
static SCIP_DECL_NLPIGETSOLUTION(nlpiGetSolutionIpopt)
enum SCIP_Retcode SCIP_RETCODE
#define DEFAULT_PRINTLEVEL
SCIP_RETCODE SCIPnlpiOracleEvalObjectiveValue(SCIP_NLPIORACLE *oracle, const SCIP_Real *x, SCIP_Real *objval)
static SCIP_DECL_NLPIGETINTPAR(nlpiGetIntParIpopt)
#define BMSallocMemoryArray(ptr, num)
static SCIP_DECL_NLPISETINITIALGUESS(nlpiSetInitialGuessIpopt)
void SCIPmessageVPrintInfo(SCIP_MESSAGEHDLR *messagehdlr, const char *formatstr, va_list ap)
#define SCIP_CALL_ABORT_QUIET(x)
static SCIP_DECL_NLPISETINTPAR(nlpiSetIntParIpopt)
SCIP_RETCODE SCIPnlpiSetMessageHdlr(SCIP_NLPI *nlpi, SCIP_MESSAGEHDLR *messagehdlr)
unsigned int SCIP_EXPRINTCAPABILITY
SCIP_RETCODE SCIPnlpiOracleEvalObjectiveGradient(SCIP_NLPIORACLE *oracle, const SCIP_Real *x, SCIP_Bool isnewx, SCIP_Real *objval, SCIP_Real *objgrad)
static SCIP_DECL_NLPISETOBJECTIVE(nlpiSetObjectiveIpopt)
SCIP_RETCODE SCIPnlpiOracleDelConsSet(SCIP_NLPIORACLE *oracle, int *delstats)
SCIP_RETCODE SCIPnlpiOracleChgObjConstant(SCIP_NLPIORACLE *oracle, SCIP_Real objconstant)
static SCIP_DECL_NLPISETSTRINGPAR(nlpiSetStringParIpopt)
int SCIPnlpiOracleGetNConstraints(SCIP_NLPIORACLE *oracle)
SCIP_Real * lastsoldualvarub
void SCIPmessageVPrintError(const char *formatstr, va_list ap)
void SCIPrandomFree(SCIP_RANDNUMGEN **randnumgen)
static SCIP_DECL_NLPIGETSTATISTICS(nlpiGetStatisticsIpopt)
SCIP_DECL_NLPIGETPROBLEMPOINTER(nlpiGetProblemPointerIpopt)
int SCIPnlpiOracleGetConstraintDegree(SCIP_NLPIORACLE *oracle, int considx)
const char * SCIPgetSolverNameIpopt(void)
#define BMSfreeMemoryArray(ptr)
SCIP_RETCODE SCIPnlpiOracleChgExprtree(SCIP_NLPIORACLE *oracle, int considx, const int *exprvaridxs, const SCIP_EXPRTREE *exprtree)
static SCIP_DECL_NLPICHGOBJCONSTANT(nlpiChgObjConstantIpopt)
SCIP_RETCODE SCIPnlpiOracleCreate(BMS_BLKMEM *blkmem, SCIP_NLPIORACLE **oracle)
void SCIPmessagePrintError(const char *formatstr,...)
const SCIP_Real * SCIPnlpiOracleGetVarLbs(SCIP_NLPIORACLE *oracle)
SCIP_RETCODE SCIPnlpiOracleChgVarBounds(SCIP_NLPIORACLE *oracle, int nvars, const int *indices, const SCIP_Real *lbs, const SCIP_Real *ubs)
struct SCIP_NlpiData SCIP_NLPIDATA
enum SCIP_NlpSolStat SCIP_NLPSOLSTAT
static SCIP_DECL_NLPICHGQUADCOEFS(nlpiChgQuadraticCoefsIpopt)
static SCIP_DECL_NLPICHGNONLINCOEF(nlpiChgNonlinCoefIpopt)
SCIP_RETCODE SCIPnlpiOracleAddVars(SCIP_NLPIORACLE *oracle, int nvars, const SCIP_Real *lbs, const SCIP_Real *ubs, const char **varnames)
static SCIP_DECL_NLPIGETREALPAR(nlpiGetRealParIpopt)
void SCIPmessagePrintWarning(SCIP_MESSAGEHDLR *messagehdlr, const char *formatstr,...)
static void invalidateSolution(SCIP_NLPIPROBLEM *problem)
SCIP_Real * lastsolprimals
#define SCIP_DEFAULT_FEASTOL
static SCIP_DECL_NLPICHGVARBOUNDS(nlpiChgVarBoundsIpopt)
void SCIPmessagePrintInfo(SCIP_MESSAGEHDLR *messagehdlr, const char *formatstr,...)
SCIP_EXPRINTCAPABILITY SCIPexprintGetCapability(void)
static SCIP_DECL_NLPICOPY(nlpiCopyIpopt)
SCIP_RETCODE LapackDsyev(SCIP_Bool computeeigenvectors, int N, SCIP_Real *a, SCIP_Real *w)
SCIP_Real SCIPnlpiOracleGetConstraintRhs(SCIP_NLPIORACLE *oracle, int considx)
SCIP_Real SCIPnlpiOracleGetInfinity(SCIP_NLPIORACLE *oracle)
#define BMSduplicateMemoryArray(ptr, source, num)
SCIP_RETCODE SCIPnlpiOracleFree(SCIP_NLPIORACLE **oracle)
static const int convcheck_nchecks
methods for catching the user CTRL-C interrupt
SmartPtr< IpoptApplication > ipopt
SCIP_RETCODE SCIPnlpiCreate(SCIP_NLPI **nlpi, const char *name, const char *description, int priority, SCIP_DECL_NLPICOPY((*nlpicopy)), SCIP_DECL_NLPIFREE((*nlpifree)), SCIP_DECL_NLPIGETSOLVERPOINTER((*nlpigetsolverpointer)), SCIP_DECL_NLPICREATEPROBLEM((*nlpicreateproblem)), SCIP_DECL_NLPIFREEPROBLEM((*nlpifreeproblem)), SCIP_DECL_NLPIGETPROBLEMPOINTER((*nlpigetproblempointer)), SCIP_DECL_NLPIADDVARS((*nlpiaddvars)), SCIP_DECL_NLPIADDCONSTRAINTS((*nlpiaddconstraints)), SCIP_DECL_NLPISETOBJECTIVE((*nlpisetobjective)), SCIP_DECL_NLPICHGVARBOUNDS((*nlpichgvarbounds)), SCIP_DECL_NLPICHGCONSSIDES((*nlpichgconssides)), SCIP_DECL_NLPIDELVARSET((*nlpidelvarset)), SCIP_DECL_NLPIDELCONSSET((*nlpidelconsset)), SCIP_DECL_NLPICHGLINEARCOEFS((*nlpichglinearcoefs)), SCIP_DECL_NLPICHGQUADCOEFS((*nlpichgquadcoefs)), SCIP_DECL_NLPICHGEXPRTREE((*nlpichgexprtree)), SCIP_DECL_NLPICHGNONLINCOEF((*nlpichgnonlincoef)), SCIP_DECL_NLPICHGOBJCONSTANT((*nlpichgobjconstant)), SCIP_DECL_NLPISETINITIALGUESS((*nlpisetinitialguess)), SCIP_DECL_NLPISOLVE((*nlpisolve)), SCIP_DECL_NLPIGETSOLSTAT((*nlpigetsolstat)), SCIP_DECL_NLPIGETTERMSTAT((*nlpigettermstat)), SCIP_DECL_NLPIGETSOLUTION((*nlpigetsolution)), SCIP_DECL_NLPIGETSTATISTICS((*nlpigetstatistics)), SCIP_DECL_NLPIGETWARMSTARTSIZE((*nlpigetwarmstartsize)), SCIP_DECL_NLPIGETWARMSTARTMEMO((*nlpigetwarmstartmemo)), SCIP_DECL_NLPISETWARMSTARTMEMO((*nlpisetwarmstartmemo)), SCIP_DECL_NLPIGETINTPAR((*nlpigetintpar)), SCIP_DECL_NLPISETINTPAR((*nlpisetintpar)), SCIP_DECL_NLPIGETREALPAR((*nlpigetrealpar)), SCIP_DECL_NLPISETREALPAR((*nlpisetrealpar)), SCIP_DECL_NLPIGETSTRINGPAR((*nlpigetstringpar)), SCIP_DECL_NLPISETSTRINGPAR((*nlpisetstringpar)), SCIP_DECL_NLPISETMESSAGEHDLR((*nlpisetmessagehdlr)), SCIP_NLPIDATA *nlpidata)
public data structures and miscellaneous methods
#define SCIP_EXPRINTCAPABILITY_HESSIAN
static SCIP_DECL_NLPISETWARMSTARTMEMO(nlpiSetWarmstartMemoIpopt)
SCIP_Bool SCIPinterrupted(void)
SCIP_RETCODE SCIPnlpiOracleSetProblemName(SCIP_NLPIORACLE *oracle, const char *name)
static void setFeastol(SCIP_NLPIPROBLEM *nlpiproblem, SCIP_Real feastol)
SCIP_RETCODE SCIPnlpiOracleAddConstraints(SCIP_NLPIORACLE *oracle, int nconss, const SCIP_Real *lhss, const SCIP_Real *rhss, const int *nlininds, int *const *lininds, SCIP_Real *const *linvals, const int *nquadelems, SCIP_QUADELEM *const *quadelems, int *const *exprvaridxs, SCIP_EXPRTREE *const *exprtrees, const char **consnames)
static SCIP_DECL_NLPICHGLINEARCOEFS(nlpiChgLinearCoefsIpopt)
void SCIPnlpStatisticsSetNIterations(SCIP_NLPSTATISTICS *statistics, int niterations)
static const int convcheck_startiter
static SCIP_DECL_NLPIGETSOLSTAT(nlpiGetSolstatIpopt)
void SCIPnlpStatisticsSetTotalTime(SCIP_NLPSTATISTICS *statistics, SCIP_Real totaltime)
static SCIP_DECL_NLPIGETTERMSTAT(nlpiGetTermstatIpopt)
SCIP_RETCODE SCIPnlpiOracleChgLinearCoefs(SCIP_NLPIORACLE *oracle, int considx, int nentries, const int *varidxs, const SCIP_Real *newcoefs)
#define BMScopyMemoryArray(ptr, source, num)
static SCIP_DECL_NLPIADDCONSTRAINTS(nlpiAddConstraintsIpopt)
SCIP_RETCODE SCIPnlpiOracleChgQuadCoefs(SCIP_NLPIORACLE *oracle, int considx, int nquadelems, const SCIP_QUADELEM *quadelems)
SCIP_RETCODE SCIPcreateNlpSolverIpopt(BMS_BLKMEM *blkmem, SCIP_NLPI **nlpi)
SCIP_RETCODE SCIPnlpiOracleChgConsSides(SCIP_NLPIORACLE *oracle, int nconss, const int *indices, const SCIP_Real *lhss, const SCIP_Real *rhss)
SCIP_Real SCIPrandomGetReal(SCIP_RANDNUMGEN *randnumgen, SCIP_Real minrandval, SCIP_Real maxrandval)
SCIP_RETCODE SCIPnlpiOracleDelVarSet(SCIP_NLPIORACLE *oracle, int *delstats)
static SCIP_DECL_NLPIGETSOLVERPOINTER(nlpiGetSolverPointerIpopt)
SCIP_RETCODE SCIPsolveLinearProb(int N, SCIP_Real *A, SCIP_Real *b, SCIP_Real *x, SCIP_Bool *success)
char * SCIPnlpiOracleGetConstraintName(SCIP_NLPIORACLE *oracle, int considx)
#define SCIP_DEFAULT_INFINITY
#define SCIP_EXPRINTCAPABILITY_FUNCVALUE
void * SCIPgetIpoptApplicationPointerIpopt(SCIP_NLPIPROBLEM *nlpiproblem)
SCIP_RETCODE SCIPnlpiOracleChgExprParam(SCIP_NLPIORACLE *oracle, int considx, int paramidx, SCIP_Real paramval)
int SCIPnlpiOracleGetVarDegree(SCIP_NLPIORACLE *oracle, int varidx)
SCIP_NLPIDATA * SCIPnlpiGetData(SCIP_NLPI *nlpi)
static SCIP_DECL_NLPIGETWARMSTARTSIZE(nlpiGetWarmstartSizeIpopt)
SCIP_RETCODE SCIPnlpiOracleEvalHessianLag(SCIP_NLPIORACLE *oracle, const SCIP_Real *x, SCIP_Bool isnewx, SCIP_Real objfactor, const SCIP_Real *lambda, SCIP_Real *hessian)
const char * SCIPgetSolverDescIpopt(void)
static SCIP_DECL_NLPIDELVARSET(nlpiDelVarSetIpopt)
SCIP_NLPTERMSTAT lasttermstat
static SCIP_DECL_NLPISETMESSAGEHDLR(nlpiSetMessageHdlrIpopt)
SCIP_Real * lastsoldualcons
static SCIP_DECL_NLPISOLVE(nlpiSolveIpopt)
SCIP_RETCODE SCIPnlpiOracleSetInfinity(SCIP_NLPIORACLE *oracle, SCIP_Real infinity)
static SCIP_DECL_NLPIGETSTRINGPAR(nlpiGetStringParIpopt)
static SCIP_DECL_NLPIDELCONSSET(nlpiDelConstraintSetIpopt)
static SCIP_DECL_NLPISETREALPAR(nlpiSetRealParIpopt)
SCIP_RETCODE SCIPnlpiOracleEvalJacobian(SCIP_NLPIORACLE *oracle, const SCIP_Real *x, SCIP_Bool isnewx, SCIP_Real *convals, SCIP_Real *jacobi)
#define BMSclearMemoryArray(ptr, num)
static const SCIP_Real convcheck_minred[convcheck_nchecks]
struct BMS_BlkMem BMS_BLKMEM
char ** SCIPnlpiOracleGetVarNames(SCIP_NLPIORACLE *oracle)
static SCIP_DECL_NLPICHGEXPRTREE(nlpiChgExprtreeIpopt)
static SCIP_DECL_NLPICHGCONSSIDES(nlpiChgConsSidesIpopt)
static SCIP_RETCODE SCIPsolveLinearProb3(SCIP_Real *A, SCIP_Real *b, SCIP_Real *x, SCIP_Bool *success)
static SCIP_DECL_NLPIADDVARS(nlpiAddVarsIpopt)
#define SCIP_EXPRINTCAPABILITY_GRADIENT
int SCIPnlpiOracleGetMaxDegree(SCIP_NLPIORACLE *oracle)
SCIP_RETCODE SCIPnlpiSetRealPar(SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, SCIP_NLPPARAM type, SCIP_Real dval)
static const int convcheck_maxiter[convcheck_nchecks]