converst string (constraint) into GRBLinExpr (C++)
I would like to know if there is a way to convert a string into GRBLinExpr?
in order to use: model.addConstr(string)
or another way to add a constraint of string type to model file using gurobi c++ library.
-
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?. -
I'm not sure I understand your question well. Can you provide an example of a string that you want to convert into a linear expression?
0 -
Thank you for your reply, I have an old work with lp_solve, and I want to use gurobi API C++ : all my constraints written as string to a file, so I am looking for putting my string constraints equations to the model.
I try to do somthing like that (put a string to constraint) :
sprintf(Constraint1, "x%d + %d r%d - %d r%d - x%d - %d p%d%d - %d q%d%d <= - %d\n", i, hi, i, wi, i, j, M, i, j, M, i, j, wi);
model.addConstr(Constraint1);
My Old code :
------------------------------------------------
for (int i = 1; i <= block_list->size(); i++) {
for (int j = i + 1; j <= block_list->size(); j++) {
hi = block_list->at(i - 1)->height;
hj = block_list->at(j - 1)->height;
wi = block_list->at(i - 1)->width;
wj = block_list->at(j - 1)->width;
fprintf(f, "c%d: x%d + %d r%d - %d r%d - x%d - %d p%d%d - %d q%d%d <= - %d\n", eq++, i, hi, i, wi, i, j, M, i, j, M, i, j, wi);
fprintf(f, "c%d: y%d + %d r%d - %d r%d - y%d - %d p%d%d + %d q%d%d <= + %d\n", eq++, i, wi, i, hi, i, j, M, i, j, M, i, j, M-hi);
fprintf(f, "c%d: x%d - %d r%d + %d r%d - x%d - %d p%d%d + %d q%d%d >= - %d\n ", eq++, i, hj, j, wj, j, j, M, i, j, M, i, j,M-wj);
fprintf(f, "c%d: y%d - %d r%d + %d r%d - y%d - %d p%d%d - %d q%d%d >= - %d\n", eq++, i, wj, j, hj, j, j, M, i, j, M, i, j,(2 * M)-hj);
//fprintf(f, "\n");
}
}0
Post is closed for comments.
Comments
3 comments