I am solving an LP by using GUROBI - C++ combo.
Assume I have a variable $p \in \mathbb{R}^n$. I am adding this as a vector:
GRBEnv* env;
GRBModel* model;
vector<GRBVar> p;
Now I have $a\in\mathbb{R}^n$ parameters, and I want to add a constraint $a^\top p\ \leq 0$, so I say:
GRBLinExpr sum_expo = 0;
for (int i = 0; i < p.size(); i++) {// add all the coeffs given
sum_expo += a[i] * p[i];
}
model->addConstr(sum_expo <= 0);
Obviously, this is too inefficient. Is there a way that I can:
- Define the whole $p$ vector as a multivariate GRBVar, rather than having a vector with all GRBVar values
- Add a constraint $a^\top p \leq 0$ in a single line.