You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from dimod import ConstrainedQuadraticModel, Binary, quicksum
cqm_test = ConstrainedQuadraticModel()
vars = [Binary(f"X{i}") for i in range(7)]
def add_constraint(cqm, vars, indices, biases, sense, rhs):
if len(indices) != len(biases):
raise ValueError('The indices and biases do not have same size.')
constraint = quicksum(biases[i] * vars[indices[i]] for i in range(len(indices)))
cqm.add_constraint(constraint, sense=sense, rhs=rhs, label='c')
add_constraint(cqm_test, vars, [0, 2, 5], [1, 2, 3], "==", 5)
print(cqm_test.constraints['c'].to_polystring())
>> X0 + 2*X2 + 3*X5 == 5.0
Requested by @mhramani #1307 (review).
Something like
which would be interpreted as a linear constraint$x_0 + 2x_1 + 3x_5 = 5$ .
The text was updated successfully, but these errors were encountered: