extern "C" double AMPL_solve(char *instance, char *temp, double obval) {
double retval;
try{
ampl::AMPL ampl;
ampl.setOption("solver", "baron");
ampl.setOption("baron_options","optfile BaronOpt.txt outlev 1");
ampl.setOption("omit_zero_rows","1");
// Read the model and data files.
std::string modelDirectory = "./PONDP";
std::string dataDirectory = "./PONDP/NetDesign/";
ampl.read(modelDirectory + "/PO_UNDP.mod");
ampl.readData(dataDirectory + instance);
ampl.readData(dataDirectory + "GE");
//Adjusting the value of the gravit_exp
// Solve
ampl.solve();
I ASSUME I WOULD QUERY FOR SOLVE_RESULT_NUM HERE.
// Get objective entity by AMPL name
ampl::Objective profit = ampl.getObjective("Profit");
// Print it
std::cout << instance << " objective function is: " << profit.value() << std::endl;
// Get the values of the variable in a dataframe object
ampl::Variable x = ampl.getVariable("x");
ampl::DataFrame df = x.getValues();
retval=profit.value()-obval;
// Print them
ofstream myfile;
myfile.open (temp);
myfile << df.toString();
myfile.close();
std::cout << df.toString() << std::endl;
return retval;
}
catch (const std::exception &e)
{
std::cout << e.what() << "\n";
return -1;
}
}
******
Thank you in advance for your time.
Regards
Carlos