#include #include "gurobi_c++.h" using namespace std; int main() { //8. Exception Handling try { //1.1 Basic elements declaration GRBEnv env = GRBEnv(); GRBModel model= GRBModel(env); //1.2 Parameters definition const int N = 2; //number of resources const int M = 2; //number of products (D.V.) int a[N][M]= {{1, 2}, {4, 3}}; //coefficients in the constraints int b[N] = {40, 120}; //coefficients of the RHS (Right-Hand-Side) int c[M] = {40, 50}; //coefficients of objective function //2. Decision Variables GRBVar x1, x2; x1= model.addVar(0.0, GRB_INFINITY, 0.0, GRB_CONTINUOUS); x2 = model.addVar(0.0, GRB_INFINITY, 0.0, GRB_CONTINUOUS); //3. Integrate variables into model model.update(); //4. Constraint Declaration model.addConstr(1*x1 + 2*x2 <= 40); model.addConstr(4*x1 + 3*x2 <= 120); //5. set the model to maximization model.set(GRB_IntAttr_ModelSense, -1); model.setObjective(40*x1+50*x2); //6. Optimize the model model.optimize(); //7.1 Check Optimality int status = model.get(GRB_IntAttr_Status); if (status == GRB_OPTIMAL) { //7.2 Output the objective value and solutions double ObjValue = model.get(GRB_DoubleAttr_ObjVal); cout<<"total cost= "<