bestSol: Extract the index of the best solution

bestSolR Documentation

Extract the index of the best solution

Description

Extracts the index of the best solution for all traits under the constraints specified.

Usage

bestSol(object, selectTop=TRUE, n=1)

Arguments

object

A resulting object from the function evolafit.

selectTop

Selects highest values for the fitness value if TRUE. Selects lowest values if FALSE.

n

An integer indicating how many solutions should be returned.

Details

A simple apply function looking at the fitness value of all the solution in the last generation to find the maximum value.

Value

$res

the vector of best solutions in M for each trait in the problem

References

Giovanny Covarrubias-Pazaran (2024). evola: a simple evolutionary algorithm for complex problems. To be submitted to Bioinformatics.

See Also

evolafit – the core function of the package

Examples



set.seed(1)
# Data
Gems <- data.frame(
  Color = c("Red", "Blue", "Purple", "Orange",
            "Green", "Pink", "White", "Black", 
            "Yellow"),
  Weight = round(runif(9,0.5,5),2),
  Value = round(abs(rnorm(9,0,5))+0.5,2),
  Times=c(rep(1,8),0)
)
head(Gems)

 
# Task: Gem selection. 
# Aim: Get highest combined value.
# Restriction: Max weight of the gem combined = 10. 
res0<-evolafit(cbind(Weight,Value)~Color, dt= Gems,
               # constraints: if greater than this ignore
               constraintsUB = c(10,Inf), 
               # constraints: if smaller than this ignore
               constraintsLB= c(-Inf,-Inf), 
               # weight the traits for the selection
               b = c(0,1), 
               # population parameters
               nCrosses = 100, nProgeny = 20, recombGens = 1, 
               # coancestry parameters
               D=NULL, lambda=c(0,0), nQtlStart = 1, 
               # selection parameters
               propSelBetween = .9, propSelWithin =0.9, 
               nGenerations = 50
) 

bestSol(res0$pop, n=2)



evola documentation built on Aug. 8, 2025, 7:54 p.m.