I am trying to explore the field of optimization using GA in R. I understand that R is probably not the best place for me, but that is what I know right now.
So, here is the problem: I have a set of people who I can choose to build my home most efficiently. I am ready to spend no more than 100,000 on work (a limit beyond which the solution no longer applies), and I must choose one electrician, two plumbers, two general builders and two guys from the list of 500 or so (7 guys for work in total).
Each of these people has a rate that they will charge for work, and the total cost that they will provide for work (the total amount should be maximum). See data here:
Data
I looked at genalg and DeOptim R packages, where you can use binary functions to select people who maximize the total value for a given price, but I cannot determine how to set a limit on what type of employee is selected. The solution can be all electrician, and although they all provide great value, they cannot complete the job. So basically I'm looking for a way to manage the population, and none of these packages seem to allow this.
Any ideas on how I can solve this problem? I am sure that many of you have considered options for this problem and received excellent information. Thank you very much for your help.
Here is the code I got from the forums here:
library(genalg)
iter = 10
population = 500
brank = read.csv("GA_Data.csv")
dataset <- data.frame(item = brank$Person.ID, survivalpoints = brank$Value, weight = brank$Labor.Cost)
weightlimit <- 100000
monitor <- function(obj) {
minEval = min(obj$evaluations);
plot(obj$mean, obj$best, type="p", main = obj$iter);
}
evalFunc <- function(x) {
current_solution_survivalpoints <- x %*% dataset$survivalpoints
current_solution_weight <- x %*% dataset$weight
if (current_solution_weight > weightlimit)
return(0) else return(-current_solution_survivalpoints)
}
GAmodel <- rbga.bin(size = length(brank$Person.ID), popSize = population, iters = iter, mutationChance = 0.01,
monitorFunc = monitor, elitism = T, zeroToOneRatio = 200, evalFunc = evalFunc)
cat(summary.rbga(GAmodel))
solution = c(0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0)
brank[solution == 1, ]
sum(brank$Value[solution == 1])
sum(brank$Labor.Cost[solution == 1])