I am trying to use CPLEX module via python for the scheduling case. However there is an error as follows.
model = Model(name='scheduling')
# --- decision variables ---
numbers = range(1, math.factorial(6))
K = [number for number in range(1, math.factorial(6)+1)] #720
model.x_i = model.continuous_var_dict(keys=K) #keys untuk siapin tempat x dari 1 sampai
720
model.x_j = model.continuous_var_dict(keys=K)
#mdl.s = mdl.continuous_var_dict(keys=K).sort() #check sort di cplex
for k in K:
mdl.x_i[k] = mdl.continuous_var_dict(TRANSITIONS)
mdl.x_i[k] = mdl.x_i[k] #K
if k < max(K)-1: # bukan angka 5, tetapi maksimal nilai K yang terakhir
mdl.x_j[k] = mdl.x_i[k+1] #K+1
print('k[1]',mdl.x_i[1],mdl.x_j[1])
print('k[2]',mdl.x_i[2],mdl.x_j[2])
print('k[3]',mdl.x_i[3], mdl.x_j[3]) #check X
mdl.obj_lambda = mdl.continuous_var_dict(keys=K) #define the lambda before
proceeding into the constraint
mdl.add_constraint(mdl.x_j[k] - mdl.x_i[k] >= p(1) - p(2)*mdl.obj_lambda) for p in
PLACES #p(1) for holding time (h), m0 from p(2) #ERROR invalid syntax
mdl.add_constraint(m[k] == mdl.sum(m[k-1] + AT*MZ[k]) for k in T) #Error object is not iterable
mdl.add_constraint(mdl.sum(MZ[i]) == 1 for i in T) #Error int object is not iterable
mdl.add_constraint(mdl.sum(MZ[k]) == 1) #define iteration k #list index out of range
mdl.add_constraint(mdl.sum(MZ[k]) == 1) #list index out of range
File "<ipython-input-14-a8eac2458627>", line 22
mdl.add_constraint(mdl.x_j[k] - mdl.x_i[k] >= p(1) - p(2)*mdl.obj_lambda) for p in PLACES #p(1) for holding time (h), m0 from p(2) #ERROR
^
SyntaxError: invalid syntax
Could anyone have any reference on how to write the code for CPLEX, especially the constraint, please?
Thank you.