45 #pragma GCC diagnostic ignored "-Wshadow" 47 #include "IpoptConfig.h" 48 #include "IpIpoptApplication.hpp" 49 #include "IpIpoptCalculatedQuantities.hpp" 50 #include "IpSolveStatistics.hpp" 51 #include "IpJournalist.hpp" 52 #include "IpIpoptData.hpp" 53 #include "IpTNLPAdapter.hpp" 54 #include "IpOrigIpoptNLP.hpp" 55 #include "IpLapack.hpp" 57 #pragma GCC diagnostic warning "-Wshadow" 60 #if (IPOPT_VERSION_MAJOR < 3 || (IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR < 12)) 61 #error "The Ipopt interface requires at least 3.12." 64 using namespace Ipopt;
66 #define NLPI_NAME "ipopt" 67 #define NLPI_DESC "Ipopt interface" 68 #define NLPI_PRIORITY 1000 71 #define DEFAULT_PRINTLEVEL J_WARNING 73 #define DEFAULT_PRINTLEVEL J_STRONGWARNING 75 #define DEFAULT_MAXITER 3000 77 #define MAXPERTURB 0.01 78 #define FEASTOLFACTOR 0.05 80 #define DEFAULT_RANDSEED 71 120 std::string defoptions;
123 explicit SCIP_NlpiData(
159 storeintermediate(false), fastfail(false),
160 firstrun(
TRUE), initguess(NULL),
162 lastsolprimals(NULL), lastsoldualcons(NULL), lastsoldualvarlb(NULL), lastsoldualvarub(NULL),
163 lastniter(-1), lasttime(-1.0)
168 class ScipNLP :
public TNLP 178 int conv_lastrestoiter;
189 : nlpiproblem(nlpiproblem_), randnumgen(NULL), blkmem(blkmem_), conv_lastrestoiter(-1), approxhessian(
false)
191 assert(blkmem != NULL);
198 assert(randnumgen != NULL);
205 assert(nlpiproblem_ != NULL);
206 nlpiproblem = nlpiproblem_;
215 IndexStyleEnum& index_style
219 bool get_bounds_info(
229 bool get_starting_point(
242 bool get_variables_linearity(
244 LinearityType* var_types
248 bool get_constraints_linearity(
250 LinearityType* const_types
254 Index get_number_of_nonlinear_variables();
257 bool get_list_of_nonlinear_variables(
258 Index num_nonlin_vars,
259 Index* pos_nonlin_vars
263 bool get_var_con_metadata(
265 StringMetaDataMapType& var_string_md,
266 IntegerMetaDataMapType& var_integer_md,
267 NumericMetaDataMapType& var_numeric_md,
269 StringMetaDataMapType& con_string_md,
270 IntegerMetaDataMapType& con_integer_md,
271 NumericMetaDataMapType& con_numeric_md
327 const Number* lambda,
341 bool intermediate_callback(
349 Number regularization_size,
353 const IpoptData* ip_data,
354 IpoptCalculatedQuantities* ip_cq
358 void finalize_solution(
366 const Number* lambda,
368 const IpoptData* data,
369 IpoptCalculatedQuantities* cq
374 class ScipJournal :
public Ipopt::Journal {
382 Ipopt::EJournalLevel default_level,
385 : Ipopt::Journal(name, default_level),
386 messagehdlr(messagehdlr_)
393 Ipopt::EJournalCategory category,
394 Ipopt::EJournalLevel level,
398 if( level == J_ERROR )
409 Ipopt::EJournalCategory category,
410 Ipopt::EJournalLevel level,
415 if( level == J_ERROR )
425 void FlushBufferImpl() { }
434 assert(problem != NULL);
459 assert(nlpiproblem != NULL);
462 nlpiproblem->
ipopt->Options()->SetNumericValue(
"constr_viol_tol",
FEASTOLFACTOR * feastol);
464 nlpiproblem->
ipopt->Options()->SetNumericValue(
"acceptable_tol", feastol);
465 nlpiproblem->
ipopt->Options()->SetNumericValue(
"acceptable_constr_viol_tol", feastol);
490 assert(nlpiproblem != NULL);
492 nlpiproblem->
ipopt->Options()->SetNumericValue(
"dual_inf_tol", opttol);
493 nlpiproblem->
ipopt->Options()->SetNumericValue(
"compl_inf_tol", opttol);
509 assert(sourcenlpi != NULL);
510 assert(targetnlpi != NULL);
513 assert(sourcedata != NULL);
516 assert(*targetnlpi != NULL);
522 assert(targetdata != NULL);
524 targetdata->defoptions = sourcedata->defoptions;
539 assert(nlpi != NULL);
542 assert(data != NULL);
559 assert(nlpi != NULL);
576 assert(nlpi != NULL);
577 assert(problem != NULL);
580 assert(data != NULL);
583 if( *problem == NULL )
593 (*problem)->ipopt =
new IpoptApplication(
false);
594 if( IsNull((*problem)->ipopt) )
595 throw std::bad_alloc();
598 SmartPtr<Journal> jrnl =
new ScipJournal(
"console", J_ITERSUMMARY, data->messagehdlr);
600 throw std::bad_alloc();
601 jrnl->SetPrintLevel(J_DBG, J_NONE);
602 if( !(*problem)->ipopt->Jnlst()->AddJournal(jrnl) )
608 (*problem)->nlp =
new ScipNLP(*problem, data->blkmem);
609 if( IsNull((*problem)->nlp) )
610 throw std::bad_alloc();
612 catch( std::bad_alloc )
619 (*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");
622 (*problem)->ipopt->Options()->SetStringValue(
"mu_strategy",
"adaptive");
623 (*problem)->ipopt->Options()->SetStringValue(
"expect_infeasible_problem",
"yes");
624 (*problem)->ipopt->Options()->SetIntegerValue(
"max_iter",
DEFAULT_MAXITER);
625 (*problem)->ipopt->Options()->SetNumericValue(
"nlp_lower_bound_inf", -data->infinity,
false);
626 (*problem)->ipopt->Options()->SetNumericValue(
"nlp_upper_bound_inf", data->infinity,
false);
627 (*problem)->ipopt->Options()->SetNumericValue(
"diverging_iterates_tol", data->infinity,
false);
631 (*problem)->ipopt->Options()->SetStringValue(
"derivative_test",
"second-order");
637 if( data->defoptions.length() > 0 )
639 std::istringstream is(data->defoptions);
641 #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) 642 if( !(*problem)->ipopt->Options()->ReadFromStream(*(*problem)->ipopt->Jnlst(), is,
true) )
644 if( !(*problem)->ipopt->Options()->ReadFromStream(*(*problem)->ipopt->Jnlst(), is) )
647 SCIPerrorMessage(
"Error when modifiying Ipopt options using options string\n%s\n", data->defoptions.c_str());
653 if( (*problem)->ipopt->Initialize((*problem)->optfile) != Solve_Succeeded )
655 SCIPerrorMessage(
"Error during initialization of Ipopt using optionfile \"%s\"\n", (*problem)->optfile.c_str());
672 assert(nlpi != NULL);
673 assert(problem != NULL);
674 assert(*problem != NULL);
676 if( (*problem)->oracle != NULL )
704 assert(nlpi != NULL);
705 assert(problem != NULL);
707 return GetRawPtr(problem->nlp);
723 assert(nlpi != NULL);
724 assert(problem != NULL);
725 assert(problem->oracle != NULL);
729 problem->firstrun =
TRUE;
768 assert(nlpi != NULL);
769 assert(problem != NULL);
770 assert(problem->oracle != NULL);
774 nlininds, lininds, linvals,
775 nquadelems, quadelems,
776 exprvaridxs, exprtrees, names) );
778 problem->firstrun =
TRUE;
808 assert(nlpi != NULL);
809 assert(problem != NULL);
810 assert(problem->oracle != NULL);
817 problem->firstrun =
TRUE;
820 constant, nlins, lininds, linvals,
821 nquadelems, quadelems,
822 exprvaridxs, exprtree) );
844 assert(nlpi != NULL);
845 assert(problem != NULL);
846 assert(problem->oracle != NULL);
852 for( i = 0; i < nvars && !problem->firstrun; ++i )
854 problem->firstrun =
TRUE;
876 assert(nlpi != NULL);
877 assert(problem != NULL);
878 assert(problem->oracle != NULL);
901 assert(nlpi != NULL);
902 assert(problem != NULL);
903 assert(problem->oracle != NULL);
907 problem->firstrun =
TRUE;
928 assert(nlpi != NULL);
929 assert(problem != NULL);
930 assert(problem->oracle != NULL);
934 problem->firstrun =
TRUE;
956 assert(nlpi != NULL);
957 assert(problem != NULL);
958 assert(problem->oracle != NULL);
980 assert(nlpi != NULL);
981 assert(problem != NULL);
982 assert(problem->oracle != NULL);
1001 assert(nlpi != NULL);
1002 assert(problem != NULL);
1003 assert(problem->oracle != NULL);
1025 assert(nlpi != NULL);
1026 assert(problem != NULL);
1027 assert(problem->oracle != NULL);
1045 assert(nlpi != NULL);
1046 assert(problem != NULL);
1047 assert(problem->oracle != NULL);
1067 assert(nlpi != NULL);
1068 assert(problem != NULL);
1069 assert(problem->oracle != NULL);
1071 if( primalvalues != NULL )
1073 if( !problem->initguess )
1100 ApplicationReturnStatus status;
1102 assert(nlpi != NULL);
1103 assert(problem != NULL);
1104 assert(problem->oracle != NULL);
1106 assert(IsValid(problem->ipopt));
1107 assert(IsValid(problem->nlp));
1109 problem->nlp->setNLPIPROBLEM(problem);
1111 problem->lastniter = -1;
1112 problem->lasttime = -1.0;
1117 SmartPtr<SolveStatistics> stats;
1119 if( problem->firstrun )
1135 SCIPerrorMessage(
"Do not have expression interpreter that can compute function values and gradients. Cannot solve NLP with Ipopt.\n");
1144 problem->ipopt->Options()->SetStringValue(
"hessian_approximation",
"limited-memory");
1145 problem->nlp->approxhessian =
true;
1148 problem->nlp->approxhessian =
false;
1151 status = problem->ipopt->OptimizeTNLP(GetRawPtr(problem->nlp));
1155 status = problem->ipopt->ReOptimizeTNLP(GetRawPtr(problem->nlp));
1160 case Invalid_Problem_Definition:
1161 case Invalid_Option:
1162 case Unrecoverable_Exception:
1163 case NonIpopt_Exception_Thrown:
1164 case Internal_Error:
1165 SCIPerrorMessage(
"Ipopt returned with application return status %d\n", status);
1167 case Insufficient_Memory:
1170 case Invalid_Number_Detected:
1171 SCIPdebugMessage(
"Ipopt failed because of an invalid number in function or derivative value\n");
1178 stats = problem->ipopt->Statistics();
1179 if( IsValid(stats) )
1181 problem->lastniter = stats->IterationCount();
1182 problem->lasttime = stats->TotalCPUTime();
1187 problem->lastniter = 0;
1188 problem->lasttime = 0.0;
1191 catch( IpoptException& except )
1193 SCIPerrorMessage(
"Ipopt returned with exception: %s\n", except.Message().c_str());
1197 problem->firstrun =
FALSE;
1213 assert(nlpi != NULL);
1214 assert(problem != NULL);
1216 return problem->lastsolstat;
1230 assert(nlpi != NULL);
1231 assert(problem != NULL);
1233 return problem->lasttermstat;
1250 assert(nlpi != NULL);
1251 assert(problem != NULL);
1253 if( primalvalues != NULL )
1254 *primalvalues = problem->lastsolprimals;
1256 if( consdualvalues != NULL )
1257 *consdualvalues = problem->lastsoldualcons;
1259 if( varlbdualvalues != NULL )
1260 *varlbdualvalues = problem->lastsoldualvarlb;
1262 if( varubdualvalues != NULL )
1263 *varubdualvalues = problem->lastsoldualvarub;
1265 if( objval != NULL )
1267 if( problem->lastsolprimals != NULL )
1292 assert(nlpi != NULL);
1293 assert(problem != NULL);
1368 assert(nlpi != NULL);
1369 assert(ival != NULL);
1370 assert(problem != NULL);
1371 assert(IsValid(problem->ipopt));
1385 problem->ipopt->Options()->GetIntegerValue(
"print_level", printlevel,
"");
1386 if( printlevel <= J_STRONGWARNING )
1388 else if( printlevel >= J_DETAILED )
1389 *ival = printlevel - J_ITERSUMMARY + 1;
1403 SCIPerrorMessage(
"relative objective tolerance parameter is of type real.\n");
1421 problem->ipopt->Options()->GetIntegerValue(
"max_iter", *ival,
"");
1439 *ival = problem->fastfail ? 1 : 0;
1464 assert(nlpi != NULL);
1465 assert(problem != NULL);
1466 assert(IsValid(problem->ipopt));
1472 if( ival == 0 || ival == 1 )
1477 assert(data != NULL);
1479 SCIPmessagePrintWarning(data->messagehdlr,
"from scratch parameter not supported by Ipopt interface yet. Ignored.\n");
1483 SCIPerrorMessage(
"Value %d for parameter from scratch out of range {0, 1}\n", ival);
1494 problem->ipopt->Options()->SetIntegerValue(
"print_level", J_STRONGWARNING);
1497 problem->ipopt->Options()->SetIntegerValue(
"print_level", J_ITERSUMMARY);
1500 problem->ipopt->Options()->SetIntegerValue(
"print_level", J_DETAILED);
1505 problem->ipopt->Options()->SetIntegerValue(
"print_level", MIN(J_ITERSUMMARY + (ival-1), J_ALL));
1510 SCIPerrorMessage(
"Value %d for parameter from verbosity level out of range {0, 1, 2}\n", ival);
1525 SCIPerrorMessage(
"relative objective tolerance parameter is of type real.\n");
1545 problem->ipopt->Options()->SetIntegerValue(
"max_iter", ival);
1549 SCIPerrorMessage(
"Value %d for parameter iteration limit is negative\n", ival);
1569 if( ival == 0 || ival == 1 )
1571 problem->fastfail = (bool)ival;
1572 problem->storeintermediate = (bool)ival;
1576 SCIPerrorMessage(
"Value %d for parameter fastfail out of range {0, 1}\n", ival);
1606 assert(nlpi != NULL);
1607 assert(dval != NULL);
1627 problem->ipopt->Options()->GetNumericValue(
"acceptable_constr_viol_tol", *dval,
"");
1633 problem->ipopt->Options()->GetNumericValue(
"dual_inf_tol", *dval,
"");
1652 assert(data != NULL);
1653 *dval = data->infinity;
1666 problem->ipopt->Options()->GetNumericValue(
"max_cpu_time", *dval,
"");
1703 assert(nlpi != NULL);
1729 SCIPerrorMessage(
"Value %g for parameter feasibility tolerance is negative\n", dval);
1743 SCIPerrorMessage(
"Value %g for parameter relative objective tolerance is negative\n", dval);
1754 assert(data != NULL);
1756 SCIPmessagePrintWarning(data->messagehdlr,
"Parameter lower objective limit not supported by Ipopt interface yet. Ignored.\n");
1766 problem->ipopt->Options()->SetNumericValue(
"diverging_iterates_tol", dval);
1767 problem->ipopt->Options()->SetNumericValue(
"nlp_lower_bound_inf", -dval);
1768 problem->ipopt->Options()->SetNumericValue(
"nlp_upper_bound_inf", dval);
1774 assert(data != NULL);
1775 data->infinity = dval;
1790 problem->ipopt->Options()->SetNumericValue(
"max_cpu_time", dval);
1836 assert(nlpi != NULL);
1837 assert(problem != NULL);
1891 if( !problem->optfile.empty() )
1892 *sval = problem->optfile.c_str();
1925 assert(nlpi != NULL);
1926 assert(problem != NULL);
1981 problem->optfile = sval;
1983 problem->optfile.clear();
1985 if( problem->ipopt->Initialize(problem->optfile) != Solve_Succeeded )
1987 SCIPerrorMessage(
"Error initializing Ipopt using optionfile \"%s\"\n", problem->optfile.c_str());
1990 problem->ipopt->Options()->GetBoolValue(
"store_intermediate", problem->storeintermediate,
"");
1991 problem->firstrun =
TRUE;
2023 assert(nlpi != NULL);
2026 assert(nlpidata != NULL);
2028 nlpidata->messagehdlr = messagehdlr;
2041 assert(blkmem != NULL);
2042 assert(nlpi != NULL);
2048 nlpiCopyIpopt, nlpiFreeIpopt, nlpiGetSolverPointerIpopt,
2049 nlpiCreateProblemIpopt, nlpiFreeProblemIpopt, nlpiGetProblemPointerIpopt,
2050 nlpiAddVarsIpopt, nlpiAddConstraintsIpopt, nlpiSetObjectiveIpopt,
2051 nlpiChgVarBoundsIpopt, nlpiChgConsSidesIpopt, nlpiDelVarSetIpopt, nlpiDelConstraintSetIpopt,
2052 nlpiChgLinearCoefsIpopt, nlpiChgQuadraticCoefsIpopt, nlpiChgExprtreeIpopt, nlpiChgNonlinCoefIpopt,
2053 nlpiChgObjConstantIpopt, nlpiSetInitialGuessIpopt, nlpiSolveIpopt, nlpiGetSolstatIpopt, nlpiGetTermstatIpopt,
2054 nlpiGetSolutionIpopt, nlpiGetStatisticsIpopt,
2055 nlpiGetWarmstartSizeIpopt, nlpiGetWarmstartMemoIpopt, nlpiSetWarmstartMemoIpopt,
2056 nlpiGetIntParIpopt, nlpiSetIntParIpopt, nlpiGetRealParIpopt, nlpiSetRealParIpopt,
2057 nlpiGetStringParIpopt, nlpiSetStringParIpopt, nlpiSetMessageHdlrIpopt,
2066 return "Ipopt " IPOPT_VERSION;
2072 return "Interior Point Optimizer developed by A. Waechter et.al. (www.coin-or.org/Ipopt)";
2086 assert(nlpiproblem != NULL);
2088 return (
void*)GetRawPtr(nlpiproblem->
ipopt);
2096 assert(nlpiproblem != NULL);
2098 return nlpiproblem->
oracle;
2107 const char* optionsstring
2112 assert(nlpi != NULL);
2115 assert(data != NULL);
2117 data->defoptions = optionsstring;
2121 bool ScipNLP::get_nlp_info(
2126 IndexStyleEnum& index_style
2132 assert(nlpiproblem != NULL);
2133 assert(nlpiproblem->oracle != NULL);
2141 assert(offset != NULL);
2142 nnz_jac_g = offset[m];
2144 if( !approxhessian )
2149 assert(offset != NULL);
2150 nnz_h_lag = offset[n];
2157 index_style = TNLP::C_STYLE;
2163 bool ScipNLP::get_bounds_info(
2172 assert(nlpiproblem != NULL);
2173 assert(nlpiproblem->oracle != NULL);
2184 for(
int i = 0; i < n; ++i )
2185 assert(x_l[i] <= x_u[i]);
2188 for(
int i = 0; i < m; ++i )
2192 assert(g_l[i] <= g_u[i]);
2199 bool ScipNLP::get_starting_point(
2211 assert(nlpiproblem != NULL);
2212 assert(nlpiproblem->oracle != NULL);
2219 if( nlpiproblem->initguess )
2227 SCIPdebugMessage(
"Ipopt started without intial primal values; make up starting guess by projecting 0 onto variable bounds\n");
2229 for(
int i = 0; i < n; ++i )
2242 if( init_z || init_lambda )
2249 bool ScipNLP::get_variables_linearity(
2251 LinearityType* var_types
2254 assert(nlpiproblem != NULL);
2255 assert(nlpiproblem->oracle != NULL);
2259 for(
int i = 0; i < n; ++i )
2266 bool ScipNLP::get_constraints_linearity(
2268 LinearityType* const_types
2273 assert(nlpiproblem != NULL);
2274 assert(nlpiproblem->oracle != NULL);
2278 for( i = 0; i < m; ++i )
2285 Index ScipNLP::get_number_of_nonlinear_variables()
2290 assert(nlpiproblem != NULL);
2291 assert(nlpiproblem->oracle != NULL);
2296 for(
int i = 0; i < n; ++i )
2304 bool ScipNLP::get_list_of_nonlinear_variables(
2305 Index num_nonlin_vars,
2306 Index* pos_nonlin_vars
2312 assert(nlpiproblem != NULL);
2313 assert(nlpiproblem->oracle != NULL);
2318 for(
int i = 0; i < n; ++i )
2321 assert(count < num_nonlin_vars);
2322 pos_nonlin_vars[count++] = i;
2325 assert(count == num_nonlin_vars);
2331 bool ScipNLP::get_var_con_metadata(
2333 StringMetaDataMapType& var_string_md,
2334 IntegerMetaDataMapType& var_integer_md,
2335 NumericMetaDataMapType& var_numeric_md,
2337 StringMetaDataMapType& con_string_md,
2338 IntegerMetaDataMapType& con_integer_md,
2339 NumericMetaDataMapType& con_numeric_md
2342 assert(nlpiproblem != NULL);
2343 assert(nlpiproblem->oracle != NULL);
2348 if( varnames != NULL )
2350 std::vector<std::string>& varnamesvec(var_string_md[
"idx_names"]);
2351 varnamesvec.reserve(n);
2352 for(
int i = 0; i < n; ++i )
2354 if( varnames[i] != NULL )
2356 varnamesvec.push_back(varnames[i]);
2361 sprintf(buffer,
"nlpivar%8d", i);
2362 varnamesvec.push_back(buffer);
2367 std::vector<std::string>& consnamesvec(con_string_md[
"idx_names"]);
2368 consnamesvec.reserve(m);
2369 for(
int i = 0; i < m; ++i )
2378 sprintf(buffer,
"nlpicons%8d", i);
2379 consnamesvec.push_back(buffer);
2387 bool ScipNLP::eval_f(
2394 assert(nlpiproblem != NULL);
2395 assert(nlpiproblem->oracle != NULL);
2403 bool ScipNLP::eval_grad_f(
2412 assert(nlpiproblem != NULL);
2413 assert(nlpiproblem->oracle != NULL);
2421 bool ScipNLP::eval_g(
2429 assert(nlpiproblem != NULL);
2430 assert(nlpiproblem->oracle != NULL);
2441 bool ScipNLP::eval_jac_g(
2452 assert(nlpiproblem != NULL);
2453 assert(nlpiproblem->oracle != NULL);
2458 if( values == NULL )
2460 const int* jacoffset;
2465 assert(iRow != NULL);
2466 assert(jCol != NULL);
2471 assert(jacoffset[0] == 0);
2472 assert(jacoffset[m] == nele_jac);
2474 for( i = 0; i < m; ++i )
2475 for( ; j < jacoffset[i+1]; ++j )
2493 bool ScipNLP::eval_h(
2499 const Number* lambda,
2507 assert(nlpiproblem != NULL);
2508 assert(nlpiproblem->oracle != NULL);
2513 if( values == NULL )
2515 const int* heslagoffset;
2516 const int* heslagcol;
2520 assert(iRow != NULL);
2521 assert(jCol != NULL);
2526 assert(heslagoffset[0] == 0);
2527 assert(heslagoffset[n] == nele_hess);
2528 j = heslagoffset[0];
2529 for( i = 0; i < n; ++i )
2530 for( ; j < heslagoffset[i+1]; ++j )
2548 bool ScipNLP::intermediate_callback(
2556 Number regularization_size,
2560 const IpoptData* ip_data,
2561 IpoptCalculatedQuantities* ip_cq
2564 if( nlpiproblem->storeintermediate && mode == RegularMode && inf_pr < nlpiproblem->lastsolinfeas )
2566 Ipopt::TNLPAdapter* tnlp_adapter;
2568 tnlp_adapter = NULL;
2571 Ipopt::OrigIpoptNLP* orignlp;
2573 orignlp =
dynamic_cast<OrigIpoptNLP*
>(GetRawPtr(ip_cq->GetIpoptNLP()));
2574 if( orignlp != NULL )
2575 tnlp_adapter =
dynamic_cast<TNLPAdapter*
>(GetRawPtr(orignlp->nlp()));
2578 if( tnlp_adapter != NULL && ip_data != NULL && IsValid(ip_data->curr()) )
2580 SCIPdebugMessage(
"update lastsol: inf_pr old = %g -> new = %g\n", nlpiproblem->lastsolinfeas, inf_pr);
2582 if( nlpiproblem->lastsolprimals == NULL )
2584 assert(nlpiproblem->lastsoldualcons == NULL);
2585 assert(nlpiproblem->lastsoldualvarlb == NULL);
2586 assert(nlpiproblem->lastsoldualvarub == NULL);
2597 assert(IsValid(ip_data->curr()->x()));
2598 tnlp_adapter->ResortX(*ip_data->curr()->x(), nlpiproblem->lastsolprimals);
2599 nlpiproblem->lastsolinfeas = inf_pr;
2601 assert(IsValid(ip_data->curr()->y_c()));
2602 assert(IsValid(ip_data->curr()->y_d()));
2603 tnlp_adapter->ResortG(*ip_data->curr()->y_c(), *ip_data->curr()->y_d(), nlpiproblem->lastsoldualcons);
2608 assert(IsValid(ip_data->curr()->z_L()));
2609 assert(IsValid(ip_data->curr()->z_U()));
2610 tnlp_adapter->ResortBnds(*ip_data->curr()->z_L(), nlpiproblem->lastsoldualvarlb, *ip_data->curr()->z_U(), nlpiproblem->lastsoldualvarub);
2616 if( nlpiproblem->fastfail )
2622 conv_lastrestoiter = -1;
2624 else if( mode == RestorationPhaseMode )
2626 conv_lastrestoiter = iter;
2628 else if( conv_lastrestoiter == iter-1 )
2650 if( inf_pr <= conv_prtarget[i] )
2659 else if( iter >= conv_iterlim[i] )
2662 SCIPdebugMessage(
"convcheck %d: inf_pr = %e > target %e; inf_du = %e target %e: ",
2663 i, inf_pr, conv_prtarget[i], inf_du, conv_dutarget[i]);
2669 SCIPdebugPrintf(
"continue, because restoration phase only %d iters ago\n", iter - conv_lastrestoiter);
2671 else if( mode == RegularMode && inf_du <= conv_dutarget[i] && iter < conv_iterlim[i] +
convcheck_maxiter[i] )
2674 SCIPdebugPrintf(
"continue, because dual infeas. red. sufficient and only %d iters above limit\n", iter - conv_iterlim[i]);
2690 void ScipNLP::finalize_solution(
2691 SolverReturn status,
2698 const Number* lambda,
2700 const IpoptData* data,
2701 IpoptCalculatedQuantities* cq
2704 assert(nlpiproblem != NULL);
2705 assert(nlpiproblem->oracle != NULL);
2710 bool check_feasibility =
false;
2719 case STOP_AT_ACCEPTABLE_POINT:
2721 case FEASIBLE_POINT_FOUND:
2727 case MAXITER_EXCEEDED:
2728 check_feasibility =
true;
2733 case CPUTIME_EXCEEDED:
2734 check_feasibility =
true;
2739 case STOP_AT_TINY_STEP:
2740 case RESTORATION_FAILURE:
2741 case ERROR_IN_STEP_COMPUTATION:
2742 check_feasibility =
true;
2747 case LOCAL_INFEASIBILITY:
2749 check_feasibility =
true;
2754 case DIVERGING_ITERATES:
2759 case INVALID_NUMBER_DETECTED:
2764 case USER_REQUESTED_STOP:
2765 check_feasibility =
true;
2770 case TOO_FEW_DEGREES_OF_FREEDOM:
2771 case INTERNAL_ERROR:
2772 case INVALID_OPTION:
2783 SCIPerrorMessage(
"Ipopt returned with unknown solution status %d\n", status);
2793 assert(nlpiproblem->lastsolprimals != NULL);
2794 assert(nlpiproblem->lastsoldualcons != NULL);
2795 assert(nlpiproblem->lastsoldualvarlb != NULL);
2796 assert(nlpiproblem->lastsoldualvarub != NULL);
2799 Number constrvioltol;
2800 nlpiproblem->ipopt->Options()->GetNumericValue(
"acceptable_constr_viol_tol", constrvioltol,
"");
2801 if( nlpiproblem->lastsolinfeas <= constrvioltol )
2806 SCIPdebugMessage(
"drop Ipopt's final point and report intermediate locally %sfeasible solution with infeas %g instead (acceptable: %g)\n",
2812 assert(lambda != NULL);
2813 assert(z_L != NULL);
2814 assert(z_U != NULL);
2816 if( nlpiproblem->lastsolprimals == NULL )
2818 assert(nlpiproblem->lastsoldualcons == NULL);
2819 assert(nlpiproblem->lastsoldualvarlb == NULL);
2820 assert(nlpiproblem->lastsoldualvarub == NULL);
2826 if( nlpiproblem->lastsolprimals == NULL || nlpiproblem->lastsoldualcons == NULL ||
2827 nlpiproblem->lastsoldualvarlb == NULL || nlpiproblem->lastsoldualvarub == NULL )
2840 if( check_feasibility && cq != NULL )
2843 Number constrvioltol;
2845 constrviol = cq->curr_constraint_violation();
2847 nlpiproblem->ipopt->Options()->GetNumericValue(
"acceptable_constr_viol_tol", constrvioltol,
"");
2848 if( constrviol <= constrvioltol )
2869 IpLapackDsyev(computeeigenvectors, N, a, N, w, info);
2873 SCIPerrorMessage(
"There was an error when calling DSYEV. INFO = %d\n", info);
2898 assert(success != NULL);
2904 IpLapackDgetrf(N, Acopy, pivotcopy, N, info);
2908 SCIPerrorMessage(
"There was an error when calling Dgetrf. INFO = %d\n", info);
2916 IpLapackDgetrs(N, 1, Acopy, N, pivotcopy, bcopy, N);
2948 assert(success != NULL);
2966 IpLapackDgetrf(N, Acopy, pivotcopy, N, info);
2970 SCIPerrorMessage(
"There was an error when calling Dgetrf. INFO = %d\n", info);
2978 IpLapackDgetrs(N, 1, Acopy, N, pivotcopy, bcopy, N);
SCIP_Bool SCIPisIpoptAvailableIpopt(void)
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
static SCIP_DECL_NLPIGETPROBLEMPOINTER(nlpiGetProblemPointerIpopt)
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)
static void setOpttol(SCIP_NLPIPROBLEM *nlpiproblem, SCIP_Real opttol)
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)
static SCIP_DECL_NLPIGETSTATISTICS(nlpiGetStatisticsIpopt)
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,...)
internal miscellaneous methods
void SCIPrandomFree(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem)
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
#define SCIP_DEFAULT_DUALFEASTOL
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
SCIP_RETCODE SCIPrandomCreate(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem, unsigned int initialseed)
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]