I am trying to formulate this complex matrix based constraint in PuLP for a cost Optimization Problem: I have a vars[(i,j)] for i in TruckTypes for j in Days
as my decision variable which can take only non-negative integer values. I am trying to implement a constraint on number of active
days.
Now, Since Days
are denoted as columns, any column which has all zero values is an inactive
day and all other columns are active
days. There are 6 columns denoting Monday to Saturday. For Example in the below Matrix :
1 0 0 1 3 0
0 0 0 1 1 0
2 0 0 1 0 0
0 0 0 1 0 0
Columns 2,3 and 6 are inactive
and Columns 1,4 and 5 are active
. Now, How to formulate a constraint such as Number of active Days == 3
for this decision variable.
Any Help will be Appreciated. Thanks!!
After thinking for a while.. I think I have cracked this one...
ActiveDays = LpVariable.dicts('activedays', Days,0,1, LpBinary)
M=200000
prob += LpSum(m[j] for j in Days) ==3
Add Second Constraint
for j in Days: prob += LpSum(vars[i][j] for i in TruckTypes) <= M*m[j]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.