Infeasibility Relaxation with Gurobi
回答済みI have an infeasible model. I am attempting to perform Infeasibility Relaxation with model.feasRelax.
While doing that, I am trying to keep a certain number of constraints outside of the analysis i.e. they can't be relaxed.
Below is my pseudocode:
# constraint filtering conditionWhile, trying to do this, I get the following error:
constraints_ls = [i for i in self.gurobi_model.getConstrs() if 'xyz_upper_bound' not in i.constrname if 'xyz_lower_bound' not in i.constrname]
# feasibility relaxation
self.gurobi_model.feasRelax(
relaxobjtype=0, minrelax=False, vars=False, lbpen=None, ubpen=None,
constrs=constraints_ls, rhspen=None)
)
TypeError: object of type 'bool' has no len()
I am not sure what is causing it. Could someone help me with it?
What more information would you need to help me?
Thanks
-
正式なコメント
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 Nitin,
Note that in the documentation you linked it states the following for the vars parameter:
vars: Variables whose bounds are allowed to be violated.The function is expecting a collection of variables, such as a list, which is why vars=False is causing an error.
- Riley
0 -
But what if I don't want the relaxation to play with the variable bounds, but only the RHS of the constraints?
0 -
Passing an empty list as an argument is acceptable.
- Riley
1 -
I just did that. Thanks.
My bad that I thought it was a boolean.0 -
Riley Clement
I have a follow up question on this. For the same infeasible model (now I am not filtering down any constraint for this relaxation exercise):
If I try model.feasRelax as follows:self.gurobi_model.feasRelax(
relaxobjtype=0, minrelax=False, vars=[], lbpen=None, ubpen=None,
constrs=self.gurobi_model.getConstrs(), rhspen=None
)The model still remains infeasible, however if I use the model.feasRelaxS as:
self.gurobi_model.feasRelaxS(
relaxobjtype=0, minrelax=False, vrelax=False, crelax=True
), I am able to arrive at a possible feasibility relaxation.
What is likely to cause this difference in the behavior?Thanks
0 -
Hi Nitin,
The rhspen parameter needs values if you are providing constraints to be relaxed.
rhspen: Penalty for violating a linear constraint. One entry for each constraint in argument constrs.
If you use
rhspen=[1]*len(m.getConstrs())
then you will get equivalent results to feasRelaxS.
- Riley
0
投稿コメントは受け付けていません。
コメント
7件のコメント