0

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:

  • 0:00-4:00 < 5 4:00-8:00 < 7 8:00-12:00< 15 12:00-16:00 <10 16:00-20:00 <15 20:00-24:00 <9

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.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Mick
  • 21
  • 7

2 Answers2

0

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
WhiteViking
  • 3,146
  • 1
  • 19
  • 22
  • Thank you, I understand it now. Yes, this example does not solve my problem, it actually says, that I need max. 5 employees, whitch is not true at all. I still think about this case, but cant figure it out. – Mick Sep 06 '15 at 14:12
0

OK, I got it after 4 days :)) I post results here if anybody else'd have same problem. The main difficulty here is to calculate "people" as "number of hours at one shift"

a=c(1,1,1,1,1,1)
> w1=c(4,0,0,0,0,4)
> w2=c(4,4,0,0,0,0)
> w3=c(0,4,4,0,0,0)
> w4=c(0,0,4,4,0,0)
> w5=c(0,0,0,4,4,0)
> w6=c(0,0,0,0,4,4)
> b1=c(20,28,60,40,60,36)
> library(boot)
> simplex(a=a,A1=rbind(w1,w2,w3,w4,w5,w6)
+ ,b1=b1,maxi=T)

Linear Programming Results

Call : simplex(a = a, A1 = rbind(w1, w2, w3, w4, w5, w6), b1 = b1, maxi = T)

Maximization Problem with Objective Function Coefficients

x1 x2 x3 x4 x5 x6 
 1  1  1  1  1  1 

Optimal solution has the following values

x1 x2 x3 x4 x5 x6 
 5  2 10  0  9  0 

The optimal value of the objective function is 26. CLOSED, Deletle subject or leave for others. Thank you admins for edit and @WhiteViking !

Mick
  • 21
  • 7