R/fps.R

fps <- function(population,fitnesses,elitism){

        popsize <- nrow(population)
        goodSols <- which(fitnesses>0)
        probShare <- fitnesses[goodSols]/sum(fitnesses[goodSols])
        cutoffs <- cumsum(probShare)
        intpop <- array(dim=dim(population))
        if (elitism){
                fittest <- sort(fitnesses,index.return=TRUE,decreasing=TRUE)$ix[1]
                intpop[1,] <- population[fittest,]
                selectionPoints <- runif(nrow(intpop)-1)
                selectedSols <- goodSols[unlist(lapply(selectionPoints,function(x,cutoffs)min(which(cutoffs>x)),cutoffs=cutoffs))]
                intpop[c(2:popsize),] <- population[selectedSols,]
        }
  
        else {
                selectionPoints <- runif(nrow(intpop))
                selectedSols <- goodSols[unlist(lapply(selectionPoints,function(x,cutoffs)min(which(cutoffs>x)),cutoffs=cutoffs))]
                intpop <- population[selectedSols,]
        }
        intpop
        
}

Try the GABi package in your browser

Any scripts or data that you put into this service are public.

GABi documentation built on May 1, 2019, 8:19 p.m.