constraint for inequality
I have an inequality constraint like that: a >= b + c - d*(1-x) with a,b,c,d is constant numbers, x is binary variable. How can I write it into a Constraint() class using from_func() method?
dwavebinarycsp.Constraint.from_func(myfunc_, [a,b,c,d,x], dwavebinarycsp.BINARY, "inequality")
However, a, b, c, d is constant numbers, not variables. So I tried:
dwavebinarycsp.Constraint.from_func(myfunc_(a,b,c,d), [x], dwavebinarycsp.BINARY, "inequality")
But the second version cannot put x into myfunc_ function.
Does anyone know how to handle this situation?
Comments
Hi Le Hoa,
What does your myfunc_ look like?
My approach would be to reframe your constraint as
In this form it's a bit easier to see that if z >= 1 the constraint will always be satisfied (since the maximum value of x is 1). So you could do this:
I think it's worth mentioning that there's a more performant way of defining this constraint as well. When the constraint is always satisfied we don't actually need the constraint at all. So you could evaluate z while you're constructing your BQM. If z >= 1 you can fix the variable to true using fix_variable().
Let me know if this helps and if you have any more questions!
Please sign in to leave a comment.