title: Converting Integer programming to binary in python
body: <p><a href="https://i.stack.imgur.com/TpuQy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TpuQy.png" alt="Excel Image"></a></p>
  
  <p>See the image above to understand my explanation of the problem.</p>
  
  <pre><code>from scipy.optimize import linprog
  
  a = [-800,-1200,-800]
  
  b = [[200,100,400],[200,200,400],[200,300,200]]
  
  c = [600,600,600]
  
  result = linprog(a,b,c)
  print(result)
  </code></pre>
  
  <p>The code I have written is above. The number in the output I am interested is <code>fun : -2400.0</code> &lt;-- This is the current result. This is not what I want though.</p>
  
  <p>Here is the problem and what I am looking for.</p>
  
  <p>In the picture, there are two tables. The table on the RHS is the integer part and the LHS table is the binary part. The answer that I want is <code>fun : -2800.0</code>, which is part of the 4th column in LHS table.</p>
  
  <p>Let me tell you how I determined that answer.
  First, as you can see there are all possible combinations of 0's and 1's are written for all the three assignments in the LHS table. I have to find the best highest number from the 4th column LHS that satisfies all the conditions in RHS table. For ex: Starting with the top; numbers taken from LHS and RHS table. 1 means choose that assignment and 0 means don't choose. So the first row has 1 1 1 meaning choosing all the assignments. Now, we add all the numbers for day 0,1,and 2 and we can see that they all go above 600. Adding 200*1+100*1+400*1=700 which is greater than 600. Same thing for day 1 and 2. So, 2801 is not the number we want. Next, we choose 2800, and it does satisfy the total condition of every added number &lt;= 600 because assignment1 is 0, so 200*0+100*1+400*1=500, which is less than 600, and same thing for the remaining two days.</p>
  
  <p>I just don't understand how to put every single thing in python and get result of -2800 instead -2400.</p>
  
  <p>There has to be a simple way with linprog.</p>
  
  <p>The way I got the numbers in the 4th of LHS table was using the green highlighted numbers from RHS table, which are also on the last row of LHS table.
  I did =((B5+$B$13)+(C5*$C$13)+(D5*$D$13)) to get 2801 and so on for the remaining ones.</p>
  
  <p>Without using linprog, I can't think anything better than the following code:</p>
  
  <pre><code>B = [800,1200,800]
  A = [[200,100,400],[200,200,400],[200,300,200]]
  
  for num in A[0],A[1],A[2]:
      t0 = num[0]*1 + num[1]*1 + num[2]*1
      t1 = num[0]*0 + num[1]*1 + num[2]*1
      print(t0)
  </code></pre>