C API Examples#

This section lists a few examples in C. These are the same files that can be found in the examples directory of the distribution, and show the basic usage of the C API.

Example 1: First steps#

firstexample_c.c

This example shows how to

  • read an AMPL model

  • reassign values to parameters

  • solve the model

  • display the objective function value

Example 2: Get and set AMPL options#

optionsexample_c.c

This example shows how to:

  • get and set AMPL options

Example 3: Get and set data through DataFrames#

dataframeexample_c.c

This example shows how to:

  • Use AMPL_DATAFRAME struct to assign values to sets and parameters

  • Use an AMPL_DATAFRAME struct to fetch and decouple values from a variable

Example 4: Operate with multidimensional data#

multidimensionalexample_c.cc

This example shows how to:

  • Use a AMPL_DATAFRAME to assign values to multidimensional parameters

Example 5: Assign all data to a model and solve it#

dietmodel_c.c

This example shows how to:

  • Assign all the data necessary to generate a model instance programmatically

Example 6: Build an efficient frontier#

efficientfrontier_c.c

This example shows how to:

  • build an efficient frontier by repeteatly solve a portfolio problem in AMPL

Example 7: Simple heuristic#

trackingmodel_c.c

This example shows how to:

  • Do a simple heuristics for solving a QMIP problem, using the relaxed solution as a hint