0

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!!

1 Answers1

0

After thinking for a while.. I think I have cracked this one...

  1. Create a dummy 1-D binary decision Variable for Active Days. 0- NonActive 1-Active.

ActiveDays = LpVariable.dicts('activedays', Days,0,1, LpBinary)

  1. Create a Dummy very large Constant.

M=200000

  1. Add first Constraint.

prob += LpSum(m[j] for j in Days) ==3

  1. Add Second Constraint

    for j in Days:
    
         prob += LpSum(vars[i][j] for i in TruckTypes) <= M*m[j]