【发布时间】:2019-02-23 03:45:45
【问题描述】:
如何实现广义分配问题:https://en.wikipedia.org/wiki/Generalized_assignment_problem 用 R 中的遗传算法 https://cran.r-project.org/web/packages/GA/GA.pdf 解决。
我有一个代码的工作示例,但它不工作:
require(GA)
p <- matrix(c(5, 1, 5, 1, 5, 5, 5, 5, 1), nrow = 3)
t <- c(2, 2, 2)
w <- c(2, 2, 2)
assigment <- function(x) {
f <- sum(x * p)
penalty1 <- sum(w)*(sum(t)-sum(w*x))
penalty2 <- sum(w)*(1-sum(x))
f - penalty1 - penalty2
}
GA <- ga(type = "binary", fitness = assigment, nBits = length(p),
maxiter = 1000, run = 200, popSize = 20)
summary(GA)
【问题讨论】:
-
您是否看过这些出版物:A Genetic Algorithm for the Generalised Assignment Problem 和 A genetic algorithm for the generalised assignment problem?谷歌搜索揭示了更多优化/专业的 GA 实现。
标签: r genetic-algorithm integer-programming