[R] Genalg not respecting constraints

byku martin.lukasiewicz at gmail.com
Sun Feb 27 15:21:55 CET 2011


Hello everyone,
I've got a pretty simple exercise to solve with genalg. The goal is to
maximize the revenue.
Even tough genalg is not respecting rather simple constraints.
What's wrong with my code?

library(genalg)


evaluate <- function(X=c()) {
returnVal = NA;
a<-c(X*c(2,0,0,4,8,1,0),X*c(0,2,1,0,3,4,5),X*c(1,0,1,0,3,0,1),X*c(7,2,0,5,0,0,9),X*c(0,4,0,1,0,11,0),X*c(3,6,10,0,0,0,0),X*c(1,0,0,8,0,1,3),X*c(0,9,0,0,1,4,0));
b<-c(148,87,234,176,23,845,234,111);
d<-b-a;
if (min (d)>=0)
{returnVal<-sum(a*c(-50,-237,-128,-34,-27,-239,-78,-99))}else{returnVal<-10000}
returnVal
}


rbga.results =
rbga(c(0,0,0,0,0,0,0),c(100,100,100,100,100,100,100),popSize=500,
evalFunc=evaluate, iters=1000,verbose=TRUE, mutationChance=0.01)


summary.rbga(rbga.results,echo=TRUE)


plot(rbga.results)

Thank you for your help
best regards

-- 
View this message in context: http://r.789695.n4.nabble.com/Genalg-not-respecting-constraints-tp3326819p3326819.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list