Roulette wheel selection for function minimization

Use the same algorithm but make the proportion of each individual = maxfitness - fitness


import java.util.Random;
import java.util.Arrays;
import java.util.Comparator;

class MyComparator implements Comparator
{
    public int compare(Object o1, Object o2)
    {
        Number n1 = (Number) o1;
        Number n2 = (Number) o2;

        if(n1.jump > n2.jump)
        {
            return 1;
        }
        else if(n1.jump < n2.jump)
        {
            return -1;
        }
        else
        {
            return 0;
        }
    }
}


class Number
{
    public double i;
    public int pos;
    public double jump = 0;


    public Random r = new Random();

    public Number(int pos)
    {
        this.pos = pos;

        i = r.nextInt();
    }
}


public class Temp
{
    public static  void main(String[] args)
    {
        Number[] n = new Number[50];

        double total = 0;

        for(int i=0; i<50; i++)
        {
            n[i] = new Number(i);

            total += n[i].i;
        }

        for(int i=0; i<50; i++)
        {
            n[i].jump = n[i].i/total;
        }


        Arrays.sort(n, new MyComparator());     

        for(int i=0; i<50; i++)
        {
            System.out.print(n[i].pos + ", ");
        }

        System.out.println();

        for(int i=0; i<50; i++)
        {
            n[i].jump = n[i].i / total;
            n[i].jump = 1-n[i].jump;
        }

        Arrays.sort(n, new MyComparator());     

        for(int i=0; i<50; i++)
        {
            System.out.print(n[i].pos + ", ");
        }

        System.out.println();   
    }
}

In above example, say Number class is your individual class, i is fitness, jump is the probability of being selected as parent. At first we compute the probability of being selected as parent like before. At this step, higher fitness will get higher probability. Then we subtract probability from 1. This gives lower fitness individual higher fitness (pseudo fitness for selection's sake). Now recalculate the probability. See, the order of being is totally reversed.


Roulette wheel cannot be used for minimization because of the scaling. Furthermore, it also cannot be used when there are negative or null fitnesses because their probability would be negative or null.

As suggested by Larry you can use local normalization by subtracting, to the maximal fitness of your population, the fitness of each individual, but again you will have to fix the maximal fitness so that it has not a null probability.

I suggest you to use a tournament selection that has been proved multiple times better than roulette.