Skip to content
Stefan Vigerske edited this page Mar 5, 2019 · 1 revision

The OS library contains a class OSnl2osil that is used to convert AMPL nl model instance files into the OSiL XML format. The class constructor for takes a string which is the name of a file in AMPL nl format. The OSnl2osil class has a method, createOSInstance() that creates an in-memory model instance in OSiL format. This class can be used two ways.

Method 1 -- Outside of AMPL

The OSnl2osil class can be used as part of an executable to read an nl file, convert to OSiL, and then solve. Here is an example assuming the solver is Ipopt.

OSnl2osil *nl2osil = NULL;

cout << "create an Ipopt Solver for AMPL nl - OSInstance solution" << endl;
SmartPtr<IpoptSolver> ipoptSolver  = new IpoptSolver();	

nl2osil = new OSnl2osil( nlFileName);
nl2osil->createOSInstance() ;
ipoptSolver->osinstance = nl2osil->osinstance;	
cout << "call Ipopt Solver" << endl;  
ipoptSolver->solve();
cout << "Here is the Ipopt solver solution" << endl;
cout << ipoptSolver->osrl << endl;

Method 2 -- Inside of AMPL

The OSnl2osil class can be used to create an AMPL solver. In the examples folder we illustrate this with the executable amplClient. Here is an example of AMPL using amplClient which talks to a LINDO sovler that is hosted locally.

ampl
model hs71.mod;
option solver amplClient;
option amplClient_options "solver lindo";
write gtestfile;
solve;

Of course, you can also call a solver remotely. Here is an example where the remote solver is Ipopt.

model hs71.mod;
option solver amplClient;
option amplClient_options "solver ipopt";
option ipopt_options "http://***.***.***.***:8080/lindo/IPOPTSolverService.jws";
write gtestfile;
solve;