Model becomes infeasible after adding a set of polynomial constraints
AnsweredHello together,
I am trying to solve a problem with general constraints.
The model works when polynomial constraints are not added. But after those constraints are added, the model became infeasible. Mid_4 is just a normal variable without more constraints, I don't understand why it would cause infeasible.
Thanks for your help.
Connection = model_2.addVars(self.UserNum, self.StationNum, self.pt_num, vtype=GRB.BINARY, name='Connection')
Distance = model_2.addVars(self.UserNum, self.StationNum, self.pt_num, name='Distance')
Distance_max = model_2.addVars(self.StationNum, self.pt_num, name='Distance_max')
BSUserNum = model_2.addVars(self.StationNum, self.pt_num, name='BSUserNum')
Mid_4 = model_2.addVars(self.StationNum, self.pt_num, ub=GRB.INFINITY, name='Mid_4')
model_2.addConstrs(Connection.sum(i, '*', k) == self.UserConnect[i, k] for i in range(self.UserNum) for k in range(self.pt_num))
model_2.addConstrs(Distance[i, j, k] == Connection[i, j, k] * math.sqrt((self.MUs.Users[i].xx - self.BSs.BaseStations[j].xx) ** 2 + (self.MUs.Users[i].yy - self.BSs.BaseStations[j].yy) ** 2)
for i in range(self.UserNum) for j in range(self.StationNum) for k in range(self.pt_num))
model_2.addConstrs(Distance[i, j, k] <= self.MaxDistance for i in range(self.UserNum) for j in range(self.StationNum) for k in range(self.pt_num))
model_2.addConstrs(Distance_max[j, k] == gp.max_(Distance[i, j, k] for i in range(self.UserNum)) for j in range(self.StationNum) for k in range(self.pt_num))
model_2.addConstrs(BSUserNum[j, k] == Connection.sum('*', j, k) for j in range(self.StationNum) for k in range(self.pt_num))
for j in range(self.StationNum):
for k in range(self.pt_num):
model_2.addGenConstrPoly(Distance_max[j, k], Mid_4[j, k], [0, 0, 1, 0, 0])
obj = gp.LinExpr(0)
for k in range(self.pt_num):
for j in range(self.StationNum):
#obj += Power[j, k]
obj += Distance_max[j, k]
model_2.setObjective(obj, GRB.MINIMIZE)
model_2.setParam('MIPGap', 1e-2)
model_2.write('version_6_2.lp')
model_2.optimize()
-
Hi Tianqing,
I agree this is a little strange, and perhaps is a result of numerical issues in your model. Perhaps start with this KB article "How do I determine why my model is infeasible" and generate an IIS to provide further insight. Without a reproducible example there is not much we can do.
Note that if you want the constraint
Mid_4[j, k] == Distance_max[j, k] * Distance_max[j, k]
then you can add this to the model directly without resorting to using the addGenConstrPoly method.
- Riley
0 -
The article Riley noted is a great place to determine why your model is infeasible.
I just wanted to add an example to build on what you will learn in that article: workforce1.py. If you want to take a look through an example of an infeasibility diagnosis, I recommend checking out this example which shows how to use the Model.computeIIS() method. This can help you narrow down your list of suspicious constraints. This is a great place to start understanding which constraints may be problematic.
If you want to take the next step, you can determine how much these constraints need to be relaxed to restore feasibility. The best way to do this is by using our feasibility relaxation tool to see how much the constraints need to be relaxed. You can do this with the Model.feasRelax() and Model.feasRelaxS() methods -- though this is not shown in the example.0
Please sign in to leave a comment.
Comments
2 comments