Forum Discussion

FICO's avatar
FICO
Community Manager
5 years ago

How do I add a user function definition to an SLP problem in C#?

I am evaluating Xpress Nonlinear Solver v.8.11.0 which I am going to use with .NET. There is a good example Polygon.cs which shows how to pass a nonlinear objective function and constraints to XSLP provided they can be defined algebraically. However, in the applications I am developing, most of the objective functions and constraints are defined algorithmically. So I need to specify a user-defined C# method and to pass its reference/delegate to XSLP. There is another good example ComplexUserFunctions.c which is doing precisely what I need, and it uses the C function XSLPadduserfunction() with the following signature:

int XPRS_CC XSLPadduserfunction(XSLPprob Prob, const char * FunctionName, int FunctionType, int nInput, int nOutput, int Options, void * FunctionPointer, void * UserContext, int * FunctionTokenId);

(well-documented in the Xpress Nonlinear manual).

In my C# code, I tried to use the following:

XSLP sProb = new XSLP();
sProb.addUserFuncs(nSLPUserFunc, Type, Value);

The function addUserFuncs() requires a different set of arguments, and I don't even see the user function's reference or delegate among them. Its signature is

int addUserFuncs(int nSLPUserFunc, int[] Type, double[] Value);

which is obviously quite different from that in C. I couldn't find any documentation about it.

Can somebody explain to me how to pass user-defined (black-box) functions to XSLP in C#? Or show me where I can read about it (preferably with a C# example)? Can somebody help me to reproduce the ComplexUserFunctions.c example in C#?

Thanks,

Alexander

No RepliesBe the first to reply