我相信你的问题是多重背包问题(MKP)的一个近似变体,这是先验的,而不是小菜一碟......
但是,您的维度足够小,可以通过混合整数规划 (MIP) 来解决问题。我在下面使用解决了它Rglpk
;求解器花了大约四分钟。如果您有幸能够访问 CPLEX,我强烈建议您改用Rcplex
它,它会冒烟。
ItemTime<-c(3,75,55,12,45,55,11,8,21,16,65,28,84,3,58,46,5,84,8,48)
N <- length(ItemTime)
M <- 3
问题表述:
# variables are in this order:
# z: slack variable for the max of (s1, s2, s3)
# s1: sum of times for machine 1
# s2: sum of times for machine 2
# s3: sum of times for machine 3
# a1-a20: booleans for assignment to machine1
# b1-b20: booleans for assignment to machine1
# c1-c20: booleans for assignment to machine1
obj <- c(1, rep(0, 3 + 3*N))
mat <- rbind(
c(1, -1, 0, 0, rep(0, M*N)), # z >= s1
c(1, 0, -1, 0, rep(0, M*N)), # z >= s2
c(1, 0, 0, -1, rep(0, M*N)), # z >= s3
c(0, -1, 0, 0, ItemTime, rep(0, N), rep(0, N)), # s1 = ...
c(0, 0, -1, 0, rep(0, N), ItemTime, rep(0, N)), # s2 = ...
c(0, 0, 0, -1, rep(0, N), rep(0, N), ItemTime), # s3 = ...
cbind(matrix(0, N, 4), diag(N), diag(N), diag(N)) # a_i + b_i + c_i = 1
)
dir <- c( ">=", ">=", ">=", "==", "==", "==" , rep("==", N))
rhs <- c(rep(0, 2*M), rep(1, N))
types <- c(rep("C", 1+M), rep("B", M*N))
现在让我们解决它:
Rglpk_solve_LP(obj, mat, dir, rhs, types, max=FALSE, verbose=TRUE)
# GLPK Simplex Optimizer, v4.47
# INTEGER OPTIMAL SOLUTION FOUND
# $optimum
# [1] 244
#
# $solution
# [1] 244 243 243 244 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 0 0
# [31] 1 1 1 0 1 0 0 0 1 0 1 0 1 0 1 0 0 0 1 1 0 0 0 1 0 1 0 1 0 1
# [61] 0 0 0 1
#
# $status
# [1] 0