我认为,你的问题是多Knapsack 问题(MKP)的一个近似变体,它是一个先验的问题,不是一件ake事。
然而,你的层面很小,这个问题可以作为一个混合分类方案加以解决。 我用<代码>Rglpk将其解决。 如果你能够接触到CPLEX,我会非常建议你使用code>,否则就会吸烟。
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
Problem formulation:
# 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