UPDATE: AMPL has since added support for the GNU Scientific Library which includes an error function, as discussed here.
AMPL does not have a built in function for the normal cdf (error function) — see the post from Robert Fourer on the Google Groups page for AMPL (a great resource). To use the function in a model, you need to use a shared C library that can do the computation. I got it working (on my Mac) using the following process.
The AMPL site has a page on this topic. It turns out you need to find the folder …/ampl/solvers/ on your system. I couldn’t find it for my version of AMPL (perhaps because I have a version that comes packaged with the Knitro solver). But netlib.org hosts a copy of the folder. They say you can get a copy of the whole thing by emailing them, but this didn’t work quickly for me, so I used
wget to download the whole thing, as described here, with the following command:
wget -r -np -nH –cut-dirs=3 -R index.html http://www.netlib.org/ampl/solvers
The goal is to compile the file …/ampl/solvers/funclink/funcadd.c into the library amplfunc.dlll. (This funcadd.c doesn’t include the error function, but that’s the easy part once you get this working…) I tried to compile with the following commands (which require compilers — you can get these on a Mac by downloading Xcode):
cd .../ampl/solvers/funclink make -f makefile.macosx
This threw me an error that there was no stdio1.h. I tried renaming …/ampl/solvers/stdio1.h0 to …/ampl/solvers/stdio1.h and that seemed to resolve the issue. I was able to successfully run
ampl silly.x >silly.out 2>silly.2
as described in the funclink README. But we still don’t have error function code itself. To get it, downloaded Robert Vanderbei’s code for his version of funcadd.c, which includes a function
myerf(). I replaced the file …/ampl/solvers/funclink/funcadd.c from netlib.org with Vanderbei’s version and tried to recompile using the
make command above. Turns out I also needed to download Vanderbei’s file myalloc.h, which I placed in …/ampl/solvers/funclink/, and the compiler couldn’t initially find OS X’s built-in malloc.h, so I changed the following line in myalloc.h:
This worked, and regenerated the file amplfunc.dlll, though it threw a bunch of warnings in the process. I copied this file into the directory where I wanted to run the AMPL model from (AMPL automatically looks for such a file in the directory where it is launched). Upon launching AMPL interactively, I typed
to import the function, then
and I got the output:
myerf(1.96) = 0.975002