Ploxzx
Ploxzx

Reputation: 53

Genetic Algorithm : Langermann's function and Tournament selection

I'm having some trouble understanding how to implement Langermann's function and tournament selection in my Genetic algorithm. I have this as a reference for Langermann's function but I don't understand where the C value comes from, seeing as I only have an X and Y. Is the C value always a constant set of numbers?

As for tournament selection, I want to randomly select any 3 of my population and compare their fitness. Once being able to generate fitness values with Langermann's function, I will have each fitness value stores in a vector. I then want to select 3 unique random elements from the vector and compare them with one another. How do you select 3 unique random elements from a vector without using the same numbers?

Any help is appreciated!

Upvotes: 4

Views: 741

Answers (1)

manlio
manlio

Reputation: 18902

Lagermann function

is the C value always a constant set of numbers?

The proposed values for m, c and A are those given by Molga & Smutnicki (2005).

c is a constant vector (other values are possible / in use).

The function is usually evaluated on (x, y) ∈ [0, 10] x [0, 10]. It presents m minima whose importance is determined by c. They're modulated by the product of a cosine, which gives them an oscillatory character.

As for every complex expression, the best way to translate the Langermann function is starting from simpler sub-expressions.

There are two identical "internal" summations:

const double A[5][2] = {{3.0, 5.0},{5.0, 2.0},{2.0, 1.0},{1.0, 4.0},{7.0, 9.0}};
const double c[5] = {1.0, 2.0, 5.0, 2.0, 3.0};
const unsigned d = 2;

double s = 0.0;
for (unsigned j = 0; j < d; ++j)
  s += std::pow(x[j] - A[i][j], 2.0);

Now for the main summation:

const double pi = 3.1415926535897932;
const unsigned m = 5;

double ret = 0.0;
for (unsigned i(0); i < m; ++i)
{
  // calculate `s`

  ret += c[i] * std::exp(-s / pi) * std::cos(pi * s);
}

and ret contains the value of the function.


How do you select 3 unique random elements from a vector without using the same numbers?

The naive approach is: generate a random number, then check whether it was already used and, if it was already used, just generate another number until finding an unused one.

It's a simple sequence of do ... while () loops.

If the population size is small or the range of choice artificially restricted (10/15 individuals) this can be quite expensive.

Many alternatives are described in Unique random numbers in an integer array in the C programming language

Upvotes: 4

Related Questions