Dear Paul,
Thank you so much for your recommendation. I already have the Y variables, which in my case it is called Z[k][i].
However, there is an error when I defined the constraint for the sorted S. Do you have any idea on what I might define it incorrectly? Thank you.
This is my code:
Total_T = 6
obj_lambda = mdl.continuous_var(lb = 0, ub=inf, name='obj_lambda')
x = np.empty((Total_T,1), dtype= object)
for i in range(Total_T):
x[i] = mdl.continuous_var(lb= 0, ub= inf, name='x' + str(i+1))
Z = np.empty((Total_T, Total_T), dtype = object)
for k in range(Total_T):
for i in range(Total_T):
Z[k][i] = mdl.binary_var(name='Z' + str(k+1) + str(',') + str(i+1))
S = np.empty((Total_T,1), dtype= object)
for k in range(Total_T):
S[k] = mdl.continuous_var(lb= 0, ub= inf, name='S' + str(k+1))
for k in range(Total_T):
for i in range(Total_T):
if Z[k][i] is 1:
S[k] = x[i]
for k in range(Total_T):
if S is not None:
mdl.add_constraint(S[k]<= S[k + 1] <= S[k + 2] <= S[k + 3] <= S[k + 4] <= S[Total_T - 1] <= S[k] + obj_lambda)
Traceback (most recent call last):
File "C:/Users/pknu/Documents/Research/project/MILP Correct 19 July 2022.py", line 152, in <module>
mdl.add_constraint(S[k]<= S[k + 1] <= S[k + 2] <= S[k + 3] <= S[k + 4] <= S[Total_T - 1] <= S[k] + obj_lambda)
File "C:\Users\pknu\anaconda3\envs\env-cplex\lib\site-packages\docplex\mp\constr.py", line 101, in __bool__
self._no_linear_ct_in_logical_test_error() # pragma: no cover
File "C:\Users\pknu\anaconda3\envs\env-cplex\lib\site-packages\docplex\mp\constr.py", line 549, in _no_linear_ct_in_logical_test_error
raise TypeError(msg)
TypeError: Cannot convert a linear constraint to boolean: S1 <= S2
In addition, the next two constraints which I am going to write are:
bigM = 1000000
for k in range(Total_T):
for i in range(Total_T):
if S.any() is not None and x.any() is not None:
mdl.add_constraint(S[k] - xi[i] <= (1 - Z[k][i])*bigM)
mdl.add_constraint(S[k] - xi[i] >= (Z[k][i] - 1)*bigM)
------------------------------
Nicholas Nicholas
------------------------------
Original Message:
Sent: Mon July 18, 2022 01:34 PM
From: Paul Rubin
Subject: How to define a set of decision variables in ascending order?
If each X is an epoch, then they should all be bounded above by the maximum possible epoch. So you would just need an a priori limit on cycle time.
In any case, the following is how I would incorporate S directly in the model. In addition to X and S, you would need binary decision variables Y[i][j], where Y[i][j] = 1 implies that S[i] = X[j] (and so X[j] is the i-th smallest of the X values). With 6 transitions, this would be 36 Y variables.
To make sure that the Y variables are well defined, you need constraints that say the sum over j of Y[i][j] = 1 for all i and the sum over i of Y[i][j] = 1 for all j.
To get the sorted epoch times in S, you add constraints S[1] <= S[2] <= ... <= S[6].
Now you just need enforce the definition of Y[i][j]. One possibility is to use implication (if-then) constraints in the model: Y[i][j] == 1 => S[i] = X[j] for all i and j. The other possibility, which depends on knowing an upper bound M for very X variable, is to use two inequalities for each combination of i and j: S[i] <= [j] + M(1-Y[i][j]) and S[i] >= X[j] - M(1 - Y[i][j]). With a reasonably tight (but valid) bound M, I suspect the second approach will solve faster. If you don't have a value for M (other than setting M to some extremely big number), the first approach is at least worth a try.
------------------------------
Paul Rubin
Professor Emeritus
Michigan State University
Original Message:
Sent: Mon July 18, 2022 12:27 PM
From: Nicholas Nicholas
Subject: How to define a set of decision variables in ascending order?
Dear Paul,
To give you a little bit of background, the objective is to minimize the cycle time (lambda) for a semiconductor cluster tools scheduling case.
From the Timed Petri Net concept, we will have a set of transitions (T) and Places (P). Each t in T will be corresponded to each p in P.
x is the firing epoch of transition ti ∈ T in a cycle. So, if there are 6 transitions, then there will be 6 x's.
Let me know if you have any further questions, thank you.
Yours sincerely,
Nicholas
Original Message:
Sent: 7/18/2022 12:07:00 PM
From: Paul Rubin
Subject: RE: How to define a set of decision variables in ascending order?
You might be able to make it work with implication (if-then) constraints, but if X is truly unbounded I'm not sure how well CPLEX would handle those constraints. What do the X variables represent?
------------------------------
Paul Rubin
Professor Emeritus
Michigan State University
Original Message:
Sent: Mon July 18, 2022 11:40 AM
From: Nicholas Nicholas
Subject: How to define a set of decision variables in ascending order?
Dear Paul,
Unfortunately there is no apriori upper bound for each X. So, the CPLEX will get the value for each X with the objective function to minimize the cycle time (lambda).
Will there be any possibility of other ways to define the decision variable S?
Thank you so much.
Yours sincerely,
Nicholas
Original Message:
Sent: 7/18/2022 11:18:00 AM
From: Paul Rubin
Subject: RE: How to define a set of decision variables in ascending order?
You will have to add a bunch of binary variables and constraints to enforce this. Unfortunately, they require a finite upper bound on each X variable, whereas you have declared the upper bounds to be infinity. Can you come up with a priori upper bounds for every X?
------------------------------
Paul Rubin
Professor Emeritus
Michigan State University
Original Message:
Sent: Mon July 18, 2022 10:56 AM
From: Nicholas Nicholas
Subject: How to define a set of decision variables in ascending order?
Dear All,
Good day to you.
I would like to define two decision variables for
docplex.mp in cplex as follows.
X = a set of decision variables, i.e.[ [X1] ,
[X2] ,
[X3],
[X4],
[X5],
[X6] ]
S = a set of sorted decision variables of X in ascending order (smallest value of X to the largest value of X), i.e. [ [S1] ,
[S2] ,
[S3],
[S4],
[S5],
[S6] ]
I need the S decision variables for the next MILP constraints.
x = np.empty((Total_T,1), dtype= object)
for i in range(Total_T):
x[i] = mdl.continuous_var(lb= 0, ub= inf, name='x' + str(i+1))
S = x.sort()
Thank you in advance.
Yours sincerely,
Nicholas
#DecisionOptimization