Reputation: 1
I'm attempting to create a set of constraints about the simple VRP problem.
I've tried add_constraint but I'm getting an invalid syntax error
How can solve the problem?? Now I use add_constraint, and My error and code is something like below.
from docplex.mp.model import Model
md1 = Model('VRPPD')
K=[0,1,2]
D=[1,2,3,4,5,6]
D_PLUS=[0,1,2,3,4,5,6]
ccost=[2000,2000,2000]
cmax=[2,2,2]
#define decision variables
c1 = md1.integer_var_dict([(k,i) for k in K for i in D_PLUS], name='c1')
c2 = md1.integer_var_dict([(k,i) for k in K for i in D_PLUS], name='c2')
x = md1.binary_var_dict([(k,i,j) for k in K for i in D_PLUS for j in D_PLUS], name='x')
y = md1.binary_var_dict([(k) for k in K], name='y')
#define objective functions
md1.maximize(md1.sum(y[k]*ccost[k] for k in K))
#********************************** constraint 1 entire job should be served***********************************
md1.add_constraint(md1.sum(x[k,i,j] for k in K for i in D_PLUS for j in D) == 20, 'st1')
#********************************** constraint 2 allocate vehicle***********************************
mdl.add_constraint(md1.sum(x[k,i,j] for i in D_PLUS for j in D_PLUS) <= 1000*y[k] for k in K, 'st2')
#solve and print outputs
md1.solve_details
solution = md1.solve(log_output=True)
print(solution)
Upvotes: 0
Views: 406
Reputation: 10062
If you rewrite st2 into
for k in K:
md1.add_constraint((md1.sum(x[k,i,j] for i in D_PLUS for j in D_PLUS) <= 1000*y[k]), 'st2'+str(k))
your model works.
Upvotes: 1