#include <iostream>
#include "ampl/ampl.h"
int main(int argc, char **argv) {
try {
ampl::AMPL ampl;
if (argc > 1) ampl.setOption("solver", argv[1]);
std::string modelDirectory = argc == 3 ? argv[2] : "../../models";
ampl.read(modelDirectory + "/diet/diet.mod");
ampl.readData(modelDirectory + "/diet/diet.dat");
ampl.solve();
ampl::Objective totalcost = ampl.getObjective("Total_Cost");
std::cout << "Objective is: " << totalcost.value() << std::endl;
ampl::Parameter cost = ampl.getParameter("cost");
ampl::Tuple indices[] = {ampl::Tuple("BEEF"), ampl::Tuple("HAM")};
double values[] = {5.01, 4.55};
cost.setValues(indices, values, 2);
std::cout << "Increased costs of beef and ham." << std::endl;
ampl.solve();
std::cout << "New objective value: " << totalcost.value() << std::endl;
double elements[8] = {3, 5, 5, 6, 1, 2, 5.01, 4.55};
cost.setValues(elements, 8);
std::cout << "Updated all costs." << std::endl;
ampl.solve();
std::cout << "New objective value: " << totalcost.value() << std::endl;
ampl::Variable buy = ampl.getVariable("Buy");
ampl::DataFrame df = buy.getValues();
std::cout << df.toString() << std::endl;
ampl::DataFrame df2 = ampl.getData("{j in FOOD} 100*Buy[j]/Buy[j].ub");
std::cout << df2.toString() << std::endl;
return 0;
} catch (const std::exception &e) {
std::cout << e.what() << "\n";
return 1;
}
}