I am trying to use R LPSolve to create an automatic scheduling tool. But the output seems cant meet my expectation. the demand cant be fully covered. Please kindly help me out this problem !! Many many thanks!!

Given that I have demand by hourly basis. I need to assign shift based on the demand in order to meet the demand as much as possible. I currently have 9 shifts (obj.fun).

The objective:

to minimize the difference between total supply and total demand to minimize the difference between supply and demand for each hour

In the constr matrix, 24 rows represent 24 hours starting from 7 am and 9 columns refers to no. of shifts I have.

The constr.val refers to hourly demand.

library(lpSolve)
obj.fun<-c(1,1,1,1,1,1,1,1,1)
constr<-matrix(c(
1,  0,  0,  0,  0,  0,  0,  0,  0,
1,  0,  0,  0,  0,  0,  0,  0,  0,
1,  0,  0,  0,  0,  0,  0,  0,  0,
1,  0,  0,  1,  0,  0,  0,  0,  0,
1,  0,  0,  1,  0,  1,  0,  0,  0,
1,  0,  0,  1,  0,  1,  0,  1,  0,
1,  0,  0,  1,  0,  1,  0,  1,  0,
1,  0,  0,  1,  0,  1,  0,  1,  0,
0,  1,  0,  1,  0,  1,  0,  1,  0,
0,  1,  0,  1,  0,  1,  0,  1,  0,
0,  1,  0,  1,  0,  1,  0,  1,  0,
0,  1,  0,  0,  1,  1,  0,  1,  0,
0,  1,  0,  0,  1,  0,  1,  1,  0,
0,  1,  0,  0,  1,  0,  1,  0,  1,
0,  1,  0,  0,  1,  0,  1,  0,  1,
0,  1,  0,  0,  1,  0,  1,  0,  1,
0,  0,  1,  0,  1,  0,  1,  0,  1,
0,  0,  1,  0,  1,  0,  1,  0,  1,
0,  0,  1,  0,  1,  0,  1,  0,  1,
0,  0,  1,  0,  0,  0,  1,  0,  1,
0,  0,  1,  0,  0,  0,  0,  0,  1,
0,  0,  1,  0,  0,  0,  0,  0,  0,
0,  0,  1,  0,  0,  0,  0,  0,  0,
0,  0,  1,  0,  0,  0,  0,  0,  0),nrow=24,byrow=TRUE)
constr.dir<-rep("<=",24)
constr.val<-c(24,   20, 21, 22, 26, 34, 40, 44, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 41, 27)
day.shift<-lp("max",obj.fun,constr,constr.dir,constr.val,compute.sens=TRUE)

day.shift$objval

day.shift$solution

0 Answers