Does Column::addTerm() assumes constraints in normal/standard form?
回答済みI am solving a linear programme with column generation (sung the C++ API and Gurobi 10.0). My programme has a polynomial number of variables \(x_i, \; i \in I\) and an exponential number of variables \(y_j, \; j \in J\). I do column generation on variables \(y\) and I initially have none of them.
To build the model, I first create variables \(x\) and then all constraints. Because I do not yet have variables \(y\), I put a 0 where they shall later appear. For example, if I have a constraint \(\sum_i x_i \leq \sum_j y_j\), I add it with
GRBLinExpr lhs;
for(auto i : I) { lhs += x[i]; }
GRBConstr c = model.addConstr(lhs, GRB_LESS_EQUAL, 0);
I now want to add a variable \(y_0\). To this end, I should first create a \(\texttt{Column}\) object and call \(\texttt{addTerm}\) to set the coefficient of my new variable \(y_0\) in constraint \(\texttt{c}\). However, I cannot find in the documentation (of neither \(\texttt{addTerm}\), \(\texttt{addTerms}\), nor \(\texttt{addVar}\)) any hint on where this coefficient will go. I assume that it will go to the LHS and that the sign of the constraint is the same sign as when I created it. Is it so?
In this case, if my constraint should now look like \(\sum_i x_i \leq y_0\) I shall use a coefficient of -1 in \(\texttt{addTerm}\). Is this correct?
Thanks in advance,
Alberto
-
正式なコメント
This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi Alberto,
You are correct. You can verify this by adding the following code
for (int i = 0; i < model.getCol(x).size(); i++) {
cout << "Coeff term:" << i << ": " << model.getCol(x).getCoeff(i) << endl;
}to our simple mip1 c++ example, and playing with it to see that the coefficients of the terms in the Column object are invariant to the constraint sense or whether x is added to the LHS or RHS.
- Riley
0
投稿コメントは受け付けていません。
コメント
2件のコメント