AMPL > >General > >Can my program call AMPL as a subroutine?

Currently AMPL is not configured as a subroutine library whose individual pieces can be called as needed from a user’s program. A “batch” session of AMPL can be executed from a program in any popular programming language, however. This feature can be used as a high-level “call” to AMPL that is sufficient for some applications.

In a C program, you would execute AMPL by use of the system procedure, as in these examples:

system("ampl <");
system("ampl < >cut.out");

The argument to system can be anything one would type on a command line. Most commonly, an input file ( above) contains a series of AMPL commands that read model and data input, invoke solvers, and write results to files. This arrangement does not provide for results to be passed back directly to your program; following the call to system, your program must get the results by reading a file that AMPL has written. Other languages (such as C++, C#, Java, Python) have their own calling conventions, but the principles are the same.

Posted in: General