0

I need to solve a problem (reproducible toy example below):

There is a p matrix (N =3 x M=2):

p<-matrix(c(3,17,14,20,0,3), nrow=3, ncol=2, byrow=TRUE)

I seek to maximize the element-wise sum where lets say X is (3x2) and are binary variables:

enter image description here

The sum we are maximizing: enter image description here

I have various constraints, the sum of each column of X are >= a. So, this would be written as (EDIT: SHOULD BE >=)

enter image description here

Another is that the rows of X need to be <= 1. This means that at most only a single X in a row can be activated (=1):

enter image description here

Back to R:

For the objective function:

Question #1: Do I need to "stretch" the p matrix into a vector:

obj<-c(3,17,14,20,0,3) 

For the constraints:

Question #2 Does the constraint matrix need to be sized (rows= number of constraints, columns = number of x's in X)?

So for these constraints, it would be (5,6)?

Question #3

Would the constraint matrix look like this - assuming I am correct about Question #2?

enter image description here

The first row represents x11 + x21 + x31 >= a1

The second row represents x12 + x22 + x32 >= a2

The third row represents x11 + x12 <=1

The fourth row represents x21 + x22 <=1

The fifth row represents x31 + x32 <=1

Then of course the direction matrix and the RHS matrix are set accordingly.

B_Miner
  • 1,840
  • 4
  • 31
  • 66
  • See ?lp.transport – G. Grothendieck Sep 01 '18 at 21:04
  • Not sure I see the connection I am afraid. If you happen to know if my setup / understanding for lpSolve is correct I would appreciate any feedback. – B_Miner Sep 02 '18 at 01:25
  • @G.Grothendieck, I see now that my problem is a transportation problem. I did not however provide sufficient information, in that I have one additional constraint which is that the grand sum of the rows and columns of X (which are binary variables) need to be <= T. It does not appear this can fit into the transportation problem framework. – B_Miner Sep 02 '18 at 13:52

0 Answers0