Confusion regarding the sum of log functions as the objective function
AnsweredI’m trying to solve the following problem, where only epsilon is unknown.
I attempted to model the problem as a function with the given information:
def howtosolve(dim, varA, varB, varC, varLam, centerB, epsDomain):
vectorB = np.array(varB)
vectorBNormL1 = np.linalg.norm(vectorB, 1).item()
vectorA = np.array(varA)
solverE = grb.Model()
eps = [solverE.addVar(name=f"eps_{i}", lb=0.1, ub=epsDomain[i]) for i in range(dim)]
solverE.update()
temp = [solverE.addVar(name=f"temp_{i}")for i in range(dim)]
solverE.update()
for i in range(dim):
solverE.addGenConstrLog(eps[i], temp[i])
solverE.update()
solverE.addConstr(sum(vectorA[i] * eps[i] for i in range(dim)) + vectorBNormL1 + centerB + varC + varLam <= 0.)
solverE.update()
solverE.setParam('OutputFlag', 0)
solverE.setParam('PreSolve', 2)
solverE.setParam('DualReductions', 0)
solverE.setObjective(grb.quicksum(temp[i] for i in range(dim)), grb.GRB.MAXIMIZE)
solverE.optimize()
if solverE.status == grb.GRB.OPTIMAL:
print("Optimal solution:")
print("eps values:")
for i in range(dim):
print(eps[i].X)
elif solverE.status == grb.GRB.Status.INFEASIBLE:
print("Infeasible")
solverE.computeIIS()
solverE.write("model.ilp")
elif solverE.status == grb.GRB.Status.UNBOUNDED:
print("Unbounded")
else:
print("Solution end with state ", solverE.status)
but encountered an issue with infeasibility (from the "model.ilp"):
\ Model _copy
\ LP format - for model browsing. Use MPS format to capture full model detail.
Maximize
0 eps_2 + 0 temp_2
Subject To
Bounds
-infinity <= eps_2 <= 0.418
General Constraints
GC2: temp_2 = LOG ( eps_2 )
End
-
Hi Zengyu,
First, note that variables in Gurobi have a default lower bound of 0 unless specified otherwise. This is a common source of unexpected infeasibility.
The upper bound of eps_2 is 0.418 and log(x) for x <= 0.418 is negative. Since your temp_2 variable has a lower bound of 0 you have an infeasible model.
A couple of more things to note:
* An ILP file is only supposed to contain information that contributes to the infeasibility. The model is infeasible no matter what the value of the eps_2 lower bound, and so the bound is ignored which is why you see "-infinity <= eps_2"
* The objective does not matter when a model is infeasible, so you should not expect to see your original objective in the ILP file
* When writing out LP files, Gurobi will include any variable that does not appear in any linear constraint in the objective with a 0 coefficient, if it is not part of the objective already. For reasons behind this please refer to this post. You can just ignore these variables.
- Riley
0 -
Hi Riley,
Thank you so much for your detailed explanation!
Have a nice day!0
Please sign in to leave a comment.
Comments
2 comments