rsimplex

How to specify variables in this simplex method case?


I'm about to learn all about the simplex method in R project, unfortunately I crashed in this case:

We're running a 24h shop and we need to know how many employees do we need if there are six shifts (8-12,12-16 etc.) during the day, and one employee can work a maximum of 8 hours. Limits of the employees at one shift are:

I tried this:

library(boot)
a=c(1,1,1,1,1,1)
w1=c(1,1)
w2=c(1,1)
w3=c(1,1)
w4=c(1,1)
w5=c(1,1)
w6=c(1,1)
A1=rbind(w1,w2,w3,w4,w5,w6)
b1=c(5,7,15,10,15,9)
simplex(a=a,A1=A1,b1=b1,maxi=TRUE)

Error in`[<-`(`*tmp*`, , basic, value = iden(M)) : 
   index is out of borders

But it doesn't work.


Solution

  • The error occurs because the dimensions of the input matrices and vectors are not correct.

    Since the coefficients vector a in your example has dimension 6, also the vector x in the objective function must have dimension 6. And since the b1 that is supplied to simplex() also has dimension 6, it follows that A1 in the constraint

    A1 * x <= b1
    

    must be a 6 x 6 matrix. However, A in your example is only a 6 x 2 matrix. This triggers the error message. (It would have been nicer if simplex() checked its inputs first and issued a more user friendly message...)

    Here is an example with the right dimensions, which does work:

    library(boot)
    a = rep(1, 6)                        # vector with 6 ones
    A1 = matrix(1, nrow=6, ncol=6)       # 6x6 matrix with all ones
    b1 = c(5, 7, 15, 10, 15, 9)
    simplex(a=a, A1=A1, b1=b1, maxi=TRUE)
    

    Note that this corrected example does not try to actually solve your specific simplex problem, it only illustrates correct usage of simplex().

    In general it is worth carefully checking the input dimensions of the inputs to simplex(). They are explained nicely in the help pages:

    ?simplex