Dear Nicholas,
- constraints 15 has no closing parenthesis
- to add multiple constrants use 'add_constraint
s
' and pass a python sequence, not a generator.
I hope this helps.
Cheers,
------------------------------
Renaud Dumeur
------------------------------
Original Message:
Sent: Fri August 05, 2022 02:41 AM
From: Nicholas Nicholas
Subject: Invalid Syntax for Constraint
Dear All,
When I created a constraint in pycharm with cplex library, there is an error as follows.
Could anyone tell me what should I do, please? Thank you in advance.
import cplex
from docplex.mp.model import Model
mdl = Model(name='Marking Optimization')
inf = cplex.infinity
bigM= 1000000
n = 2
p = [40,100]
c = [20,100]
v = 3
w = 5
m = [1,3]
y = mdl.integer_var(lb = 0, ub=inf, name='y')
#constraint 15
mdl.add_constraint(1 >= y*(n+1)*(2*v + 2*w)
#constraint 16
mdl.add_constraint(1 >= (y*1/m[i])*(p[i] + c[i] + 2*w) for i in range(n))
File "C:/Users/pknu/Documents/Research/project/Marking Optimization.py", line 25
mdl.add_constraint(1 >= (y*1/m[i])*(p[i] + c[i] + 2*w) for i in range(n))
^
SyntaxError: invalid syntax
Process finished with exit code 1
#DecisionOptimization