我曾尝试使用R包LPSolve,特别是lp.transport函数来解决优化问题。我想最大限度地减少上班的总距离,同时满足每个办公室的最小员工数量。
最初,这是有效的,因为我对所有员工一视同仁(1)。然而,当我根据每个员工的效率对他们进行评分时,问题就开始出现了。例如,我现在想说,officeX需要相当于2个工程师,这可能由4个50%效率的工程师或1个200%效率的工程师组成。当我这样做时,但是找到的解决方案会将一个员工拆分到多个办公室,我需要的是一个额外的约束,因此强制一个员工只能在一个办公室。无论如何,希望这就是足够的背景知识,下面是我的例子:
Employee <- c("Jim","John","Jonah","James","Jeremy","Jorge")
Office1 <- c(2.58321505105556, 5.13811249390279, 2.75943834864996,
6.73543614029559, 6.23080251653027, 9.00620341764497)
Office2 <- c(24.1757667923894, 19.9990724784926, 24.3538456922105,
27.9532073293925, 26.3310994833106, 14.6856664813007)
Office3 <- c(38.6957155251069, 37.9074293509861, 38.8271000719858,
40.3882569566947, 42.6658938732098, 34.2011184027657)
Office4 <- c(28.8754359274453, 30.396841941228, 28.9595182970988,
29.2042274337124, 33.3933900645023, 28.6340025144932)
Office5 <- c(49.8854888720157, 51.9164328512659, 49.948290261029,
49.4793138594302, 54.4908258333456, 50.1487397648236)
#create CostMatrix
costMat<-data.frame(Employee,Office1, Office2, Office3, Office4, Office5)
#efficiency is the worth of employees, eg if 1 they are working at 100%
#so if for example I wanted 5 Employees
#working in a office then I could choose 5 at 100% or 10 working at 50% etc...
efficiency<-c(0.8416298, 0.8207991, 0.7129663, 1.1406839, 1.3868177, 1.1989748)
#Uncomment next line to see the working version based on headcount
#efficiency<-c(1,1,1,1,1,1)
#Minimum is the minimum number of Employees we want in each office
minimum<-c(1, 1, 2, 1, 1)
#solve problem
opSol <-lp.transport(cost.mat = as.matrix(costMat[,-1]),
direction = "min",
col.signs = rep(">=",length(minimum)),
col.rhs = minimum,
row.signs = rep("==", length(efficiency)),
row.rhs = efficiency,
integers=NULL)
#view solution
opSol$solution
# My issue is one employee is being spread across multiple areas,
#what I really want is a extra constraint that says that in a row there
# can only be 1 non 0 value.发布于 2016-03-01 00:53:05
我认为这不再是一个交通问题了。但是,您仍然可以将其作为MIP模型来解决:

https://stackoverflow.com/questions/35703346
复制相似问题