RankingSort Class

Inheritance Hierarchy
  • Laga.GeneticAlgorithm
    • public class RankingSort
      • BidirectionalBubbleSort(population, arrResults, minmax)


Class Constructor:
Syntax Parameters
RankingSort()


Methods

BidirectionalBubbleSort(population, arrResults, minmax)

  • Description: Sort the individuals in the population by fitness value.
  • Parameters:
    • population[object or double or float or int or char]: population to sort
    • arrResults[int or float]: Array of fitness in the population
    • minmax[boolean]: if is true the sort is by max to min, else min to max
  • Return: modify itself the original population.

Example

GenrPopulation popToSort = new GenrPopulation(5); //create a population
int[][] pop = popToSort.NumPopulation(3, 1, 11);

float[] arrR = new float[5]; //random fitness.
for(int i = 0; i < 5; i++)
    arrR[i] = (float)LagaTools.GetRandomNumber();

RankingSort rs = new RankingSort(); //apply ranking sort
rs.BidirectionalBubbleSort(pop, arrR, true);

//result
Unsorted Population:
chr: 3, 10, 6 Fitness: 0.488704
chr: 8, 1, 6 Fitness: 0.7935584
chr: 8, 6, 11 Fitness: 0.5336143
chr: 2, 11, 3 Fitness: 0.8152208
chr: 2, 11, 9 Fitness: 0.5565483

Sorted Population:
chr: 2, 11, 3 Fitness: 0.8152208
chr: 8, 1, 6 Fitness: 0.7935584
chr: 2, 11, 9 Fitness: 0.5565483
chr: 8, 6, 11 Fitness: 0.5336143
chr: 3, 10, 6 Fitness: 0.488704


Revised documentation: 2019/07/03