dwavesystems / dwavesystems/dimod

TypeError: '<' not supported between instances of 'BinaryQuadraticModel' and 'int'

Open
#1,211 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
143
Forks
91
Avg merge
1h 24m
Merged PRs (30d)
3

Description

Hi, I am trying to set an inequality constraint (I want the sum of some terms to be negative, less than 0 essentially), but get this error :

Traceback (most recent call last):
File "C:\Users\elmm\Desktop\CQM\CQM Assignment JRP\CQM_JRP.py", line 182, in
cqm.add_constraint(upper_bound_eq < 0,
TypeError: '<' not supported between instances of 'BinaryQuadraticModel' and 'int'

I don't think there is a need for a minimal reproducible example, as any cqm with a < sense which has binary vars will get this error but mine is :

for i in range(M):
for j in range(N):
X_.append(Binary('X_' + str(i + 1) + "_" + str(j + 1)))
if j == 0:
lower_bound_eq = quicksum(Y_[y] * list[0][y] * X_[j] - D[i] * k_i[i] * k_val[k] * T for k in range(38) for y in range(3))

cqm.add_constraint(lower_bound_eq <= 0,
label="Constraint lower-bound " + str(i + 1) + str(j + 1))
upper_bound_eq = quicksum(D[i] * k_i[i] * k_val[k] * T - (Y_[y + 1] * list[0][y + 1] * X_[j] + (1 - X_[j]) * Max_capacity) for k in range(38) for y in range(3))
cqm.add_constraint(upper_bound_eq < 0,
label="Constraint lower-bound " + str(i + 1) + str(j + 1))
elif j == 1:
lower_bound_eq = quicksum(Y_[y] * list[1][y] * X_[j] - D[i] * k_i[i] * k_val[k] * T for k in range(38) for y in range(3))
cqm.add_constraint(lower_bound_eq <= 0,
label="Constraint lower-bound " + str(i + 1) + str(j + 1))
upper_bound_eq = quicksum(D[i] * k_i[i] * k_val[k] * T - (Y_[y + 1] * list[0][y + 1] * X_[j] + (1 - X_[j]) * Max_capacity) for k in range(38) for y in range(3))
cqm.add_constraint(upper_bound_eq < 0,
label="Constraint lower-bound " + str(i + 1) + str(j + 1))
elif j == 2:
lower_bound_eq = quicksum(Y_[y] * list[2][y] * X_[j] - D[i] * k_i[i] * k_val[k] * T for k in range(38) for y in range(3))
cqm.add_constraint(lower_bound_eq <= 0,
label="Constraint lower-bound " + str(i + 1) + str(j + 1))
upper_bound_eq = quicksum(D[i] * k_i[i] * k_val[k] * T - (Y_[y + 1] * list[0][y + 1] * X_[j] + (1 - X_[j]) * Max_capacity) for k in range(38) for y in range(3))
cqm.add_constraint(upper_bound_eq < 0,
label="Constraint lower-bound " + str(i + 1) + str(j + 1))

X_.clear()

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.