Constraint involves log
AnsweredI want to use Gurobi solve a problem with log constraint
The origin CVXPY code is:
w = cp.Variable((n, 1))
Z = cp.Variable((n, N))
for j in range(N):
column_Zj=cp.reshape(Z[:, j], (-1, 1))
log_expression=-cp.log(1+ (w.T @ R_stack)) +column_Zj.T @ R_stack
constraints.append(log_expression <=-s[:,j])
And I tried to turn into Gurobi code:
w = model.addMVar((n, 1), name="w")
w_t = w.transpose()
Z = model.addMVar((n, N), name="Z")
for j in range(N):
column_Zj=Z[:, j]
column_Zj_t=column_Zj.transpose()
x=model.addVar(name="x", lb=-1)
y=model.addVar(name="y", lb=-1000)
model.addConstr(x == 1+ (w_t @ R_stack), name="log inside")
model.addGenConstrLog(x, y, name="log")
log_expression=model.addVar(name="log_expression")
model.addConstr(log_expression == -y + column_Zj_t @ R_stack)
model.addConstr(log_expression<=-s[:, j], name=f"log_expr")
model.Params.FuncNonlinear=1
model.setParam('MIPGap', 0)
But when using Gurobi to solve, I got the solution :
Model is infeasible or unbounded Best objective -, best bound -, gap -I think the two code above is the same, it seems that the Gurobi code is wrong
I can't find the error
0
-
Official comment
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 Xiao,
By default Gurobi variables have a default lower bound of 0.
Could this cause the issue here?
- Riley
0 -
Hi Riley,
Thanks for answering.
I tried to set the variables who may be negative to a negative lower bound,
but still encountered an infeasible model.
Therefore, I suspect there may be an error in the code for the log term,
but I cannot find the error.
0 -
Hi Xiao,
I would suggest the following article will help
How do I determine why my model in infeasible?- Riley
0
Post is closed for comments.
Comments
4 comments