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:
I have various constraints, the sum of each column of X are >= a. So, this would be written as (EDIT: SHOULD BE >=)
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):
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?
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.