Indicator constraint not working as expected
OngoingHi,
I have an array of variables that I want to count the number of non zero elements. I have tried using an indicator variable to achieve this. However, the indicator variable is not being applied and is always 0. Below is some sudo code to show what I am trying to achieve. Is this the best way to count non-zeros? If so any idea why this may not be working?
Thanks
qty = 100
x_vars = []
x_abs_qty_vars = []
for i in range(10)"
x = m.addVar(
vtype=GRB.BINARY,
name=f"x")
x_qty = m.addVar(
lb=min(0, qty), ub=max(0, qty),
vtype=GRB.CONTINUOUS,
name=f"x_qty")
x_abs_qty = m.addVar(
lb=0, ub=abs(qty),
vtype=GRB.CONTINUOUS,
name=f"x_abs_qty")
m.addGenConstrAbs(
allocated_abs_qty, allocated_qty,
name=f"x_abs_qty_constr")
m.addConstr((allocated == 1) >>
(allocated_abs_qty >= 1))
x_vars.append(x)
x_abs_qty_vars.append(x_abs_qty)
n_non_zero = gp.quicksum(x_vars)
0
-
Official comment
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?.
Post is closed for comments.
Comments
1 comment