线性规划的班次计划 [英] Shift planning with Linear Programming
问题描述
使用R建模和求解线性规划本书在第3.7节中有一个很好的示例,说明了计划转移.我无法用R解决.而且,我对本书中提供的解决方案也不清楚.
The Modeling and Solving Linear Programming with R book has a nice example on planning shifts in Sec 3.7. I am unable to solve it with R. Also, I am not clear with the solution provided in the book.
一家公司设有急救中心,该中心一天24小时不间断地工作.在 下表详细列出了每个员工的最低需求 每天四班制的六班制.
A company has a emergency center which is working 24 hours a day. In the table below, is detailed the minimal needs of employees for each of the six shifts of four hours in which the day is divided.
Shift Employees
00:00 - 04:00 5
04:00 - 08:00 7
08:00 - 12:00 18
12:00 - 16:00 12
16:00 - 20:00 15
20:00 - 00:00 10
R解决方案
我使用以下方法解决了上述问题.
R solution
I used the following to solve the above.
library(lpSolve)
obj.fun <- c(1,1,1,1,1,1)
constr <- c(1,1,0,0,0,0,
0,1,1,0,0,0,
0,0,1,1,0,0,
0,0,0,1,1,0,
0,0,0,0,1,1,
1,0,0,0,0,1)
constr.dir <- rep(">=",6)
constr.val <-c (12,25,30,27,25,15)
day.shift <- lp("min",obj.fun,constr,constr.dir,constr.val,compute.sens = TRUE)
然后,我得到以下结果.
And, I get the following result.
> day.shift$objval
[1] 1.666667
> day.shift$solution
[1] 0.000000 1.666667 0.000000 0.000000 0.000000 0.000000
这与本书中提到的数值解决方案相去甚远.
This is nowhere close to the numerical solution mentioned in the book.
根据数值解所需的解总数为38
.但是,由于问题表明,每个时期都有规定的最小雇员人数,因此该解决方案如何有效?
The total number of solutions required as per the numerical solution is 38
. However, since the problem stated that, there is a defined minimum number of employees in every period, how can this solution be valid?
s1 5
s2 6
s3 12
s4 0
s5 15
s6 0
s1 5
s2 6
s3 12
s4 0
s5 15
s6 0
推荐答案
您的错误在于初始化变量constr
的时候,因为您没有将其定义为矩阵.第二个错误是矩阵本身.看看我的例子.
Your mistake is at the point where you initialize the variable constr
, because you don't define it as a matrix. Second fault is your matrix itself. Just look at my example.
我想知道为什么您不坚持书中的示例,因为我想检查我的解决方案.我的基于此.
I was wondering why you didn't stick to the example in the book because I wanted to check my solution. Mine is based on that.
library(lpSolve)
obj.fun <- c(1,1,1,1,1,1)
constr <- matrix(c(1,0,0,0,0,1,
1,1,0,0,0,0,
0,1,1,0,0,0,
0,0,1,1,0,0,
0,0,0,1,1,0,
0,0,0,0,1,1), ncol = 6, byrow = TRUE)
constr.dir <- rep(">=",6)
constr.val <-c (5,7,18,12,15,10)
day.shift <- lp("min",obj.fun,constr,constr.dir,constr.val,compute.sens = TRUE)
day.shift$objval
# [1] 38
day.shift$solution
# [1] 5 11 7 5 10 0
根据您在评论中的问题进行
EDIT based on your question in the comments:
这是周期内班次的分布:
This is the distribution of the shifts on the periods:
shift | 0-4 | 4-8 | 8-12 | 12-16 | 16-20 | 20-24
---------------------------------------------------
20-4 | 5 | 5 | | | |
0-8 | | 11 | 11 | | |
4-12 | | | 7 | 7 | |
8-16 | | | | 5 | 5 |
12-20 | | | | | 10 | 10
18-24 | | | | | |
----------------------------------------------------
sum | 5 | 16 | 18 | 12 | 15 | 10
----------------------------------------------------
need | 5 | 7 | 18 | 12 | 15 | 10
---------------------------------------------------
这篇关于线性规划的班次计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!