, - (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
:
obj <- c(1, rep(0, 3 + 3*N))
mat <- rbind(
c(1, -1, 0, 0, rep(0, M*N)),
c(1, 0, -1, 0, rep(0, M*N)),
c(1, 0, 0, -1, rep(0, M*N)),
c(0, -1, 0, 0, ItemTime, rep(0, N), rep(0, N)),
c(0, 0, -1, 0, rep(0, N), ItemTime, rep(0, N)),
c(0, 0, 0, -1, rep(0, N), rep(0, N), ItemTime),
cbind(matrix(0, N, 4), diag(N), diag(N), diag(N))
)
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