diff --git a/CHANGELOG b/CHANGELOG index 48a5928635..a1b9212b8b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -91,6 +91,8 @@ Interface changes ### New API functions +- New function SCIPgetExprActivityNonlinear() to get activity of nonlinear constraint. + ### Command line interface ### Interfaces to external software diff --git a/src/scip/cons_nonlinear.c b/src/scip/cons_nonlinear.c index dd24b4adc7..888d6e4699 100644 --- a/src/scip/cons_nonlinear.c +++ b/src/scip/cons_nonlinear.c @@ -13777,6 +13777,32 @@ SCIP_RETCODE SCIPaddExprNonlinear( return SCIP_OKAY; } +/** computes value of constraint expression in a given solution + * + * Stores value of constraint expression in sol in activity. + * In case of a domain error (function cannot be evaluated in sol), activity is set to SCIP_INVALID. + */ +SCIP_RETCODE SCIPgetExprActivityNonlinear( + SCIP* scip, /**< SCIP data structure */ + SCIP_CONS* cons, /**< constraint */ + SCIP_SOL* sol, /**< solution */ + SCIP_Real* activity /**< buffer to store computed activity */ + ) +{ + SCIP_CONSDATA* consdata; + + assert(cons != NULL); + assert(activity != NULL); + + consdata = SCIPconsGetData(cons); + assert(consdata != NULL); + + SCIP_CALL( SCIPevalExpr(scip, consdata->expr, sol, 0L) ); + *activity = SCIPexprGetEvalValue(consdata->expr); + + return SCIP_OKAY; +} + /** gets absolute violation of nonlinear constraint * * This function evaluates the constraints in the given solution. diff --git a/src/scip/cons_nonlinear.h b/src/scip/cons_nonlinear.h index edaaad4f4f..1e17e58507 100644 --- a/src/scip/cons_nonlinear.h +++ b/src/scip/cons_nonlinear.h @@ -807,6 +807,19 @@ SCIP_RETCODE SCIPregisterExprUsageNonlinear( SCIP_Bool useactivityforsepaabove /**< whether activity of expr will be used by overestimation */ ); +/** computes value of constraint expression in a given solution + * + * Stores value of constraint expression in sol in activity. + * In case of a domain error (function cannot be evaluated in sol), activity is set to SCIP_INVALID. + */ +SCIP_EXPORT +SCIP_RETCODE SCIPgetExprActivityNonlinear( + SCIP* scip, /**< SCIP data structure */ + SCIP_CONS* cons, /**< constraint */ + SCIP_SOL* sol, /**< solution */ + SCIP_Real* activity /**< buffer to store computed activity */ + ); + /** computes absolute violation for auxvar relation in an expression w.r.t. original variables * * Assume the expression is f(x), where x are original (i.e., not auxiliary) variables.