API for AMPL
$ dotnet add package AMPL.ApiAMPL API is an interface 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 or in conjuction to the normal AMPL data reading procedures.
using (ampl.AMPL a = new ampl.AMPL()) {
a.Eval("var x<=3; maximize z:x;")
a.Solve();
var z=a.GetObjective("z");
Console.WriteLine($"Objective is: {z.Value})
}
using (var ampl = new AMPL())
{
ampl.Eval("var x{1..3};");
ampl.Eval("maximize z: sum{i in 1..3} x[i];");
// Redirect output using lambda expression
ampl.EnableOutputRouting();
ampl.Output += (kind, message) => Console.Write("Got AMPL message:\n{0}\n", message);
ampl.Eval("display x,z;");
}