nonlinear programming problem
AnsweredI am modeling a nonlinear programming problem where the price is a nonlinear function of probabilities. How should I use Gurobi to handle this?
model_de = Model("model_de")
probabilities = model_de.addVars(n, lb=0, ub=1, vtype=GRB.CONTINUOUS, name="probabilities")
r = model_de.addVars(n, lb=0, vtype=GRB.CONTINUOUS, name="r")
# r = alpha/beta  1/beta * (np.log(probabilities) / np.log(1  np.sum(probabilities)))
model_de.setObjective(quicksum((r[j] * probabilities[j]) for j in range(n)), GRB.MAXIMIZE)
for i in range(m):
model_de.addConstr(c[i] >= quicksum(a[i][j] * probabilities[j] for j in range(n)))
model_de.addConstr(quicksum(probabilities[j] for j in range(n)) < 1)
model_de.optimize()

You can model a division as described in How do I divide by a variable in Gurobi?
The log term can be introduced by the addGenConstrLog method.
Please note that the addGenConstrLog method takes only exactly one optimization variable as argument variable. This means that you will have to introduce a couple of auxiliary variables. In the end, you will have to model something like
\[\begin{align*}
z_1 &= \text{probabilities}\\
z_2 &= 1  z_1\\
z_3 &= \log(z_1) \quad \leftarrow \log(\text{probabilities})\\
z_4 &= \log(z_2) \quad \leftarrow \log(1  \text{probabilities})\\
z_3 &= z_4 \cdot z_5 \quad \leftarrow z_5 = \frac{z_3}{z_4}
\end{align*}\]It is important to make sure that variables \(z_3\) and \(z_4\) are \(>0\) to avoid \(\log(0)\). This means that you have to set the lower bounds for the auxiliary variables manually to something \(>0\) and this implies that your probabilities variables cannot attain values \(1\) and \(0\). You could account for this directly when defining these variables. You could set the bounds to something like
probabilities = model_de.addVars(n, lb=1e4, ub=11e4, vtype=GRB.CONTINUOUS, name="probabilities")
If you are using Gurobi version 11, then you can set the FuncNonlinear parameter to 1 to tell Gurobi to handle the \(log\) function via dynamic piecewiselinear approximation, i.e., as a nonlinear function. Please refer to the documentation of General Constraints for more details.
Best regards,
Jaromił1 
thx!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!ursoooonice
0
Please sign in to leave a comment.
Comments
2 comments