Knowing the value of some of variables (when we solve a model from a file)

46 views
Skip to first unread message

s. sadeghi

unread,
Sep 21, 2017, 1:50:14 PM9/21/17
to Gurobi Optimization
 
 I load and solve a model from a file, for example my model is as follow:
 
Maximize
  x + y + 2 z
Subject To
 c0: x + 2 y + 3 z <= 4
 c1: x + y >= 1
Bounds
Binaries
 x y z
End

 I solve this model as a file according to following source code:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include <fstream>
#include "gurobi_c++.h"
using namespace std;

int main()

 ifstream infile;
infile.open("my model.lp");
  try {

    GRBEnv env = GRBEnv();
    GRBModel model = GRBModel(env,"my model.lp");

    model.optimize();

    int optimstatus = model.get(GRB_IntAttr_Status);

    if (optimstatus == GRB_OPTIMAL) {
      double objval = model.get(GRB_DoubleAttr_ObjVal);
      cout << "Optimal objective: " << objval << endl;
    } else if (optimstatus == GRB_INFEASIBLE) {
      cout << "Model is infeasible" << endl;

   
    } else if (optimstatus == GRB_UNBOUNDED) {
      cout << "Model is unbounded" << endl;
    } else {
      cout << "Optimization was stopped with status = "
           << optimstatus << endl;
    }

  } catch(GRBException e) {
    cout << "Error code = " << e.getErrorCode() << endl;
    cout << e.getMessage() << endl;
  } catch (...) {
    cout << "Error during optimization" << endl;
  }
  return 0;
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 This source code just give me the value of objective function, but I want to know the value of some of variables (for example the value of y in my model). What command should I add to my source code?
 

Renan Garcia

unread,
Sep 21, 2017, 1:58:54 PM9/21/17
to gur...@googlegroups.com
--

---
You received this message because you are subscribed to the Google Groups "Gurobi Optimization" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gurobi+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

s. sadeghi

unread,
Sep 21, 2017, 5:18:12 PM9/21/17
to Gurobi Optimization

Thank you for your explanation.
Reply all
Reply to author
Forward
0 new messages