54#include "worhp/worhp.h"
56#if WORHP_MAJOR < 2 && WORHP_MINOR < 10
57#error "Require at least Worhp 1.10"
60#define NLPI_DESC "Worhp interface"
61#define NLPI_PRIORITY_IP 0
62#define NLPI_PRIORITY_SQP -2000
64#define DEFAULT_VERBLEVEL 0
65#define DEFAULT_SCALEDKKT TRUE
66#define DEFAULT_RANDSEED 107
68#define MAXPERTURB 0.01
149 switch( problem->
cnt->status )
184 SCIPdebugMsg(
scip,
"Worhp failed because of a NaN value in an evaluation!\n");
197 SCIPdebugMsg(
scip,
"Worhp failed because of a numerical error during optimization!\n");
208 SCIPdebugMsg(
scip,
"Worhp failed because maximal number of calls or iterations is reached!\n");
240 SCIPdebugMsg(
scip,
"Worhp failed because of convergence against infeasible stationary point!\n");
250 SCIPdebugMsg(
scip,
"Worhp failed because of convergence against infeasible stationary point!\n");
260 SCIPdebugMsg(
scip,
"Worhp failed because of regularization of Hessian matrix failed!\n");
279 SCIPdebugMsg(
scip,
"Worhp terminated successfully with a feasible point but KKT are not met!\n");
290 SCIPdebugMsg(
scip,
"Worhp terminated successfully with a feasible point but KKT are violated in unscaled space!\n");
299 SCIPdebugMsg(
scip,
"Worhp terminated at feasible solution without further progress!\n");
308 SCIPdebugMsg(
scip,
"Worhp terminated at feasible solution, optimality was not required!\n");
318 SCIPdebugMsg(
scip,
"Worhp terminated at acceptable solution due to limit or error!\n");
328 SCIPdebugMsg(
scip,
"Worhp previously found acceptable solution but terminated due to limit or error!\n");
337 SCIPdebugMsg(
scip,
"Worhp found acceptable solution but terminated due no further progress!\n");
347 SCIPdebugMsg(
scip,
"Worhp found acceptable solution but search direction is small or zero!\n");
358 SCIPdebugMsg(
scip,
"Worhp found acceptable solution but terminated perhaps due to nondifferentiability, unboundedness or at Fritz John point!\n");
366 SCIPerrorMessage(
"Worhp returned with unknown solution status %d\n", problem->
cnt->status);
376 if( problem->
opt->m > 0 )
382 if( problem->
opt->n > 0 )
400 for(
i = 0;
i < problem->
opt->n; ++
i )
402 if( problem->
opt->Lambda[
i] <= 0.0 )
441#ifdef SCIP_DEBUG_USERF
446 for(
i = 0;
i < problem->
opt->n; ++
i )
471#ifdef SCIP_DEBUG_USERG
476 for(
i = 0;
i < problem->
opt->n; ++
i )
479 for(
i = 0;
i < problem->
opt->m; ++
i )
505 problem->
wsp->DF.val) );
508 if( problem->
wsp->ScaleObj != 1.0 )
511 for(
i = 0;
i < problem->
opt->n; ++
i )
512 problem->
wsp->DF.val[
i] *= problem->
wsp->ScaleObj;
515#ifdef SCIP_DEBUG_USERDF
520 for(
i = 0;
i < problem->
opt->n; ++
i )
523 for(
i = 0;
i < problem->
opt->n; ++
i )
524 printf(
" DF[%d] = %g\n",
i, problem->
wsp->DF.val[
i]);
556 for(
i = 0;
i < problem->
wsp->DG.nnz; ++
i )
561#ifdef SCIP_DEBUG_USERDG
563 for(
i = 0;
i < problem->
opt->n; ++
i )
565 for(
i = 0;
i < problem->
wsp->DG.nnz; ++
i )
566 printf(
" DG[%d] = %g\n",
i, problem->
wsp->DG.val[
i]);
609 for(
i = 0;
i < problem->
wsp->HM.nnz; ++
i )
612 if( problem->
wsp->HM.perm[
i] - 1 >= nnonz )
613 problem->
wsp->HM.val[
i] = 0.0;
620 for(
i = 0;
i < problem->
opt->n; ++
i )
622 for(
i = 0;
i < problem->
wsp->HM.nnz; ++
i )
623 printf(
" HM[%d] = %g\n",
i, problem->
wsp->HM.val[
i]);
653 const SCIP_Real* lbs;
654 const SCIP_Real* ubs;
682 wsp->DF.nnz = opt->n;
686 wsp->DG.nnz =
offset[opt->m];
697 for(
i = 0;
i < opt->n; ++
i )
731 for(
i = 0;
i < opt->n; ++
i )
738 for(
i = 0;
i < opt->m; ++
i )
758 for(
i = 0;
i < opt->n; ++
i )
760 wsp->DF.row[
i] =
i + 1;
776 for(
i = 0;
i < opt->m; ++
i )
780 wsp->DG.row[nnonz] =
i + 1;
781 wsp->DG.col[nnonz] = cols[
j] + 1;
785 assert(nnonz == wsp->DG.nnz);
792 if( problem->
par->UserHM || problem->
par->FidifHM || problem->
par->BFGSmethod > 1 )
803 for(
i = 0;
i < opt->n; ++
i )
809 problem->
wsp->HM.row[nnonz] =
i + 1;
810 problem->
wsp->HM.col[nnonz] = cols[
j] + 1;
820 problem->
wsp->HM.row[
k] =
i + 1;
821 problem->
wsp->HM.col[
k] =
i + 1;
833 for(
i = 0;
i < wsp->HM.nnz; ++
i )
849 const SCIP_Real* lbs;
850 const SCIP_Real* ubs;
867 for(
i = 0;
i < problem->
opt->n; ++
i )
869 problem->
opt->XL[
i] = lbs[
i];
870 problem->
opt->XU[
i] = ubs[
i];
874 for(
i = 0;
i < problem->
opt->m; ++
i )
895 if( problem->
opt->initialised )
918 par->Algorithm = nlpidata->useip ? 2 : 1;
925 SCIPdebugMsg(
scip,
"warmstart parameter not supported by Worhp interface yet. Ignored.\n");
935 SCIPdebugMsg(
scip,
"fastfail parameter not supported by Worhp interface yet. Ignored.\n");
938 par->TolFeas = nlpparam.
feastol;
939 par->TolOpti = nlpparam.
opttol;
940 par->TolComp = nlpparam.
opttol;
947 par->CheckValuesDF =
TRUE;
948 par->CheckValuesDG =
TRUE;
949 par->CheckValuesHM =
TRUE;
1000 (*problem)->firstrun =
TRUE;
1009 WorhpPreInit((*problem)->opt, (*problem)->wsp, (*problem)->par, (*problem)->cnt);
1025 if( (*problem)->opt !=
NULL )
1042 if( (*problem)->oracle !=
NULL )
1067 problem->firstrun =
TRUE;
1087 problem->firstrun =
TRUE;
1106 problem->firstrun =
TRUE;
1120#ifdef SCIP_DISABLED_CODE
1130#ifdef SCIP_DISABLED_CODE
1137 int index = indices[
i];
1141 if(
REALABS(lbs[
i] - ubs[
i]) <= problem->feastol )
1142 problem->firstrun =
TRUE;
1145 problem->firstrun =
TRUE;
1170 for(
i = 0;
i < nconss; ++
i )
1172 int index = indices[
i];
1200 problem->firstrun =
TRUE;
1216 problem->firstrun =
TRUE;
1232 problem->firstrun =
TRUE;
1248 problem->firstrun =
TRUE;
1274 if( primalvalues !=
NULL )
1276 if( !problem->initguess )
1299 OptVar* opt = problem->opt;
1300 Params* par = problem->par;
1308 if( param.timelimit == 0.0 )
1311 problem->lastniter = 0;
1312 problem->lasttime = 0.0;
1319 problem->lastniter = -1;
1320 problem->lasttime = -1.0;
1322 if( param.verblevel == 0 )
1335 if( problem->firstrun )
1339 problem->firstrun =
FALSE;
1359 if( problem->initguess !=
NULL )
1369 SCIPdebugMsg(
scip,
"Worhp started without initial primal values; make up starting guess by projecting 0 onto variable bounds\n");
1371 for(
i = 0;
i < problem->opt->n; ++
i )
1388 for(
i = 0;
i < problem->opt->n; ++
i )
1410 Worhp(opt, wsp, par, cnt);
1511 problem->lastniter = wsp->MajorIter;
1524 return problem->lastsolstat;
1534 return problem->lasttermstat;
1543 if( primalvalues !=
NULL )
1544 *primalvalues = problem->lastprimal;
1546 if( consdualvalues !=
NULL )
1547 *consdualvalues = problem->lastdualcons;
1549 if( varlbdualvalues !=
NULL )
1550 *varlbdualvalues = problem->lastduallb;
1552 if( varubdualvalues !=
NULL )
1553 *varubdualvalues = problem->lastdualub;
1557 if( problem->lastprimal !=
NULL )
1577 statistics->niterations = problem->lastniter;
1580 statistics->consviol = problem->wsp->FeasOrigMax;
1602 nlpidata->useip = useip;
1605 (
void)
setenv(
"WORHP_DISABLE_KEYBOARD_HANDLER",
"1", 0);
1607#if DEFAULT_VERBLEVEL == 0
1665 return "Nonlinear programming solver developed at Research Institute Steinbeis (www.worhp.de)";
methods to interpret (evaluate) an expression "fast"
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
SCIP_RETCODE SCIPincludeNlpSolverWorhp(SCIP *scip, SCIP_Bool useip)
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)
SCIP_RETCODE SCIPnlpiOracleGetHessianLagSparsity(SCIP *scip, SCIP_NLPIORACLE *oracle, const int **offset, const int **col)
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 SCIPnlpiOraclePrintProblem(SCIP *scip, SCIP_NLPIORACLE *oracle, FILE *file)
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_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_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)
const SCIP_Real * SCIPnlpiOracleGetVarLbs(SCIP_NLPIORACLE *oracle)
const SCIP_Real * SCIPnlpiOracleGetVarUbs(SCIP_NLPIORACLE *oracle)
SCIP_RETCODE SCIPnlpiOracleFree(SCIP *scip, SCIP_NLPIORACLE **oracle)
SCIP_RETCODE SCIPnlpiOracleChgExpr(SCIP *scip, SCIP_NLPIORACLE *oracle, int considx, SCIP_EXPR *expr)
const char * SCIPgetSolverNameWorhp(void)
const char * SCIPgetSolverDescWorhp(void)
SCIP_Bool SCIPisWorhpAvailableWorhp(void)
SCIP_RETCODE SCIPincludeExternalCodeInformation(SCIP *scip, const char *name, const char *description)
#define SCIPfreeMemoryArrayNull(scip, ptr)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
#define SCIPallocClearBlockMemory(scip, ptr)
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
#define SCIPfreeBlockMemory(scip, ptr)
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
#define SCIPallocBlockMemory(scip, ptr)
#define SCIPduplicateBlockMemoryArray(scip, ptr, source, 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_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
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))
methods for catching the user CTRL-C interrupt
#define BMScopyMemoryArray(ptr, source, num)
static SCIP_RETCODE userG(SCIP *scip, SCIP_NLPIPROBLEM *problem)
static void noprint(int mode, const char s[])
static SCIP_RETCODE userDG(SCIP *scip, SCIP_NLPIPROBLEM *problem)
static SCIP_RETCODE userDF(SCIP *scip, SCIP_NLPIPROBLEM *problem)
static SCIP_RETCODE userHM(SCIP *scip, SCIP_NLPIPROBLEM *problem)
#define NLPI_PRIORITY_SQP
static SCIP_RETCODE userF(SCIP *scip, SCIP_NLPIPROBLEM *problem)
static SCIP_RETCODE initWorhp(SCIP *scip, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem)
static SCIP_RETCODE updateWorhp(SCIP_NLPIPROBLEM *problem)
static void invalidateSolution(SCIP *scip, SCIP_NLPIPROBLEM *problem)
static SCIP_RETCODE freeWorhp(SCIP_NLPIPROBLEM *problem)
static SCIP_RETCODE handleNlpParam(SCIP *scip, SCIP_NLPI *nlpi, Params *par, const SCIP_NLPPARAM nlpparam)
#define DEFAULT_SCALEDKKT
static SCIP_RETCODE evaluateWorhpRun(SCIP *scip, SCIP_NLPIPROBLEM *problem)
methods to store an NLP and request function, gradient, and Hessian values
public methods for message output
public data structures and miscellaneous methods
public methods for memory management
public methods for message handling
public methods for NLPI solver interfaces
public methods for numerical tolerances
public methods for random numbers
SCIP_NLPPARAM_FASTFAIL fastfail
SCIP_RANDNUMGEN * randnumgen
SCIP_NLPTERMSTAT lasttermstat
SCIP_NLPSOLSTAT lastsolstat
#define SCIP_DECL_NLPISOLVE(x)
#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)
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_LICENSEERROR
@ SCIP_NLPTERMSTAT_ITERLIMIT
@ SCIP_NLPTERMSTAT_OUTOFMEMORY
@ SCIP_NLPTERMSTAT_INTERRUPT
#define SCIP_DECL_NLPICOPY(x)
#define SCIP_DECL_NLPIGETSOLSTAT(x)
#define SCIP_DECL_NLPICHGVARBOUNDS(x)
#define SCIP_DECL_NLPIFREE(x)
#define SCIP_DECL_NLPIADDCONSTRAINTS(x)
@ SCIP_NLPSOLSTAT_UNBOUNDED
@ SCIP_NLPSOLSTAT_GLOBINFEASIBLE
@ SCIP_NLPSOLSTAT_LOCINFEASIBLE
@ SCIP_NLPSOLSTAT_FEASIBLE
@ SCIP_NLPSOLSTAT_UNKNOWN
#define SCIP_DECL_NLPIGETTERMSTAT(x)
enum SCIP_NlpTermStat SCIP_NLPTERMSTAT
struct SCIP_NlpiData SCIP_NLPIDATA
enum SCIP_Retcode SCIP_RETCODE