65#include "IpoptConfig.h"
67#if defined(__GNUC__) && IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR < 14
68#pragma GCC diagnostic ignored "-Wshadow"
70#include "IpIpoptApplication.hpp"
71#include "IpIpoptCalculatedQuantities.hpp"
72#include "IpSolveStatistics.hpp"
73#include "IpJournalist.hpp"
74#include "IpIpoptData.hpp"
75#include "IpTNLPAdapter.hpp"
76#include "IpOrigIpoptNLP.hpp"
77#include "IpLapack.hpp"
78#if defined(__GNUC__) && IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR < 14
79#pragma GCC diagnostic warning "-Wshadow"
82#if IPOPT_VERSION_MAJOR < 3 || (IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR < 12)
83#error "The Ipopt interface requires at least 3.12.0"
92#if defined(SCIP_THREADSAFE) && __cplusplus >= 201103L && IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR < 14
93#define PROTECT_SOLVE_BY_MUTEX
95static std::mutex solve_mutex;
100#define NLPI_NAME "ipopt"
101#define NLPI_DESC "Ipopt interface"
102#define NLPI_PRIORITY 1000
104#define MAXPERTURB 0.01
105#define FEASTOLFACTOR 0.9
107#define DEFAULT_RANDSEED 71
153 "linear_system_scaling",
154 "nlp_scaling_method",
156 "hessian_approximation"
169 explicit SCIP_NlpiData()
170 : optfile(
NULL), print_level(-1), warm_start_push(1e-9)
215class ScipNLP :
public TNLP
225 int conv_lastrestoiter;
227 unsigned int current_x;
228 unsigned int last_f_eval_x;
229 unsigned int last_g_eval_x;
240 : nlpiproblem(nlpiproblem_), scip(scip_),
241 conv_lastrestoiter(-1),
242 current_x(1), last_f_eval_x(0), last_g_eval_x(0),
254 void initializeSolve(
260 nlpiproblem = nlpiproblem_;
275 IndexStyleEnum& index_style
279 bool get_bounds_info(
289 bool get_starting_point(
302 Index get_number_of_nonlinear_variables();
305 bool get_list_of_nonlinear_variables(
306 Index num_nonlin_vars,
307 Index* pos_nonlin_vars
311 bool get_var_con_metadata(
313 StringMetaDataMapType& var_string_md,
314 IntegerMetaDataMapType& var_integer_md,
315 NumericMetaDataMapType& var_numeric_md,
317 StringMetaDataMapType& con_string_md,
318 IntegerMetaDataMapType& con_integer_md,
319 NumericMetaDataMapType& con_numeric_md
375 const Number* lambda,
389 bool intermediate_callback(
397 Number regularization_size,
401 const IpoptData* ip_data,
402 IpoptCalculatedQuantities* ip_cq
406 void finalize_solution(
414 const Number* lambda,
416 const IpoptData* data,
417 IpoptCalculatedQuantities* cq
422class ScipJournal :
public Ipopt::Journal {
429 Ipopt::EJournalLevel default_level,
432 : Ipopt::Journal(name, default_level),
441 Ipopt::EJournalCategory category,
442 Ipopt::EJournalLevel level,
446 if( level == J_ERROR )
458 Ipopt::EJournalCategory category,
459 Ipopt::EJournalLevel level,
464 if( level == J_ERROR )
475 void FlushBufferImpl() { }
525 SCIPdebugMsg(
scip,
"Disable warmstart as no primal or dual solution available.\n");
544 warmstart ?
"warm" :
"cold",
549 SCIPdebugMsg(
scip,
"Starting solution for coldstart not available. Making up something by projecting 0 onto variable bounds and adding a random perturbation.\n");
563 for(
int i = 0;
i < n; ++
i )
591 if( nlpidata->print_level < 0 )
596 (void) nlpiproblem->
ipopt->Options()->SetIntegerValue(
"print_level", J_ERROR);
599 (void) nlpiproblem->
ipopt->Options()->SetIntegerValue(
"print_level", J_SUMMARY);
602 (void) nlpiproblem->
ipopt->Options()->SetIntegerValue(
"print_level", J_ITERSUMMARY);
605 (void) nlpiproblem->
ipopt->Options()->SetIntegerValue(
"print_level", J_DETAILED);
608 (void) nlpiproblem->
ipopt->Options()->SetIntegerValue(
"print_level",
MIN(J_ITERSUMMARY + (param.
verblevel-1), J_ALL));
613#ifdef SCIP_DISABLED_CODE
616 if( nlpidata->autoiterlim > 0 )
634 for(
int i = 0;
i < n; ++
i )
654 for(
int i = 0;
i < m; ++
i )
696 -0.0021259769 * jacnnz +2.0121042012 * sqrt(jacnnz)
697 -0.0374801925 * nlincons +2.9562232443 * sqrt(nlincons)
698 -0.0133039200 * nnlcons -0.0412118434 * sqrt(nnlcons)
699 -0.0702890379 * nnlvars +7.0920920430 * sqrt(nnlvars)
700 +0.0183592749 * nvarbnd -4.7218258847 * sqrt(nvarbnd)
701 +0.0112944627 *
nvars -0.8365873360 * sqrt(
nvars));
707 if( nlpidata->print_level >= J_SUMMARY || param.
verblevel > 0 )
711 (void) nlpiproblem->
ipopt->Options()->SetIntegerValue(
"max_iter", param.
iterlimit);
723 (void) nlpiproblem->
ipopt->Options()->SetNumericValue(
"dual_inf_tol", param.
opttol);
724 (void) nlpiproblem->
ipopt->Options()->SetNumericValue(
"compl_inf_tol", param.
opttol);
726 (void) nlpiproblem->
ipopt->Options()->SetNumericValue(
"tol", param.
solvertol);
728#if IPOPT_VERSION_MAJOR > 3 || IPOPT_VERSION_MINOR > 14 || (IPOPT_VERSION_MINOR == 14 && IPOPT_VERSION_RELEASE >= 2)
729 (void) nlpiproblem->
ipopt->Options()->UnsetValue(
"tol");
731 (void) nlpiproblem->
ipopt->Options()->SetNumericValue(
"tol", 1e-8);
735#if IPOPT_VERSION_MAJOR > 3 || IPOPT_VERSION_MINOR >= 14
736 (void) nlpiproblem->
ipopt->Options()->SetNumericValue(
"max_wall_time",
MAX(param.
timelimit, DBL_MIN));
738 (void) nlpiproblem->
ipopt->Options()->SetNumericValue(
"max_cpu_time",
MAX(param.
timelimit, DBL_MIN));
744 (void) nlpiproblem->
ipopt->Options()->SetIntegerValue(
"acceptable_iter", 0);
746#if IPOPT_VERSION_MAJOR > 3 || IPOPT_VERSION_MINOR > 14 || (IPOPT_VERSION_MINOR == 14 && IPOPT_VERSION_RELEASE >= 2)
747 (void) nlpiproblem->
ipopt->Options()->UnsetValue(
"acceptable_iter");
749 (void) nlpiproblem->
ipopt->Options()->SetIntegerValue(
"acceptable_iter", 15);
752 (void) nlpiproblem->
ipopt->Options()->SetStringValue(
"expect_infeasible_problem", param.
expectinfeas ?
"yes" :
"no");
754 if( !nlpiproblem->
ipopt->Options()->SetStringValue(
"warm_start_init_point", param.
warmstart ?
"yes" :
"no") && !param.
warmstart )
757 SCIPerrorMessage(
"Failed to set Ipopt warm_start_init_point option to no.");
764#ifdef COLLECT_SOLVESTATS
767void collectStatistic(
769 ApplicationReturnStatus status,
771 SmartPtr<SolveStatistics> stats
790 for(
int i = 0;
i < n; ++
i )
815 for(
int i = 0;
i < m; ++
i )
856 for(
int i = 0;
i < n; ++
i )
857 for(
int j = offset[
i]; j < offset[
i+1]; ++j )
861 linsys11nz += 2 * (jacnnz + nslacks);
865 linsys13nz = linsys11nz + m;
871 problem->
ipopt->Options()->GetBoolValue(
"expect_infeasible_problem", expectinfeas,
"");
873 static bool firstwrite =
true;
876 printf(
"IPOPTSTAT status,iter,time,nvars,nnlvars,nvarlb,nvarub,nlincons,nnlcons,objnl,jacnnz,hesnnz,linsys11nz,linsys13nz,linsys11density,linsys13density,expectinfeas\n");
880 printf(
"IPOPTSTAT %d,%d,%g,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%f,%f,%d\n",
881 status, stats->IterationCount(), stats->TotalWallclockTime(),
882 nvars, nnlvars, nvarlb, nvarub, nlincons, nnlcons, objnl, jacnnz, hesnnz, linsys11nz, linsys13nz, linsys11density, linsys13density, expectinfeas);
911 if( problem ==
NULL )
914 return (
void*)GetRawPtr(problem->
ipopt);
937 (*problem)->ipopt =
new IpoptApplication(
false);
940 SmartPtr<Journal> jrnl =
new ScipJournal(
"console", J_ITERSUMMARY,
scip);
941 jrnl->SetPrintLevel(J_DBG, J_NONE);
942 if( !(*problem)->ipopt->Jnlst()->AddJournal(jrnl) )
948 (*problem)->nlp =
new ScipNLP(*problem,
scip);
950 catch(
const std::bad_alloc& )
973 if( *paramval !=
'\0' )
994 (void) (*problem)->ipopt->Options()->SetIntegerValue(
ipopt_int_params[
i], paramval,
false);
997#if IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR < 14
1001 (void) (*problem)->ipopt->Options()->SetNumericValue(
"bound_relax_factor", 0.0);
1007 (void) (*problem)->ipopt->Options()->SetStringValue(
"print_user_options",
"yes");
1009 (void) (*problem)->ipopt->Options()->SetStringValue(
"sb",
"yes");
1010 (void) (*problem)->ipopt->Options()->SetStringValueIfUnset(
"mu_strategy",
"adaptive");
1011 (void) (*problem)->ipopt->Options()->SetIntegerValue(
"max_iter", INT_MAX);
1012 (void) (*problem)->ipopt->Options()->SetNumericValue(
"nlp_lower_bound_inf", -
SCIPinfinity(
scip),
false);
1013 (void) (*problem)->ipopt->Options()->SetNumericValue(
"nlp_upper_bound_inf",
SCIPinfinity(
scip),
false);
1014 (void) (*problem)->ipopt->Options()->SetNumericValue(
"diverging_iterates_tol",
SCIPinfinity(
scip),
false);
1017 (void) (*problem)->ipopt->Options()->SetNumericValue(
"warm_start_bound_push", data->warm_start_push);
1018 (void) (*problem)->ipopt->Options()->SetNumericValue(
"warm_start_bound_frac", data->warm_start_push);
1019 (void) (*problem)->ipopt->Options()->SetNumericValue(
"warm_start_slack_bound_push", data->warm_start_push);
1020 (void) (*problem)->ipopt->Options()->SetNumericValue(
"warm_start_slack_bound_frac", data->warm_start_push);
1021 (void) (*problem)->ipopt->Options()->SetNumericValue(
"warm_start_mult_bound_push", data->warm_start_push);
1025 if( (*problem)->ipopt->Initialize(data->optfile) != Solve_Succeeded )
1027 SCIPerrorMessage(
"Error during initialization of Ipopt using optionfile \"%s\"\n", data->optfile);
1056 if( (*problem)->randnumgen !=
NULL )
1074 return GetRawPtr(problem->
nlp);
1169 if( (oldlb == oldub) != (lbs[
i] == ubs[
i]) )
1209 if( (oldlhs == oldrhs) != (lhss[
i] == rhss[
i]) )
1247 for(
i = 0;
i < dstatssize; ++
i )
1249 if( dstats[
i] != -1 )
1307 for(
i = 0;
i < dstatssize; ++
i )
1309 if( dstats[
i] != -1 )
1378 problem->
solobjval += objconstant - oldconstant;
1395 if( primalvalues !=
NULL )
1412 SCIPdebugMsg(
scip,
"invalidate initial guess primal values on user-request\n");
1418 if( consdualvalues !=
NULL && varlbdualvalues !=
NULL && varubdualvalues !=
NULL )
1459 ApplicationReturnStatus status;
1472 if( nlpidata->print_level >= J_SUMMARY || param.verblevel > 0 )
1480 if( param.timelimit == 0.0 )
1491#ifdef COLLECT_SOLVESTATS
1494 param.iterlimit = 1000;
1505 problem->
nlp->initializeSolve(problem, param);
1512#ifdef PROTECT_SOLVE_BY_MUTEX
1516 std::unique_lock<std::mutex> guard(solve_mutex, std::defer_lock);
1517 std::string linsolver;
1518 (void) problem->
ipopt->Options()->GetStringValue(
"linear_solver", linsolver,
"");
1519 if( linsolver ==
"mumps" )
1537 SCIPerrorMessage(
"Do not have expression interpreter that can compute function values and gradients. Cannot solve NLP with Ipopt.\n");
1546 (void) problem->
ipopt->Options()->SetStringValueIfUnset(
"hessian_approximation",
"limited-memory");
1547 problem->
nlp->approxhessian =
true;
1550 problem->
nlp->approxhessian =
false;
1554 problem->
ipopt->Options()->SetStringValue(
"derivative_test", problem->
nlp->approxhessian ?
"first-order" :
"second-order");
1557 status = problem->
ipopt->OptimizeTNLP(GetRawPtr(problem->
nlp));
1562 problem->
ipopt->Options()->SetStringValue(
"warm_start_same_structure", problem->
samestructure ?
"yes" :
"no");
1563 status = problem->
ipopt->ReOptimizeTNLP(GetRawPtr(problem->
nlp));
1569 case Solve_Succeeded:
1570 case Solved_To_Acceptable_Level:
1571 case Infeasible_Problem_Detected:
1572 case Search_Direction_Becomes_Too_Small:
1573 case Diverging_Iterates:
1574 case User_Requested_Stop:
1575 case Feasible_Point_Found:
1576 case Maximum_Iterations_Exceeded:
1577 case Restoration_Failed:
1578 case Error_In_Step_Computation:
1579 case Maximum_CpuTime_Exceeded:
1580#if IPOPT_VERSION_MAJOR > 3 || IPOPT_VERSION_MINOR >= 14
1581 case Maximum_WallTime_Exceeded:
1591 case Not_Enough_Degrees_Of_Freedom:
1597 case Invalid_Number_Detected:
1598 SCIPdebugMsg(
scip,
"Ipopt failed because of an invalid number in function or derivative value\n");
1607 case Insufficient_Memory:
1614 case Unrecoverable_Exception:
1615 case Internal_Error:
1618 SCIPerrorMessage(
"Ipopt returned with application return status %d\n", status);
1622 case Invalid_Problem_Definition:
1623 case Invalid_Option:
1624 case NonIpopt_Exception_Thrown:
1627 SCIPerrorMessage(
"Ipopt returned with application return status %d\n", status);
1631#if IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR < 14
1632 SmartPtr<SolveStatistics> stats = problem->
ipopt->Statistics();
1634 if( IsValid(stats) )
1636 problem->
lastniter = stats->IterationCount();
1637 problem->
lasttime = stats->TotalWallclockTime();
1639#ifdef COLLECT_SOLVESTATS
1640 collectStatistic(
scip, status, problem, stats);
1644 SmartPtr<IpoptData> ip_data = problem->
ipopt->IpoptDataObject();
1646 if( IsValid(ip_data) )
1648 problem->
lastniter = ip_data->iter_count();
1649 problem->
lasttime = ip_data->TimingStats().OverallAlgorithm().TotalWallclockTime();
1658 catch( IpoptException& except )
1660 SCIPerrorMessage(
"Ipopt returned with exception: %s\n", except.Message().c_str());
1694 if( primalvalues !=
NULL )
1697 if( consdualvalues !=
NULL )
1700 if( varlbdualvalues !=
NULL )
1703 if( varubdualvalues !=
NULL )
1720 statistics->niterations = problem->
lastniter;
1721 statistics->totaltime = problem->
lasttime;
1743 nlpiCopyIpopt, nlpiFreeIpopt, nlpiGetSolverPointerIpopt,
1744 nlpiCreateProblemIpopt, nlpiFreeProblemIpopt, nlpiGetProblemPointerIpopt,
1745 nlpiAddVarsIpopt, nlpiAddConstraintsIpopt, nlpiSetObjectiveIpopt,
1746 nlpiChgVarBoundsIpopt, nlpiChgConsSidesIpopt, nlpiDelVarSetIpopt, nlpiDelConstraintSetIpopt,
1747 nlpiChgLinearCoefsIpopt, nlpiChgExprIpopt,
1748 nlpiChgObjConstantIpopt, nlpiSetInitialGuessIpopt, nlpiSolveIpopt, nlpiGetSolstatIpopt, nlpiGetTermstatIpopt,
1749 nlpiGetSolutionIpopt, nlpiGetStatisticsIpopt,
1758 &nlpidata->warm_start_push,
FALSE, 1e-9, 0.0, 1.0,
NULL,
NULL) );
1760 SmartPtr<RegisteredOptions> reg_options =
new RegisteredOptions();
1761 IpoptApplication::RegisterAllIpoptOptions(reg_options);
1768 if( !IsValid(option) )
1771 assert(option->Type() == OT_String);
1778 std::stringstream descr;
1779 descr << option->ShortDescription();
1783 std::vector<RegisteredOption::string_entry> validvals = option->GetValidStrings();
1784 if( validvals.size() > 1 )
1786 descr <<
" Valid values if not empty:";
1787 for( std::vector<RegisteredOption::string_entry>::iterator val = validvals.begin(); val != validvals.end(); ++val )
1788 descr <<
' ' << val->value_;
1791#if IPOPT_VERSION_MAJOR > 3 || IPOPT_VERSION_MINOR >= 14
1793 advanced = option->Advanced();
1804 SmartPtr<const RegisteredOption> option = reg_options->GetOption(
ipopt_int_params[
i]);
1807 if( !IsValid(option) )
1810 assert(option->Type() == OT_Integer);
1816 int lower = option->LowerInteger();
1817 int upper = option->UpperInteger();
1824 std::stringstream descr;
1825 descr << option->ShortDescription();
1826 descr <<
' ' << (lower-1) <<
" to use NLPI or Ipopt default.";
1828#if IPOPT_VERSION_MAJOR > 3 || IPOPT_VERSION_MINOR >= 14
1830 advanced = option->Advanced();
1835 i == 0 ? &nlpidata->print_level :
NULL, advanced,
1836 lower-1, lower-1, upper,
NULL,
NULL) );
1845 return "Ipopt " IPOPT_VERSION;
1851 return "Interior Point Optimizer developed by A. Waechter et.al. (github.com/coin-or/Ipopt)";
1867 return nlpiproblem->
oracle;
1871bool ScipNLP::get_nlp_info(
1876 IndexStyleEnum& index_style
1892 nnz_jac_g = offset[m];
1894 if( !approxhessian )
1900 nnz_h_lag = offset[n];
1907 index_style = TNLP::C_STYLE;
1913bool ScipNLP::get_bounds_info(
1922 const int* varlincounts;
1923 const int* varnlcounts;
1937 for(
int i = 0;
i < n; ++
i )
1947 for(
int i = 0;
i < n; ++
i )
1949 if( varlincounts[
i] == 0 && varnlcounts[
i] == 0 )
1951 SCIPdebugMsg(scip,
"fix unused variable x%d [%g,%g] to 0.0 or bound\n",
i, x_l[
i], x_u[
i]);
1953 x_l[
i] = x_u[
i] =
MAX(
MIN(x_u[
i], 0.0), x_l[
i]);
1957 for(
int i = 0;
i < m; ++
i )
1968bool ScipNLP::get_starting_point(
1988 assert(nlpiproblem->solprimalvalid);
1995 assert(nlpiproblem->soldualvalid);
2004 assert(nlpiproblem->soldualvalid);
2013Index ScipNLP::get_number_of_nonlinear_variables()
2024 for(
int i = 0;
i < n; ++
i )
2032bool ScipNLP::get_list_of_nonlinear_variables(
2033 Index num_nonlin_vars,
2034 Index* pos_nonlin_vars
2046 for(
int i = 0;
i < n; ++
i )
2050 assert(count < num_nonlin_vars);
2051 pos_nonlin_vars[count++] =
i;
2055 assert(count == num_nonlin_vars);
2061bool ScipNLP::get_var_con_metadata(
2063 StringMetaDataMapType& var_string_md,
2064 IntegerMetaDataMapType& var_integer_md,
2065 NumericMetaDataMapType& var_numeric_md,
2067 StringMetaDataMapType& con_string_md,
2068 IntegerMetaDataMapType& con_integer_md,
2069 NumericMetaDataMapType& con_numeric_md
2078 if( varnames !=
NULL )
2080 std::vector<std::string>& varnamesvec(var_string_md[
"idx_names"]);
2081 varnamesvec.reserve((
size_t)n);
2082 for(
int i = 0;
i < n; ++
i )
2084 if( varnames[
i] !=
NULL )
2086 varnamesvec.push_back(varnames[
i]);
2092 varnamesvec.push_back(buffer);
2097 std::vector<std::string>& consnamesvec(con_string_md[
"idx_names"]);
2098 consnamesvec.reserve((
size_t)m);
2099 for(
int i = 0;
i < m; ++
i )
2109 consnamesvec.push_back(buffer);
2117bool ScipNLP::eval_f(
2131 last_f_eval_x = current_x;
2137bool ScipNLP::eval_grad_f(
2156 new_x = last_f_eval_x < current_x;
2160 last_f_eval_x = current_x;
2166bool ScipNLP::eval_g(
2181 last_g_eval_x = current_x;
2190bool ScipNLP::eval_jac_g(
2207 if( values ==
NULL )
2209 const int* jacoffset;
2220 assert(jacoffset[0] == 0);
2221 assert(jacoffset[m] == nele_jac);
2223 for(
i = 0;
i < m; ++
i )
2224 for( ; j < jacoffset[
i+1]; ++j )
2236 new_x = last_g_eval_x < current_x;
2240 last_f_eval_x = current_x;
2253bool ScipNLP::eval_h(
2259 const Number* lambda,
2273 if( values ==
NULL )
2275 const int* heslagoffset;
2276 const int* heslagcol;
2286 assert(heslagoffset[0] == 0);
2287 assert(heslagoffset[n] == nele_hess);
2288 j = heslagoffset[0];
2289 for(
i = 0;
i < n; ++
i )
2290 for( ; j < heslagoffset[
i+1]; ++j )
2297 bool new_x_obj = new_x;
2298 bool new_x_cons = new_x;
2305 new_x_obj = last_f_eval_x < current_x;
2306 new_x_cons = last_g_eval_x < current_x;
2309 last_f_eval_x = current_x;
2310 last_g_eval_x = current_x;
2324bool ScipNLP::intermediate_callback(
2332 Number regularization_size,
2336 const IpoptData* ip_data,
2337 IpoptCalculatedQuantities* ip_cq
2348 if( obj_value <= param.lobjlimit && inf_pr <= param.feastol )
2362 conv_lastrestoiter = -1;
2364 else if( mode == RestorationPhaseMode )
2366 conv_lastrestoiter = iter;
2368 else if( conv_lastrestoiter == iter-1 )
2390 if( inf_pr <= conv_prtarget[
i] )
2399 else if( iter >= conv_iterlim[
i] )
2402 SCIPdebugMsg(scip,
"convcheck %d: inf_pr = %e > target %e; inf_du = %e target %e: ",
2403 i, inf_pr, conv_prtarget[
i], inf_du, conv_dutarget[
i]);
2409 SCIPdebugPrintf(
"continue, because restoration phase only %d iters ago\n", iter - conv_lastrestoiter);
2411 else if( mode == RegularMode && inf_du <= conv_dutarget[
i] && iter < conv_iterlim[
i] +
convcheck_maxiter[
i] )
2414 SCIPdebugPrintf(
"continue, because dual infeas. red. sufficient and only %d iters above limit\n", iter - conv_iterlim[
i]);
2419 if( inf_pr <= param.feastol )
2435void ScipNLP::finalize_solution(
2436 SolverReturn status,
2443 const Number* lambda,
2445 const IpoptData* data,
2446 IpoptCalculatedQuantities* cq
2455 bool check_feasibility =
false;
2464 case STOP_AT_ACCEPTABLE_POINT:
2466 case FEASIBLE_POINT_FOUND:
2472 case MAXITER_EXCEEDED:
2473 check_feasibility =
true;
2478 case CPUTIME_EXCEEDED:
2479#if IPOPT_VERSION_MAJOR > 3 || IPOPT_VERSION_MINOR >= 14
2480 case WALLTIME_EXCEEDED:
2482 check_feasibility =
true;
2487 case STOP_AT_TINY_STEP:
2488 case RESTORATION_FAILURE:
2489 case ERROR_IN_STEP_COMPUTATION:
2490 check_feasibility =
true;
2495 case LOCAL_INFEASIBILITY:
2500 case USER_REQUESTED_STOP:
2504 case DIVERGING_ITERATES:
2513 case INVALID_NUMBER_DETECTED:
2517 check_feasibility =
true;
2522 case TOO_FEW_DEGREES_OF_FREEDOM:
2523 case INTERNAL_ERROR:
2524 case INVALID_OPTION:
2535 SCIPerrorMessage(
"Ipopt returned with unknown solution status %d\n", status);
2548 if( nlpiproblem->soldualcons ==
NULL )
2552 if( nlpiproblem->soldualvarlb ==
NULL )
2556 if( nlpiproblem->soldualvarub ==
NULL )
2560 if( nlpiproblem->soldualcons ==
NULL || nlpiproblem->soldualvarlb ==
NULL || nlpiproblem->soldualvarub ==
NULL )
2571 nlpiproblem->solobjval = obj_value;
2572 nlpiproblem->solprimalvalid =
true;
2573 nlpiproblem->solprimalgiven =
false;
2574 nlpiproblem->soldualvalid =
true;
2575 nlpiproblem->soldualgiven =
false;
2578#if IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR < 14
2579 nlpiproblem->solboundviol = 0.0;
2583 nlpiproblem->solconsviol = 0.0;
2588 nlpiproblem->solboundviol = cq->unscaled_curr_orig_bounds_violation(Ipopt::NORM_MAX);
2592 nlpiproblem->solconsviol = cq->unscaled_curr_nlp_constraint_violation(Ipopt::NORM_MAX);
2594 if( check_feasibility )
2598 if(
MAX(nlpiproblem->solconsviol, nlpiproblem->solboundviol) <= param.feastol )
2604 catch(
const IpoptNLP::Eval_Error& exc )
2606 SCIPdebugMsg(scip,
"Eval error when checking constraint viol: %s\n", exc.Message().c_str());
2607 assert(status == INVALID_NUMBER_DETECTED);
2616 SCIPdebugMsg(scip,
"Unknown exception when checking constraint viol\n");
2617 assert(status == INVALID_NUMBER_DETECTED);
2626 (void) nlpiproblem->ipopt->Options()->GetNumericValue(
"tol", tol,
"");
2631 bool infreasonable =
true;
2633 for(
int i = 0;
i < m && infreasonable; ++
i )
2635 if( fabs(lambda[
i]) < tol )
2638 if( lambda[
i] < 0.0 )
2646 SCIPdebugMessage(
"inconsistent dual, lambda = %g, but lhs = %g\n", lambda[
i], side);
2647 infreasonable =
false;
2658 SCIPdebugMessage(
"inconsistent dual, lambda = %g, but rhs = %g\n", lambda[
i], side);
2659 infreasonable =
false;
2664 infproof += lambda[
i] * (g[
i] - side);
2669 SCIPdebugMessage(
"infproof = %g should be positive to be valid\n", infproof);
2670 if( infproof <= 0.0 )
2671 infreasonable =
false;
2674 if( !infreasonable )
2695#if IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR < 14
2696 IpLapackDsyev((
bool)computeeigenvectors, N,
a, N,
w, info);
2698 IpLapackSyev((
bool)computeeigenvectors, N,
a, N,
w, info);
2703 SCIPerrorMessage(
"There was an error when calling DSYEV. INFO = %d\n", info);
2734#if IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR < 14
2735 IpLapackDgetrf(N, Acopy, pivotcopy, N, info);
2737 IpLapackGetrf(N, Acopy, pivotcopy, N, info);
2742 SCIPdebugMessage(
"There was an error when calling Dgetrf. INFO = %d\n", info);
2750#if IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR < 14
2751 IpLapackDgetrs(N, 1, Acopy, N, pivotcopy, bcopy, N);
2753 IpLapackGetrs(N, 1, Acopy, N, pivotcopy, bcopy, N);
2805#if IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR < 14
2806 IpLapackDgetrf(N, Acopy, pivotcopy, N, info);
2808 IpLapackGetrf(N, Acopy, pivotcopy, N, info);
2813 SCIPdebugMessage(
"There was an error when calling Dgetrf. INFO = %d\n", info);
2821#if IPOPT_VERSION_MAJOR == 3 && IPOPT_VERSION_MINOR < 14
2822 IpLapackDgetrs(N, 1, Acopy, N, pivotcopy, bcopy, N);
2824 IpLapackGetrs(N, 1, Acopy, N, pivotcopy, bcopy, N);
#define SCIP_CALL_ABORT(x)
methods to interpret (evaluate) an expression "fast"
int SCIPgetSubscipDepth(SCIP *scip)
SCIP_EXPRINTCAPABILITY SCIPexprintGetCapability(void)
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
SCIP_MESSAGEHDLR * SCIPgetMessagehdlr(SCIP *scip)
SCIP_RETCODE SCIPincludeNlpSolverIpopt(SCIP *scip)
SCIP_RETCODE SCIPnlpiOracleEvalObjectiveValue(SCIP *scip, SCIP_NLPIORACLE *oracle, const SCIP_Real *x, SCIP_Real *objval)
SCIP_RETCODE SCIPnlpiOracleChgLinearCoefs(SCIP *scip, SCIP_NLPIORACLE *oracle, int considx, int nentries, const int *varidxs, const SCIP_Real *newcoefs)
SCIP_RETCODE SCIPnlpiOracleChgVarBounds(SCIP *scip, SCIP_NLPIORACLE *oracle, int nvars, const int *indices, const SCIP_Real *lbs, const SCIP_Real *ubs)
SCIP_RETCODE SCIPnlpiOracleAddConstraints(SCIP *scip, SCIP_NLPIORACLE *oracle, int nconss, const SCIP_Real *lhss, const SCIP_Real *rhss, const int *nlininds, int *const *lininds, SCIP_Real *const *linvals, SCIP_EXPR **exprs, const char **consnames)
SCIP_Bool SCIPnlpiOracleIsConstraintNonlinear(SCIP_NLPIORACLE *oracle, int considx)
SCIP_RETCODE SCIPnlpiOracleDelVarSet(SCIP *scip, SCIP_NLPIORACLE *oracle, int *delstats)
SCIP_RETCODE SCIPnlpiOracleEvalConstraintValues(SCIP *scip, SCIP_NLPIORACLE *oracle, const SCIP_Real *x, SCIP_Real *convals)
SCIP_RETCODE SCIPnlpiOracleCreate(SCIP *scip, SCIP_NLPIORACLE **oracle)
SCIP_RETCODE SCIPnlpiOracleGetJacobianSparsity(SCIP *scip, SCIP_NLPIORACLE *oracle, const int **offset, const int **col)
void SCIPnlpiOracleGetVarCounts(SCIP *scip, SCIP_NLPIORACLE *oracle, const int **lincounts, const int **nlcounts)
SCIP_RETCODE SCIPnlpiOracleGetHessianLagSparsity(SCIP *scip, SCIP_NLPIORACLE *oracle, const int **offset, const int **col)
char * SCIPnlpiOracleGetConstraintName(SCIP_NLPIORACLE *oracle, int considx)
SCIP_RETCODE SCIPnlpiOracleEvalObjectiveGradient(SCIP *scip, SCIP_NLPIORACLE *oracle, const SCIP_Real *x, SCIP_Bool isnewx, SCIP_Real *objval, SCIP_Real *objgrad)
SCIP_RETCODE SCIPnlpiOracleResetEvalTime(SCIP *scip, SCIP_NLPIORACLE *oracle)
SCIP_RETCODE SCIPnlpiOracleSetObjective(SCIP *scip, SCIP_NLPIORACLE *oracle, const SCIP_Real constant, int nlin, const int *lininds, const SCIP_Real *linvals, SCIP_EXPR *expr)
SCIP_Real SCIPnlpiOracleGetConstraintRhs(SCIP_NLPIORACLE *oracle, int considx)
SCIP_Real SCIPnlpiOracleGetEvalTime(SCIP *scip, SCIP_NLPIORACLE *oracle)
SCIP_RETCODE SCIPnlpiOracleChgConsSides(SCIP *scip, SCIP_NLPIORACLE *oracle, int nconss, const int *indices, const SCIP_Real *lhss, const SCIP_Real *rhss)
SCIP_Real SCIPnlpiOracleGetConstraintLhs(SCIP_NLPIORACLE *oracle, int considx)
SCIP_RETCODE SCIPnlpiOracleAddVars(SCIP *scip, SCIP_NLPIORACLE *oracle, int nvars, const SCIP_Real *lbs, const SCIP_Real *ubs, const char **varnames)
int SCIPnlpiOracleGetNVars(SCIP_NLPIORACLE *oracle)
int SCIPnlpiOracleGetNConstraints(SCIP_NLPIORACLE *oracle)
SCIP_EXPRINTCAPABILITY SCIPnlpiOracleGetEvalCapability(SCIP *scip, SCIP_NLPIORACLE *oracle)
SCIP_Real SCIPnlpiOracleGetObjectiveConstant(SCIP_NLPIORACLE *oracle)
SCIP_RETCODE SCIPnlpiOracleEvalHessianLag(SCIP *scip, SCIP_NLPIORACLE *oracle, const SCIP_Real *x, SCIP_Bool isnewx_obj, SCIP_Bool isnewx_cons, SCIP_Real objfactor, const SCIP_Real *lambda, SCIP_Real *hessian)
SCIP_Bool SCIPnlpiOracleIsVarNonlinear(SCIP *scip, SCIP_NLPIORACLE *oracle, int varidx)
SCIP_RETCODE SCIPnlpiOracleEvalJacobian(SCIP *scip, SCIP_NLPIORACLE *oracle, const SCIP_Real *x, SCIP_Bool isnewx, SCIP_Real *convals, SCIP_Real *jacobi)
SCIP_RETCODE SCIPnlpiOracleDelConsSet(SCIP *scip, SCIP_NLPIORACLE *oracle, int *delstats)
SCIP_RETCODE SCIPnlpiOracleSetProblemName(SCIP *scip, SCIP_NLPIORACLE *oracle, const char *name)
SCIP_RETCODE SCIPnlpiOracleChgObjConstant(SCIP *scip, SCIP_NLPIORACLE *oracle, SCIP_Real objconstant)
char ** SCIPnlpiOracleGetVarNames(SCIP_NLPIORACLE *oracle)
const SCIP_Real * SCIPnlpiOracleGetVarLbs(SCIP_NLPIORACLE *oracle)
const SCIP_Real * SCIPnlpiOracleGetVarUbs(SCIP_NLPIORACLE *oracle)
SCIP_RETCODE SCIPnlpiOracleFree(SCIP *scip, SCIP_NLPIORACLE **oracle)
struct SCIP_NlpiOracle SCIP_NLPIORACLE
const char * SCIPnlpiOracleGetProblemName(SCIP_NLPIORACLE *oracle)
SCIP_RETCODE SCIPnlpiOracleChgExpr(SCIP *scip, SCIP_NLPIORACLE *oracle, int considx, SCIP_EXPR *expr)
const char * SCIPgetSolverNameIpopt(void)
SCIP_RETCODE SCIPcallLapackDsyevIpopt(SCIP_Bool computeeigenvectors, int N, SCIP_Real *a, SCIP_Real *w)
SCIP_RETCODE SCIPsolveLinearEquationsIpopt(int N, SCIP_Real *A, SCIP_Real *b, SCIP_Real *x, SCIP_Bool *success)
void * SCIPgetNlpiOracleIpopt(SCIP_NLPIPROBLEM *nlpiproblem)
SCIP_Bool SCIPisIpoptAvailableIpopt(void)
const char * SCIPgetSolverDescIpopt(void)
SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_PARAM * SCIPgetParam(SCIP *scip, const char *name)
SCIP_RETCODE SCIPaddStringParam(SCIP *scip, const char *name, const char *desc, char **valueptr, SCIP_Bool isadvanced, const char *defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPincludeExternalCodeInformation(SCIP *scip, const char *name, const char *description)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
SCIP_RETCODE SCIPincludeNlpi(SCIP *scip, 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_NLPICHGEXPR((*nlpichgexpr)), 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_NLPIDATA *nlpidata)
SCIP_NLPIDATA * SCIPnlpiGetData(SCIP_NLPI *nlpi)
SCIP_Bool SCIPisSolveInterrupted(SCIP *scip)
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_Real SCIPfloor(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPrandomGetReal(SCIP_RANDNUMGEN *randnumgen, SCIP_Real minrandval, SCIP_Real maxrandval)
int SCIPsnprintf(char *t, int len, const char *s,...)
SCIPfreeRandom(scip, &heurdata->randnumgen)
SCIPcreateRandom(scip, &heurdata->randnumgen, DEFAULT_RANDSEED, TRUE))
assert(minobj< SCIPgetCutoffbound(scip))
static const char * paramname[]
#define BMSduplicateMemoryArray(ptr, source, num)
#define BMSallocMemoryArray(ptr, num)
#define BMSfreeMemoryArray(ptr)
#define BMScopyMemoryArray(ptr, source, num)
void SCIPmessageVPrintError(const char *formatstr, va_list ap)
void SCIPmessageVPrintInfo(SCIP_MESSAGEHDLR *messagehdlr, const char *formatstr, va_list ap)
void SCIPmessagePrintErrorHeader(const char *sourcefile, int sourceline)
static const SCIP_Real convcheck_minred[convcheck_nchecks]
static const char * ipopt_int_params[]
integer parameters of Ipopt to make available via SCIP parameters
static const int convcheck_startiter
static const int convcheck_nchecks
static SCIP_RETCODE solveLinearProb3(SCIP_Real *A, SCIP_Real *b, SCIP_Real *x, SCIP_Bool *success)
static SCIP_RETCODE handleNlpParam(SCIP *scip, SCIP_NLPIDATA *nlpidata, SCIP_NLPIPROBLEM *nlpiproblem, const SCIP_NLPPARAM param)
pass NLP solve parameters to Ipopt
static const char * ipopt_string_params[]
string parameters of Ipopt to make available via SCIP parameters
static SCIP_RETCODE ensureStartingPoint(SCIP *scip, SCIP_NLPIPROBLEM *problem, SCIP_Bool &warmstart)
static const int convcheck_maxiter[convcheck_nchecks]
static void invalidateSolved(SCIP_NLPIPROBLEM *problem)
static void invalidateSolution(SCIP_NLPIPROBLEM *problem)
methods to store an NLP and request function, gradient, and Hessian values
char * SCIPparamGetString(SCIP_PARAM *param)
int SCIPparamGetInt(SCIP_PARAM *param)
int SCIPparamGetIntDefault(SCIP_PARAM *param)
public methods for message output
public data structures and miscellaneous methods
public methods for handling parameter settings
public methods for problem copies
public methods for memory management
public methods for message handling
public methods for NLPI solver interfaces
public methods for numerical tolerances
public methods for SCIP parameter handling
public methods for random numbers
SCIP_NLPPARAM_FASTFAIL fastfail
SmartPtr< IpoptApplication > ipopt
SCIP_RANDNUMGEN * randnumgen
SCIP_NLPTERMSTAT termstat
#define SCIP_EXPRINTCAPABILITY_GRADIENT
#define SCIP_EXPRINTCAPABILITY_HESSIAN
#define SCIP_EXPRINTCAPABILITY_FUNCVALUE
unsigned int SCIP_EXPRINTCAPABILITY
struct SCIP_RandNumGen SCIP_RANDNUMGEN
#define SCIP_DECL_NLPISOLVE(x)
struct SCIP_NlpiProblem SCIP_NLPIPROBLEM
#define SCIP_DECL_NLPICHGLINEARCOEFS(x)
#define SCIP_DECL_NLPICHGOBJCONSTANT(x)
#define SCIP_NLPPARAM_PRINT(param)
#define SCIP_DECL_NLPIGETSOLUTION(x)
#define SCIP_DECL_NLPISETOBJECTIVE(x)
#define SCIP_DECL_NLPICREATEPROBLEM(x)
#define SCIP_DECL_NLPIGETSTATISTICS(x)
#define SCIP_DECL_NLPIDELCONSSET(x)
#define SCIP_DECL_NLPICHGCONSSIDES(x)
#define SCIP_DECL_NLPIDELVARSET(x)
#define SCIP_DECL_NLPICHGEXPR(x)
#define SCIP_DECL_NLPIADDVARS(x)
@ SCIP_NLPPARAM_FASTFAIL_OFF
@ SCIP_NLPPARAM_FASTFAIL_AGGRESSIVE
enum SCIP_NlpSolStat SCIP_NLPSOLSTAT
#define SCIP_DECL_NLPISETINITIALGUESS(x)
#define SCIP_DECL_NLPIFREEPROBLEM(x)
@ SCIP_NLPTERMSTAT_TIMELIMIT
@ SCIP_NLPTERMSTAT_NUMERICERROR
@ SCIP_NLPTERMSTAT_EVALERROR
@ SCIP_NLPTERMSTAT_LOBJLIMIT
@ SCIP_NLPTERMSTAT_ITERLIMIT
@ SCIP_NLPTERMSTAT_OUTOFMEMORY
@ SCIP_NLPTERMSTAT_INTERRUPT
#define SCIP_DECL_NLPICOPY(x)
#define SCIP_DECL_NLPIGETSOLVERPOINTER(x)
#define SCIP_DECL_NLPIGETSOLSTAT(x)
#define SCIP_DECL_NLPICHGVARBOUNDS(x)
#define SCIP_DECL_NLPIGETPROBLEMPOINTER(x)
#define SCIP_DECL_NLPIFREE(x)
#define SCIP_DECL_NLPIADDCONSTRAINTS(x)
@ SCIP_NLPSOLSTAT_UNBOUNDED
@ SCIP_NLPSOLSTAT_LOCINFEASIBLE
@ SCIP_NLPSOLSTAT_FEASIBLE
@ SCIP_NLPSOLSTAT_UNKNOWN
#define SCIP_DECL_NLPIGETTERMSTAT(x)
struct SCIP_NlpParam SCIP_NLPPARAM
enum SCIP_NlpTermStat SCIP_NLPTERMSTAT
struct SCIP_NlpiData SCIP_NLPIDATA
struct SCIP_Param SCIP_PARAM
enum SCIP_Retcode SCIP_RETCODE