TRY NOW!
AMPL > >Products > >AMPL API

AMPL API
Beta Test version now available

Our new Application Programming Interface, AMPL API, provides an object-oriented callable library that lets you access AMPL models and run AMPL commands from external programs. Data and results can be exchanged directly and efficiently between AMPL’s model entities and the external language’s data structures. Uses include:

  • Programming complex algorithmic schemes
  • Embedding AMPL in enterprise applications
  • Deployment of AMPL models

We invite you to test the beta versions of the first two AMPL API releases, for Java and MATLAB, and to send your observations, suggestions, and complaints to us at beta@ampl.com. Your reactions will provide valuable guidance as we prepare the first general release version.

To get started, follow the installation and startup instructions below that correspond to your operating system:

These instructions add AMPL API to an existing installation of command-line AMPL and solvers, after which it can be used in conjunction with any Java or MATLAB installation. Full class documentation and some introductory examples are included with the installation materials. Contact us at support@ampl.com if you need help completing the AMPL or API setup.

The beta test period runs through September 2013, and installed beta versions will continue to operate through December 2013.

AMPL API is developed in partnership with Optirisk Systems. Future released are planned for support of C++, C#/.NET, Python, and R.

Microsoft Windows

Locate the folder on your computer that contains the program file ampl.exe (as well as other AMPL files). This is the “AMPL folder” that will be used for the AMPL API installation.

Determine whether you installed a 32-bit or a 64-bit version of AMPL. This information appeared in the name of the installation file that you downloaded, and is also found in the message displayed by the AMPL command “option version;”.

Now download the appropriate AMPL API package zipfile, by using the primary site or secondary site link below:

Double-click the zipfile icon, or apply an unzip utility, to extract the contents of the zipfile. When the extraction is complete you will see a folder named amplapi (possibly inside another folder named amplapi.win32 or amplapi.win64). Move the amplapi folder into your AMPL folder, by dragging or cutting and pasting the amplapi folder icon.

To use with Java, be sure that you have a valid JDK installation (release 1.6 or later) accessible; if necessary you can download the latest release. You can make an initial test using the examples in amplapi\examples\java. In a Command Prompt window, cd to that folder and enter the following to compile and then run:

javac -cp ../../ampl-0.1.jar FirstExample.java
java -cp ../../ampl-0.1.jar;. FirstExample

Or, use your preferred Java IDE. To view the documentation, go to the folder amplapi\docs\java and double-click the icon for file reference-java.html.

To use with MATLAB, open the MATLAB application window and set the path to amplapi\examples\MATLAB. Enter the following to initialize the session and then run an example:

setupOnce
firstExample

To view the documentation, go to the folder amplapi\docs\matlab in Windows, and double-click the icon for file reference-MATLAB.html.

Linux

Locate the folder on your computer that contains the program file ampl (as well as other AMPL files). This is the “AMPL folder” that will be used for the AMPL API installation.

Determine whether you installed a 32-bit or a 64-bit version of AMPL. This information appeared in the name of the installation file that you downloaded, and is also found in the message displayed by the AMPL command “option version;”.

Now download the appropriate AMPL API package zipfile, by using the primary site or secondary site link below:

Extract the contents of the package by typing the command

unzip amplapi.linux??.zip

where ?? is replaced by 32 or 64 as appropriate. When the extraction is complete you will see a directory named amplapi. Move this amplapi directory into your AMPL directory, so that it appears as a subdirectory of your AMPL directory.

To use with Java, be sure that you have a valid JDK installation (release 1.6 or later) accessible; if necessary you can download the latest release. You can make an initial test using the examples in amplapi/examples/java. Make amplapi your current directory, and enter the following to compile and then run:

javac -cp ../../ampl-0.1.jar FirstExample.java
java -cp ../../ampl-0.1.jar:. FirstExample

Or, use your preferred Java IDE. To view the documentation, open the file amplapi/docs/java/reference-java.html in a browser application.

To use with MATLAB, open the MATLAB application window and set the path to amplapi/examples/MATLAB. Enter the following to initialize the session and then run an example:

setupOnce
firstExample

To view the documentation, go to the directory amplapi/docs/matlab in Linux, open the file amplapi/docs/matlab/reference-MATLAB.html in a browser application.

Max OS X

Locate the folder on your computer that contains the icon for the ampl program (as well as other AMPL files). This is the “AMPL folder” that will be used for the AMPL API installation.

Determine whether you installed a 32-bit or a 64-bit version of AMPL. This information appeared in the name of the installation file that you downloaded, and is also found in the message displayed by the AMPL command “option version;”.

Now download the AMPL API package zipfile, by using the primary site or secondary site link below:

Double-click this file’s icon to extract its contents. When the extraction is complete you will see a folder named amplapi. Drag the amplapi folder icon into your AMPL folder.

To use with Java, be sure that you have a valid JDK installation (release 1.6 or later) accessible; if necessary you can download the latest release. You can make an initial test using the examples in amplapi/examples/java. In a Terminal window, cd to that folder and enter the following to compile and then run:

javac -cp ../../ampl-0.1.jar FirstExample.java
java -cp ../../ampl-0.1.jar:. FirstExample

Or, use your preferred Java IDE. To view the documentation, go to the folder amplapi/docs/java and double-click the icon for file reference-java.html.

To use with MATLAB, open the MATLAB application window and set the path to amplapi/examples/MATLAB. Enter the following to initialize the session and then run an example:

setupOnce
firstExample

To view the documentation, go to the folder amplapi/docs/matlab in MacOSX, and double-click the icon for file reference-MATLAB.html.