I'm trying to add a logical condition constraint into a linear expression on puLP in python. I have translated them by myself and coded them, but the solution is infeasible, which should not be the case. Is there something wrong with my logic? Are there better ways to deal with this problem?
My problem is the following: I have a row of numbers ar_i, each number corresponds to a number. ar_1's corresponding number is 1, etc.
my decision variables are m and d, where m is an integer ranges from 1 to 8, d is an integer ranges from -2 to 2.
If I choose a m and a d, for example m = 6 and d = -1, like in the picture, then I move part of the row by d. As the picture shows, the blue part is moved -1 position. Hence my b_5 = ar_6, b_6 = ar_7, etc. b_1,b_2,b_3,b_4 = 0 here.
I would like to get b_1 to b_9.
In logical condition, I have the following: for j in range(9): if j < m+d, then b_j = 0,else b_j = ar_j-d
Here's what I've done: I'm using PuLP in python since this problem is one of the major constraints. The I've translated the logical condition as the following. The two blocks of code works well by themselves, but combined together, PuLP says that it is infeasible. My guess would be somehow the constraints are conflict.
For simplicity I'll just show the pseudo code:
for j in range(1,10)
m+d >= j - M*(1-a_j)+0.01
m+d <= j+ M *(a_j)
0 - M*(1-a_j) <= b_j <= 0 + M*(1-a_j)
c_j - M*(a_j)<=b_j<=c_j+M*(a_j)
where a_j is a binary variable. If j < m+d, then a_j = 1, else 0.
c_j = sum_over_t_from_1_to_12(k_t * ar_t)
t <= j - d + M*(1-k_t)
t >= j - d - M*(1-k_t)
sum_over_t_from_1_to_12(k_t) = 1
where k_t is a binary variable. If t = j-d, then k_t = 1, else 0.
*The code is pseudo code.
Thanks!!!
Start with an example that PuLP says is infeasible but for which you know a feasible solution. Substitute that solution into the model and see which constraints are violated. Either your "feasible" solution is not really feasible, or those constraints are incorrect.