The AMPL API can function as an add-on to any existing AMPL installation. If you do not yet have an AMPL installation on the computer where you will be working with the API, see our demo page or trial page to download a working version that can be installed quickly.
Follow the instructions on our AMPL API
page to download the API package appropriate to your platform, and to add
the downloaded folder (directory)
amplapi to your AMPL installation.
Be sure that you have a valid JDK installation (release 1.6 or later) accessible. If necessary you can download the latest release.
To make an initial test, open a command/terminal window and make
amplapi/examples/java the current folder (directory). Then enter the
following commands to compile and then run a simple example: from
Linux or MacOSX,
export LD_LIBRARY_PATH=`pwd`/../../lib:$LD_LIBRARY_PATH # for Linux export DYLD_LIBRARY_PATH=`pwd`/../../lib:$DYLD_LIBRARY_PATH # for OSX javac -cp ../../lib/ampl-220.127.116.11.jar FirstExample.java java -cp ../../lib/ampl-18.104.22.168.jar:. FirstExample <solver>
or from Windows,
cp ../../bin/javaswigwrapper.dll ./ cp ../../bin/ampl-22.214.171.124.dll ./ javac -cp ../../lib/ampl-126.96.36.199.jar FirstExample.java java -cp ../../lib/ampl-188.8.131.52.jar;. FirstExample <solver>
<solver> is the name of a solver that has been installed with AMPL.
(If a solver is not specified, AMPL’s default choice will be used.) Alternatively,
compile and run
FirstExample.java from your preferred Java IDE with
ampl-184.108.40.206.jar included in the class path. This will solve several small diet
problems and then display the optimal amounts of the foods from the last
Note that the folder containing the AMPL executable should be in the system search path.
Otherwise, the error message “AMPL could not be started” will be shown.
If the AMPL installation directory is not in the system search path,
you can add it passing a new
AMPL as follows:
Environment env = new Environment("full path to the AMPL installation directory"); AMPL ampl = new AMPL(env);
Note that you may need to escape backslashes (e.g., “C:\\\ampl\\\ampl.mswin64”) if included in the path.
amplapi/lib/ampl-220.127.116.11.jar in your project that uses the AMPL API. Together with
your existing AMPL implementation, this will provide the full object library
and access to all AMPL functions. The binary files that must be accessible are
platform dependent and listed below, using the main amplapi directory as root:
amplapi folder (directory) can be moved to a different location in your
computer’s filesystem, provided that the location of your AMPL executable has
been placed in the system search path.
To deploy AMPL API applications to users who do not have their own AMPL
installations, include with your Java application the AMPL executable
ampl.exe), the additional files listed in the previous section,
the binaries needed to run any solvers that are used and
an appropriate license file for AMPL and solvers.