The top-level interface of your C function needs to have a certain form to be recognized in AMPL, as described under "User-defined functions" at
http://ampl.com/REFS/hooking2.pdf#page=19. There are some examples of the needed "funcadd" code at
http://ampl.com/netlib/ampl/solvers and another example is given by
http://orfe.princeton.edu/~rvdb/ampl/nlmodels/funcadd.c.
Typically the AMPL funcadd code serves as a wrapper around the code that actually evaluates the function. There must be a single return value, but there can be a vector of arguments, as in for example
int ({j in 1..n} x[j])
If jacobian and hessian information is to be returned, then those values will also need to be computed in your code and stored in the argument data structure (described in the documentation) prior to returning the function value. (With Knitro you have the option of asking for derivatives to be estimated automatically using finite differencing, in which case your function does not need to supply derivatives but the solves are likely to be slower.)
Bob Fourer
am...@googlegroups.com
Cc:
4...@ampl.com
Subject: Re: [AMPL 14411] Monte Carlo integration in AMPL
Very helpful! I'll look into writing a numerical integration function in C and passing it to AMPL.
Sorry for not being clear, but I am maximizing an objective function, say F, in which one of the model variables is an integral, say G(x) = \int_s g(s,x)dP(s), where s is a multi-dimensional random variable to be integrated over, distributed according to cdf P(), and x is a multi-dimensional variable to be maximized over. Suppose I wrote a C function to take as inputs x, P(), g() and produce via a Matlab numerical integration script the output G(x). How would a solver, say KNITRO, obtain jacobian and hessian information on G(x) in order to maximize F? Do I need to manually supply such information to KNITRO, and how?