-2

Since I wrote this syntax as a variable in the spyde IDE/python and the error is

invalid syntax

this is my code:

from gurobipy import*
try:
m = Model('operating_room')
#Data
b= [1,2,3]
n= [1,2,3,4,5,6,7,8,9,10]
j= [1,2,3,4,5,6,7,8,9,10,11,12,13]
t=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
W=0.5
m.update()
#create variables
X[j] =m.addVar(vtype=GRB.BINARY, name="X[j]")
Y[n] =m.addVar(vtype=GRB.BINARY, name="Y[n]")
x[b,j,t] = m.addVar(vtype=GRB.BINARY,name="x[b,j,t]") 
y[n,b] = m.addVar(vtype=GRB.BINARY,name="y[n,b]")
m.update()
#set objective
m.setObjective(quicksum(X[j] for j in J )+ W*(quicksum(Y[n] for n in 
N)),GRB.MINIMIZE)  #eqution 1

**for b in range(1,b):  
    #create constraints
    m.addConstr(quicksum(x[b,j,t]=1 for j in J for t in range(rb:(d[b]-
    p[b]+1))),name="block_allocation")    #eqution 2**

i need to know what's the problem in

    m.addConstr(quicksum(x[b,j,t]=1 for j in J for t in range(rb:(d[b]-
                                     ^
    p[b]+1))),name="block_allocation")    #eqution 2 

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

2

x[b,j,t]=1 is a statement, not an expression. generator expressions cannot include statements.

If you really want to use a list comprehension instead of an ordinary for loop (which would probably be much clearer), you can import operator and use operator.setitem(x, (b,j,t), 1).

cco
  • 5,873
  • 1
  • 16
  • 21
  • thank you very much for your fast reply but please could you explain me how can i edit it since this statement is a constraint in my model – Dina Sheweita Apr 24 '17 at 17:53