c++ Error code = 10003 Not right attribute
AnsweredI'm using gurobi in a C++ program on macOS (terminal mode). Whenever I use get(GRB_DoubleAttr_X), I always get "Error code =10003 Not right attribute". Going through output file created by model.write(), I verified that the LP is correctly formulated. The optimization step seems have gone through.The same program works on Windows (visual studio) but not here. The library I'm using is
".......-I /Library/gurobi950/macos_universal2/include/ -L /Library/gurobi950/macos_universal2/lib -lgurobi_c++ -lgurobi95 -lm"
Relevant code is as follows (I also inserted model.update() after model.optimize(), still does not work).
#include "gurobi_c++.h"
using namespace std;
GRBEnv env = GRBEnv(true);
env.start();
GRBModel model = GRBModel(env);
const int n_variable;
// set n_variable to a positive integer value
GRBVar p[n_variable];
for (int i = 0; i < n_variable; i++)
p[i] = model.addVar(0, GRB_INFINITY, 0.0, GRB_CONTINUOUS, "p" + to_string(i));
// add constraints, objective etc.
model.optimize();
try {
cout << p[0].get(GRB_DoubleAttr_X) << endl; // getting Error code 10003
// or double x= p[0].get(GRB_DoubleAttr_X); getting the same error code
}
catch (GRBException e){
cout << "Error code = "<< e.getErrorCode()<< endl;
cout << e.getMessage() << endl;
}
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
This error occurs if you use an outdated version of the \(\texttt{gurobi_c++.h}\) file. Is it possible that you recently updated to v9.5.0 but are still using the \(\texttt{gurobi_c++.h}\) file from v9.1.2?
I was able to reproduce the issue by running v9.5.0 and using the old \(\texttt{gurobi_c++.h}\) file from v9.1.2. Switchting to \(\texttt{gurobi_c++.h}\) file from v9.5.0 solves it.
Best regards,
Jaromił0
Post is closed for comments.
Comments
2 comments