Skip to content

Instantly share code, notes, and snippets.

@rschwarz
Created March 2, 2019 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rschwarz/551c10e7ee19249b326d44d69721562f to your computer and use it in GitHub Desktop.
Save rschwarz/551c10e7ee19249b326d44d69721562f to your computer and use it in GitHub Desktop.
C wrapper for SCIPexprCreate without variadic arguments of mixed type.
#include "scip/scip.h"
/*
* To create nonlinear constraints in SCIP, one creates an expression tree whose
* nodes are of type SCIP_EXPR*. To create these nodes, there is a variadic
* function, SCIPexprCreate:
*
* SCIP_RETCODE SCIPexprCreate(BMS_BLKMEM* blkmem, SCIP_EXPR** expr,
* SCIP_EXPROP op, ...);
*
* Julia's ccall facility only supports functions with variadic arguments of the
* same type, but we sometimes need to call this with mixed types.
*
* So, we build thin wrappers for different cases, mostly avoiding variadic
* arguments, at least with mixed types.
*/
SCIP_RETCODE SCIPjlExprCreateVARIDX(
BMS_BLKMEM* blkmem, SCIP_EXPR** expr, SCIP_EXPROP op, int varpos)
{
SCIP_CALL( SCIPexprCreate(blkmem, expr, op, varpos) );
return SCIP_OKAY;
}
SCIP_RETCODE SCIPjlExprCreateCONST(
BMS_BLKMEM* blkmem, SCIP_EXPR** expr, SCIP_EXPROP op, SCIP_Real value)
{
SCIP_CALL( SCIPexprCreate(blkmem, expr, op, value) );
return SCIP_OKAY;
}
SCIP_RETCODE SCIPjlExprCreateREALPOWER(
BMS_BLKMEM* blkmem, SCIP_EXPR** expr, SCIP_EXPROP op, SCIP_EXPR* base, SCIP_Real exponent)
{
SCIP_CALL( SCIPexprCreate(blkmem, expr, op, base, exponent) );
return SCIP_OKAY;
}
SCIP_RETCODE SCIPjlExprCreateUnary(
BMS_BLKMEM* blkmem, SCIP_EXPR** expr, SCIP_EXPROP op, SCIP_EXPR* child)
{
SCIP_CALL( SCIPexprCreate(blkmem, expr, op, child) );
return SCIP_OKAY;
}
SCIP_RETCODE SCIPjlExprCreateBinary(
BMS_BLKMEM* blkmem, SCIP_EXPR** expr, SCIP_EXPROP op, SCIP_EXPR* left, SCIP_EXPR* right)
{
SCIP_CALL( SCIPexprCreate(blkmem, expr, op, left, right) );
return SCIP_OKAY;
}
SCIP_RETCODE SCIPjlExprCreateNAry(
BMS_BLKMEM* blkmem, SCIP_EXPR** expr, SCIP_EXPROP op, int nchildren, ...)
{
// can't forward variadic arguments,
// see http://c-faq.com/varargs/handoff.html ???
SCIP_CALL( SCIPexprCreate(blkmem, expr, op, nchildren, ...) );
return SCIP_OKAY;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment