Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while writing optimization constraint using cplex.mp.model module #56

Open
HengChheang opened this issue Aug 23, 2021 · 2 comments

Comments

@HengChheang
Copy link

My goal is to write the following constraint with the doxplex.mp.model with Python API: P[t,j] >= s[t-j+1] - sum(s[k=t-j+2] from k to t) for t = 1,....,N, j = 1,...,t

my code.

from docplex.mp.model import Model
clsp = Model(name = 'capacitated lot sizing problem')
no_of_period = 8
period_list = [t for t in range(1, no_of_period+1)]
s_indicator = clsp.binary_var_dict(period_list, name = 's_indicator')
p_indicator = clsp.binary_var_matrix(period_list, period_list, name = 'p_indicator')
m_8 = clsp.add_constraints(p_indicator[t,j] >= s_indicator[t-j+1] - clsp.sum(s_indicator[t-j+2] for j in range(1,t+1))
for j in t for t in period_list )
Output: Keyerror 0 Any help would be appreciated
@vlkong

@vberaudi
Copy link
Member

@HengChheang sum(s[k=t-j+2] from k to t) is not clear to me.
Isn't it something like:

sums = { (t,j) : clsp.sum(s_indicator[k-j+2] for k in range(j,t))  for t in period_list for j in range(1,t+1)}
m_8 = clsp.add_constraints( p_indicator[t,j] >= (s_indicator[t-j+1] - sums[t,j]) for t in period_list for j in range(1,t+1) )

@HengChheang
Copy link
Author

@vberaudi It is actually P[t,j] >= s[t-j+1] - sum(s[t-j+2] from t-j+2 to t) for t = 1,....,N, j = 1,...,t

my code.

from docplex.mp.model import Model
clsp = Model(name = 'capacitated lot sizing problem')
no_of_period = 8
period_list = [t for t in range(1, no_of_period+1)]
s_indicator = clsp.binary_var_dict(period_list, name = 's_indicator')
p_indicator = clsp.binary_var_matrix(period_list, period_list, name = 'p_indicator')
m_8 = clsp.add_constraints(p_indicator[t,j] >= s_indicator[t-j+1] - clsp.sum(s_indicator[t-j+2] for j in range(1,t+1))
for j in t for t in period_list )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants