# 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

1 comment
• Hi Le Hoa,

What does your  myfunc_ look like?

My approach would be to reframe your constraint as

`# Collect the non-variable termsz = (a - b - c)/d + 1# Reframe the constraintz  >= x`

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:

`# Function to evaluate z >= x (where z = (a - b - c)/d + 1)def myfunc_(z):    if z < 1:        return lambda x: x == 0    else:        return lambda x: Trueconst = dwavebinarycsp.Constraint.from_func(myfunc_(z), ['x'], dwavebinarycsp.BINARY, name='myfunc_{}'.format(z))`

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.