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;
805 assert(nlpi !=
NULL);
806 assert(problem !=
NULL);
807 assert(problem->oracle !=
NULL);
829 assert(nlpi !=
NULL);
830 assert(problem !=
NULL);
831 assert(problem->oracle !=
NULL);
854 assert(nlpi !=
NULL);
855 assert(problem !=
NULL);
856 assert(problem->oracle !=
NULL);
860 problem->firstrun =
TRUE;
881 assert(nlpi !=
NULL);
882 assert(problem !=
NULL);
883 assert(problem->oracle !=
NULL);
887 problem->firstrun =
TRUE;
909 assert(nlpi !=
NULL);
910 assert(problem !=
NULL);
911 assert(problem->oracle !=
NULL);
933 assert(nlpi !=
NULL);
934 assert(problem !=
NULL);
935 assert(problem->oracle !=
NULL);
954 assert(nlpi !=
NULL);
955 assert(problem !=
NULL);
956 assert(problem->oracle !=
NULL);
978 assert(nlpi !=
NULL);
979 assert(problem !=
NULL);
980 assert(problem->oracle !=
NULL);
998 assert(nlpi !=
NULL);
999 assert(problem !=
NULL);
1000 assert(problem->oracle !=
NULL);
1020 assert(nlpi !=
NULL);
1021 assert(problem !=
NULL);
1022 assert(problem->oracle !=
NULL);
1024 if( primalvalues !=
NULL )
1026 if( !problem->initguess )
1053 ApplicationReturnStatus status;
1055 assert(nlpi !=
NULL);
1056 assert(problem !=
NULL);
1057 assert(problem->oracle !=
NULL);
1059 assert(IsValid(problem->ipopt));
1060 assert(IsValid(problem->nlp));
1062 problem->nlp->setNLPIPROBLEM(problem);
1064 problem->lastniter = -1;
1065 problem->lasttime = -1.0;
1070 SmartPtr<SolveStatistics> stats;
1072 if( problem->firstrun )
1088 SCIPerrorMessage(
"Do not have expression interpreter that can compute function values and gradients. Cannot solve NLP with Ipopt.\n");
1097 problem->ipopt->Options()->SetStringValue(
"hessian_approximation",
"limited-memory");
1098 problem->nlp->approxhessian =
true;
1101 problem->nlp->approxhessian =
false;
1104 status = problem->ipopt->OptimizeTNLP(GetRawPtr(problem->nlp));
1108 status = problem->ipopt->ReOptimizeTNLP(GetRawPtr(problem->nlp));
1113 case Invalid_Problem_Definition:
1114 case Invalid_Option:
1115 case Unrecoverable_Exception:
1116 case NonIpopt_Exception_Thrown:
1117 case Internal_Error:
1118 SCIPerrorMessage(
"Ipopt returned with application return status %d\n", status);
1120 case Insufficient_Memory:
1123 case Invalid_Number_Detected:
1124 SCIPdebugMessage(
"Ipopt failed because of an invalid number in function or derivative value\n");
1131 stats = problem->ipopt->Statistics();
1132 if( IsValid(stats) )
1134 problem->lastniter = stats->IterationCount();
1135 problem->lasttime = stats->TotalCPUTime();
1138 catch( IpoptException& except )
1140 SCIPerrorMessage(
"Ipopt returned with exception: %s\n", except.Message().c_str());
1144 problem->firstrun =
FALSE;
1160 assert(nlpi !=
NULL);
1161 assert(problem !=
NULL);
1163 return problem->lastsolstat;
1177 assert(nlpi !=
NULL);
1178 assert(problem !=
NULL);
1180 return problem->lasttermstat;
1196 assert(nlpi !=
NULL);
1197 assert(problem !=
NULL);
1199 if( primalvalues !=
NULL )
1200 *primalvalues = problem->lastsolprimals;
1202 if( consdualvalues !=
NULL )
1203 *consdualvalues = problem->lastsoldualcons;
1205 if( varlbdualvalues !=
NULL )
1206 *varlbdualvalues = problem->lastsoldualvarlb;
1208 if( varubdualvalues !=
NULL )
1209 *varubdualvalues = problem->lastsoldualvarub;
1227 assert(nlpi !=
NULL);
1228 assert(problem !=
NULL);
1303 assert(nlpi !=
NULL);
1304 assert(ival !=
NULL);
1305 assert(problem !=
NULL);
1306 assert(IsValid(problem->ipopt));
1320 problem->ipopt->Options()->GetIntegerValue(
"print_level", printlevel,
"");
1321 if( printlevel <= J_STRONGWARNING )
1323 else if( printlevel >= J_DETAILED )
1324 *ival = printlevel - J_ITERSUMMARY + 1;
1338 SCIPerrorMessage(
"relative objective tolerance parameter is of type real.\n");
1356 problem->ipopt->Options()->GetIntegerValue(
"max_iter", *ival,
"");
1374 *ival = problem->fastfail ? 1 : 0;
1399 assert(nlpi !=
NULL);
1400 assert(problem !=
NULL);
1401 assert(IsValid(problem->ipopt));
1407 if( ival == 0 || ival == 1 )
1412 assert(data !=
NULL);
1414 SCIPmessagePrintWarning(data->messagehdlr,
"from scratch parameter not supported by Ipopt interface yet. Ignored.\n");
1418 SCIPerrorMessage(
"Value %d for parameter from scratch out of range {0, 1}\n", ival);
1429 problem->ipopt->Options()->SetIntegerValue(
"print_level", J_STRONGWARNING);
1432 problem->ipopt->Options()->SetIntegerValue(
"print_level", J_ITERSUMMARY);
1435 problem->ipopt->Options()->SetIntegerValue(
"print_level", J_DETAILED);
1440 problem->ipopt->Options()->SetIntegerValue(
"print_level",
MIN(J_ITERSUMMARY + (ival-1), J_ALL));
1445 SCIPerrorMessage(
"Value %d for parameter from verbosity level out of range {0, 1, 2}\n", ival);
1460 SCIPerrorMessage(
"relative objective tolerance parameter is of type real.\n");
1480 problem->ipopt->Options()->SetIntegerValue(
"max_iter", ival);
1484 SCIPerrorMessage(
"Value %d for parameter iteration limit is negative\n", ival);
1504 if( ival == 0 || ival == 1 )
1506 problem->fastfail = (bool)ival;
1507 problem->storeintermediate = (bool)ival;
1511 SCIPerrorMessage(
"Value %d for parameter fastfail out of range {0, 1}\n", ival);
1541 assert(nlpi !=
NULL);
1542 assert(dval !=
NULL);
1562 problem->ipopt->Options()->GetNumericValue(
"acceptable_constr_viol_tol", *dval,
"");
1568 problem->ipopt->Options()->GetNumericValue(
"dual_inf_tol", *dval,
"");
1587 assert(data !=
NULL);
1588 *dval = data->infinity;
1601 problem->ipopt->Options()->GetNumericValue(
"max_cpu_time", *dval,
"");
1638 assert(nlpi !=
NULL);
1664 SCIPerrorMessage(
"Value %g for parameter feasibility tolerance is negative\n", dval);
1674 problem->ipopt->Options()->SetNumericValue(
"dual_inf_tol", dval);
1678 SCIPerrorMessage(
"Value %g for parameter relative objective tolerance is negative\n", dval);
1689 assert(data !=
NULL);
1691 SCIPmessagePrintWarning(data->messagehdlr,
"Parameter lower objective limit not supported by Ipopt interface yet. Ignored.\n");
1701 problem->ipopt->Options()->SetNumericValue(
"diverging_iterates_tol", dval);
1702 problem->ipopt->Options()->SetNumericValue(
"nlp_lower_bound_inf", -dval);
1703 problem->ipopt->Options()->SetNumericValue(
"nlp_upper_bound_inf", dval);
1709 assert(data !=
NULL);
1710 data->infinity = dval;
1725 problem->ipopt->Options()->SetNumericValue(
"max_cpu_time", dval);
1771 assert(nlpi !=
NULL);
1772 assert(problem !=
NULL);
1826 if( !problem->optfile.empty() )
1827 *sval = problem->optfile.c_str();
1860 assert(nlpi !=
NULL);
1861 assert(problem !=
NULL);
1916 problem->optfile = sval;
1918 problem->optfile.clear();
1920 if( problem->ipopt->Initialize(problem->optfile) != Solve_Succeeded )
1922 SCIPerrorMessage(
"Error initializing Ipopt using optionfile \"%s\"\n", problem->optfile.c_str());
1925 problem->ipopt->Options()->GetBoolValue(
"store_intermediate", problem->storeintermediate,
"");
1926 problem->firstrun =
TRUE;
1958 assert(nlpi !=
NULL);
1961 assert(nlpidata !=
NULL);
1963 nlpidata->messagehdlr = messagehdlr;
1976 assert(blkmem !=
NULL);
1977 assert(nlpi !=
NULL);
1983 nlpiCopyIpopt, nlpiFreeIpopt, nlpiGetSolverPointerIpopt,
1984 nlpiCreateProblemIpopt, nlpiFreeProblemIpopt, nlpiGetProblemPointerIpopt,
1985 nlpiAddVarsIpopt, nlpiAddConstraintsIpopt, nlpiSetObjectiveIpopt,
1986 nlpiChgVarBoundsIpopt, nlpiChgConsSidesIpopt, nlpiDelVarSetIpopt, nlpiDelConstraintSetIpopt,
1987 nlpiChgLinearCoefsIpopt, nlpiChgQuadraticCoefsIpopt, nlpiChgExprtreeIpopt, nlpiChgNonlinCoefIpopt,
1988 nlpiChgObjConstantIpopt, nlpiSetInitialGuessIpopt, nlpiSolveIpopt, nlpiGetSolstatIpopt, nlpiGetTermstatIpopt,
1989 nlpiGetSolutionIpopt, nlpiGetStatisticsIpopt,
1990 nlpiGetWarmstartSizeIpopt, nlpiGetWarmstartMemoIpopt, nlpiSetWarmstartMemoIpopt,
1991 nlpiGetIntParIpopt, nlpiSetIntParIpopt, nlpiGetRealParIpopt, nlpiSetRealParIpopt,
1992 nlpiGetStringParIpopt, nlpiSetStringParIpopt, nlpiSetMessageHdlrIpopt,
2001 return "Ipopt " IPOPT_VERSION;
2007 return "Interior Point Optimizer developed by A. Waechter et.al. (www.coin-or.org/Ipopt)";
2021 assert(nlpiproblem !=
NULL);
2023 return (
void*)GetRawPtr(nlpiproblem->
ipopt);
2031 assert(nlpiproblem !=
NULL);
2033 return nlpiproblem->
oracle;
2042 const char* optionsstring
2047 assert(nlpi !=
NULL);
2050 assert(data !=
NULL);
2052 data->defoptions = optionsstring;
2056 bool ScipNLP::get_nlp_info(
2061 IndexStyleEnum& index_style
2067 assert(nlpiproblem !=
NULL);
2068 assert(nlpiproblem->oracle !=
NULL);
2076 assert(offset !=
NULL);
2077 nnz_jac_g = offset[m];
2079 if( !approxhessian )
2084 assert(offset !=
NULL);
2085 nnz_h_lag = offset[n];
2092 index_style = TNLP::C_STYLE;
2098 bool ScipNLP::get_bounds_info(
2107 assert(nlpiproblem !=
NULL);
2108 assert(nlpiproblem->oracle !=
NULL);
2119 for(
int i = 0; i < n; ++i )
2120 assert(x_l[i] <= x_u[i]);
2123 for(
int i = 0; i < m; ++i )
2127 assert(g_l[i] <= g_u[i]);
2134 bool ScipNLP::get_starting_point(
2146 assert(nlpiproblem !=
NULL);
2147 assert(nlpiproblem->oracle !=
NULL);
2154 if( nlpiproblem->initguess )
2162 SCIPdebugMessage(
"Ipopt started without intial primal values; make up starting guess by projecting 0 onto variable bounds\n");
2164 for(
int i = 0; i < n; ++i )
2177 if( init_z || init_lambda )
2184 bool ScipNLP::get_variables_linearity(
2186 LinearityType* var_types
2189 assert(nlpiproblem !=
NULL);
2190 assert(nlpiproblem->oracle !=
NULL);
2194 for(
int i = 0; i < n; ++i )
2201 bool ScipNLP::get_constraints_linearity(
2203 LinearityType* const_types
2208 assert(nlpiproblem !=
NULL);
2209 assert(nlpiproblem->oracle !=
NULL);
2213 for( i = 0; i < m; ++i )
2220 Index ScipNLP::get_number_of_nonlinear_variables()
2225 assert(nlpiproblem !=
NULL);
2226 assert(nlpiproblem->oracle !=
NULL);
2231 for(
int i = 0; i < n; ++i )
2239 bool ScipNLP::get_list_of_nonlinear_variables(
2240 Index num_nonlin_vars,
2241 Index* pos_nonlin_vars
2247 assert(nlpiproblem !=
NULL);
2248 assert(nlpiproblem->oracle !=
NULL);
2253 for(
int i = 0; i < n; ++i )
2256 assert(count < num_nonlin_vars);
2257 pos_nonlin_vars[count++] = i;
2260 assert(count == num_nonlin_vars);
2266 bool ScipNLP::get_var_con_metadata(
2268 StringMetaDataMapType& var_string_md,
2269 IntegerMetaDataMapType& var_integer_md,
2270 NumericMetaDataMapType& var_numeric_md,
2272 StringMetaDataMapType& con_string_md,
2273 IntegerMetaDataMapType& con_integer_md,
2274 NumericMetaDataMapType& con_numeric_md
2277 assert(nlpiproblem !=
NULL);
2278 assert(nlpiproblem->oracle !=
NULL);
2283 if( varnames !=
NULL )
2285 std::vector<std::string>& varnamesvec(var_string_md[
"idx_names"]);
2286 varnamesvec.reserve(n);
2287 for(
int i = 0; i < n; ++i )
2289 if( varnames[i] !=
NULL )
2291 varnamesvec.push_back(varnames[i]);
2296 sprintf(buffer,
"nlpivar%8d", i);
2297 varnamesvec.push_back(buffer);
2302 std::vector<std::string>& consnamesvec(con_string_md[
"idx_names"]);
2303 consnamesvec.reserve(m);
2304 for(
int i = 0; i < m; ++i )
2313 sprintf(buffer,
"nlpicons%8d", i);
2314 consnamesvec.push_back(buffer);
2322 bool ScipNLP::eval_f(
2329 assert(nlpiproblem !=
NULL);
2330 assert(nlpiproblem->oracle !=
NULL);
2338 bool ScipNLP::eval_grad_f(
2347 assert(nlpiproblem !=
NULL);
2348 assert(nlpiproblem->oracle !=
NULL);
2356 bool ScipNLP::eval_g(
2364 assert(nlpiproblem !=
NULL);
2365 assert(nlpiproblem->oracle !=
NULL);
2376 bool ScipNLP::eval_jac_g(
2387 assert(nlpiproblem !=
NULL);
2388 assert(nlpiproblem->oracle !=
NULL);
2393 if( values ==
NULL )
2395 const int* jacoffset;
2400 assert(iRow !=
NULL);
2401 assert(jCol !=
NULL);
2406 assert(jacoffset[0] == 0);
2407 assert(jacoffset[m] == nele_jac);
2409 for( i = 0; i < m; ++i )
2410 for( ; j < jacoffset[i+1]; ++j )
2428 bool ScipNLP::eval_h(
2434 const Number* lambda,
2442 assert(nlpiproblem !=
NULL);
2443 assert(nlpiproblem->oracle !=
NULL);
2448 if( values ==
NULL )
2450 const int* heslagoffset;
2451 const int* heslagcol;
2455 assert(iRow !=
NULL);
2456 assert(jCol !=
NULL);
2461 assert(heslagoffset[0] == 0);
2462 assert(heslagoffset[n] == nele_hess);
2463 j = heslagoffset[0];
2464 for( i = 0; i < n; ++i )
2465 for( ; j < heslagoffset[i+1]; ++j )
2483 bool ScipNLP::intermediate_callback(
2491 Number regularization_size,
2495 const IpoptData* ip_data,
2496 IpoptCalculatedQuantities* ip_cq
2499 if( nlpiproblem->storeintermediate && mode == RegularMode && inf_pr < nlpiproblem->lastsolinfeas )
2501 Ipopt::TNLPAdapter* tnlp_adapter;
2503 tnlp_adapter =
NULL;
2506 Ipopt::OrigIpoptNLP* orignlp;
2508 orignlp =
dynamic_cast<OrigIpoptNLP*
>(GetRawPtr(ip_cq->GetIpoptNLP()));
2509 if( orignlp !=
NULL )
2510 tnlp_adapter =
dynamic_cast<TNLPAdapter*
>(GetRawPtr(orignlp->nlp()));
2513 if( tnlp_adapter !=
NULL && ip_data !=
NULL && IsValid(ip_data->curr()) )
2515 SCIPdebugMessage(
"update lastsol: inf_pr old = %g -> new = %g\n", nlpiproblem->lastsolinfeas, inf_pr);
2517 if( nlpiproblem->lastsolprimals ==
NULL )
2519 assert(nlpiproblem->lastsoldualcons ==
NULL);
2520 assert(nlpiproblem->lastsoldualvarlb ==
NULL);
2521 assert(nlpiproblem->lastsoldualvarub ==
NULL);
2532 assert(IsValid(ip_data->curr()->x()));
2533 tnlp_adapter->ResortX(*ip_data->curr()->x(), nlpiproblem->lastsolprimals);
2534 nlpiproblem->lastsolinfeas = inf_pr;
2536 assert(IsValid(ip_data->curr()->y_c()));
2537 assert(IsValid(ip_data->curr()->y_d()));
2538 tnlp_adapter->ResortG(*ip_data->curr()->y_c(), *ip_data->curr()->y_d(), nlpiproblem->lastsoldualcons);
2543 assert(IsValid(ip_data->curr()->z_L()));
2544 assert(IsValid(ip_data->curr()->z_U()));
2545 tnlp_adapter->ResortBnds(*ip_data->curr()->z_L(), nlpiproblem->lastsoldualvarlb, *ip_data->curr()->z_U(), nlpiproblem->lastsoldualvarub);
2551 if( nlpiproblem->fastfail )
2557 conv_lastrestoiter = -1;
2559 else if( mode == RestorationPhaseMode )
2561 conv_lastrestoiter = iter;
2563 else if( conv_lastrestoiter == iter-1 )
2585 if( inf_pr <= conv_prtarget[i] )
2594 else if( iter >= conv_iterlim[i] )
2597 SCIPdebugMessage(
"convcheck %d: inf_pr = %e > target %e; inf_du = %e target %e: ",
2598 i, inf_pr, conv_prtarget[i], inf_du, conv_dutarget[i]);
2604 SCIPdebugPrintf(
"continue, because restoration phase only %d iters ago\n", iter - conv_lastrestoiter);
2606 else if( mode == RegularMode && inf_du <= conv_dutarget[i] && iter < conv_iterlim[i] +
convcheck_maxiter[i] )
2609 SCIPdebugPrintf(
"continue, because dual infeas. red. sufficient and only %d iters above limit\n", iter - conv_iterlim[i]);
2625 void ScipNLP::finalize_solution(
2626 SolverReturn status,
2633 const Number* lambda,
2635 const IpoptData* data,
2636 IpoptCalculatedQuantities* cq
2639 assert(nlpiproblem !=
NULL);
2640 assert(nlpiproblem->oracle !=
NULL);
2645 bool check_feasibility =
false;
2654 case STOP_AT_ACCEPTABLE_POINT:
2656 case FEASIBLE_POINT_FOUND:
2662 case MAXITER_EXCEEDED:
2663 check_feasibility =
true;
2668 case CPUTIME_EXCEEDED:
2669 check_feasibility =
true;
2674 case STOP_AT_TINY_STEP:
2675 case RESTORATION_FAILURE:
2676 case ERROR_IN_STEP_COMPUTATION:
2677 check_feasibility =
true;
2682 case LOCAL_INFEASIBILITY:
2684 check_feasibility =
true;
2689 case DIVERGING_ITERATES:
2694 case INVALID_NUMBER_DETECTED:
2699 case USER_REQUESTED_STOP:
2700 check_feasibility =
true;
2705 case TOO_FEW_DEGREES_OF_FREEDOM:
2706 case INTERNAL_ERROR:
2707 case INVALID_OPTION:
2718 SCIPerrorMessage(
"Ipopt returned with unknown solution status %d\n", status);
2728 assert(nlpiproblem->lastsolprimals !=
NULL);
2729 assert(nlpiproblem->lastsoldualcons !=
NULL);
2730 assert(nlpiproblem->lastsoldualvarlb !=
NULL);
2731 assert(nlpiproblem->lastsoldualvarub !=
NULL);
2734 Number constrvioltol;
2735 nlpiproblem->ipopt->Options()->GetNumericValue(
"acceptable_constr_viol_tol", constrvioltol,
"");
2736 if( nlpiproblem->lastsolinfeas <= constrvioltol )
2741 SCIPdebugMessage(
"drop Ipopt's final point and report intermediate locally %sfeasible solution with infeas %g instead (acceptable: %g)\n",
2747 assert(lambda !=
NULL);
2748 assert(z_L !=
NULL);
2749 assert(z_U !=
NULL);
2751 if( nlpiproblem->lastsolprimals ==
NULL )
2753 assert(nlpiproblem->lastsoldualcons ==
NULL);
2754 assert(nlpiproblem->lastsoldualvarlb ==
NULL);
2755 assert(nlpiproblem->lastsoldualvarub ==
NULL);
2761 if( nlpiproblem->lastsolprimals ==
NULL || nlpiproblem->lastsoldualcons ==
NULL ||
2762 nlpiproblem->lastsoldualvarlb ==
NULL || nlpiproblem->lastsoldualvarub ==
NULL )
2775 if( check_feasibility && cq !=
NULL )
2778 Number constrvioltol;
2780 constrviol = cq->curr_constraint_violation();
2782 nlpiproblem->ipopt->Options()->GetNumericValue(
"acceptable_constr_viol_tol", constrvioltol,
"");
2783 if( constrviol <= constrvioltol )
2804 IpLapackDsyev(computeeigenvectors, N, a, N, w, info);
2808 SCIPerrorMessage(
"There was an error when calling DSYEV. INFO = %d\n", info);
2833 assert(success !=
NULL);
2839 IpLapackDgetrf(N, Acopy, pivotcopy, N, info);
2843 SCIPerrorMessage(
"There was an error when calling Dgetrf. INFO = %d\n", info);
2851 IpLapackDgetrs(N, 1, Acopy, N, pivotcopy, bcopy, N);
2883 assert(success !=
NULL);
2901 IpLapackDgetrf(N, Acopy, pivotcopy, N, info);
2905 SCIPerrorMessage(
"There was an error when calling Dgetrf. INFO = %d\n", info);
2913 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]