TRY NOW!
AMPL > >Resources > >Extended Function Library

Extended Function Library

This feature is freely available to all AMPL users. Simple instructions for download, installation, and use in AMPL modeling are given below. A detailed library listing provides full documentation.

This library extends AMPL with over 300 functions chosen from the GNU Scientific Library. Included are scientific, statistical, and utility functions of many kinds, and a variety of random number generators.

Once installed and declared, these functions may be applied to any arguments anywhere in an AMPL model or script. When applied to variables in objectives or constraints, they are sent to solvers, which automatically gain access to them. Thus solvers that rely on function evaluations can optimize over expressions that use this library. Many of the library’s continuous functions also provide for 1st and 2nd derivative evaluations that some solvers require.

Downloading and installing the library

The function library is packaged in a single file named amplgsl_32.dll for 32-bit systems or amplgsl_64.dll for 64-bit systems. This file is available in compressed form through the following links:

Platform32-bit version64-bit version
AIX amplgsl.aix.tgz
Linux-Intelamplgsl.linux-intel32.zipamplgsl.linux-intel64.zip
Mac OS Xamplgsl.macosx32.zipamplgsl.macosx64.zip
Windowsamplgsl.mswin32.zipamplgsl.mswin64.zip

To install, use one of these links to download the appropriate tgz or zip file, copy that file to the same folder or directory as your AMPL executable (ampl or ampl.exe), and then extract amplgsl_32.dll or amplgsl_64.dll from that file. (To carry out the extraction under Unix-based systems including AIX, Linux, and Mac OS X, use a command of the form

gzip -dc amplgsl.linux-intel64.tgz | tar xf -

in a command window or Mac terminal window; to carry out the extraction under Windows, use the built-in zipfile utility or any popular file-compression application.)

Using the functions in AMPL

Once in each session that uses the extended function library, the library file must be loaded with the command*

load amplgsl.dll;

Subsequently, before a particular function is used, it must be declared to the current model with a command of the form

function gsl_funcname;

where funcname is replaced by any of the names in the library listing. As an example, the following model, based on problem 69 of the first Hock-Schittkowski test set, uses a cumulative unit Gaussian density function from the extended library:

function gsl_cdf_ugaussian_P;
param l {1..4};
param u {1..4};
var x {j in 1..4} >= l[j], <= u[j] := 1;
param a := 0.1;
param b := 1000;
param d := 1;
param n := 4;
minimize obj:
  ( a*n - (b*(exp(x[1])-1) - x[3])*x[4]/(exp(x[1]) - 1 + x[4]) )/x[1] ;
subject to constr1:
    x[3] = 2*gsl_cdf_ugaussian_P(-x[2]);
subject to constr2:
    x[4] = gsl_cdf_ugaussian_P(-x[2] + d*sqrt(n)) +
           gsl_cdf_ugaussian_P(-x[2] - d*sqrt(n));

With the appropriate data file,

param:    l       u :=
  1    0.0001   100
  2    0        100
  3    0          2
  4    0          2 ;

the problem can be solved like this:

ampl: model hs069.mod;
ampl: data hs069.dat;
ampl: load amplgsl.dll;
ampl: option solver knitro;
ampl: solve;
KNITRO 8.0.0: Locally optimal solution.
objective -956.7128867; feasibility error 3.41e-11
10 iterations; 11 function evaluations
ampl: display x;
1  0.0293714
2  1.19025
3  0.233947
4  0.791668

* For versions of AMPL earlier than 20120126, the appropriate library file must be chosen explicitly using the command load amplgsl_32.dll or load amplgsl_64.dll as appropriate. If library functions are applied to model variables, then for solvers using versions of the AMPL-solver library older then 20120126, also the type of the solver (32-bit or 64-bit) must match that of AMPL. (Contact support@ampl.com for advice and quotes on updating to newer versions.)

Documentation and licensing

Complete documentation for this library is provided in AMPL Bindings for the GNU Scientific Library. It includes a listing of all functions and their definitions, further instructions for use, and complete license details.

This free-standing library is provided under the GNU General Public License (GPL). In general terms, the GNU GPL does not restrict the use of this library for internal purposes within any organization (whether a company, university, or government agency). However if this library is included within a “release” of software to the public, then you may be required to offer that release under the GPL. See the extensive list of Frequently Asked Questions about the GNU Licenses for more information about these provisions.

For uses that may require functions covered by more permissive open-source licenses, or functions from commercial libraries, please contact us for assistance with alternatives.