Non-Zero test for summation of variables
回答済みHi all,
I have a list of variable and I want to add a constraint to limit the number of non-zero variables. How should I do this?
I try to compare it to something like IntFeasTol but I think two-sided comparison is not supported. I also tried to use np.count_nonzero() but it's still not working.
Thanks in advance!
-
正式なコメント
This post is more than three 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 why not try our AI Gurobot?. -
What are the bounds on these variables? Are they continuous, integer or binary?
0 -
Thanks for your prompt reply! They are GRB.INTEGER and I set the lower bound to zero.
0 -
In order to count the number of non-zeros, you would typically introduce binary variables that indicate whether a given variable is 0 or not. So, if you have integer variables x1,...,xn, then you would introduce binary variables z1,...,zn and add an indicator constraint
zi = 0 -> xi = 0
for each i = 1,...,n that says that if the binary variable is zero, then the integer variable must be zero as well. Then, if you want to restrict the number of non-zero xi variables to, say, k, you would add the constraint
z1 + ... + zn <= k.
Regards,Tobias
0 -
It worked! Thanks so much!
0
投稿コメントは受け付けていません。
コメント
5件のコメント