Introduction

What are AMPL APIs?

AMPL APIs are interfaces that allows developers to access the features of the AMPL interpreter from within a programming language. All model generation and solver interaction is handled directly by AMPL, which leads to great stability and speed; the library just acts as an intermediary, and the added overhead (in terms of memory and CPU usage) depends mostly on how much data is read back from AMPL, the size of the model as such is irrelevant. Functions for directly assigning data to AMPL parameters and sets are provided, which can be used instead of the normal AMPL data reading procedures. AMPL API has been written with usability in mind, and it is easy to access its functionalities from Python, R, C++, C#/.NET, Java, and MATLAB.

Who can use AMPL APIs

The intended user of the library is the developer who needs to connect an application to optimization models and solvers, or the analyst with some experience in programming who wants to build a quick proof-of-concept application.

System requirements

In general, amplpy.modules or a valid AMPL setup, and Python 3 are necessary and sufficient conditions for the correct execution of AMPL API.

The officially supported platforms are Windows, Linux, and macOS. Ports to any other platform supported by AMPL can be easily obtained.

For Windows only, please make sure that the Microsoft Visual C++ Redistributable Package is installed. It often comes preinstalled or as part of other software; it can also be downloaded from Microsoft download center. Click here to download.

About this manual

This document intends to guide a developer in the process of implementing an “AMPL API based” application in Python. The section Class structure presents the main logic of the API, which does not change depending on which programming environment is chosen. Further sections walk the reader through the implementation of the most common applications, finally the sections Python API Reference and Python API Examples contain respectively the API reference documentation and a collection of examples.