# How to design a fitness function for the 8-queens problem?

In evolutionary computation and, in particular, in the context of genetic algorithms, there is the concept of a fitness function. The better a state, the greater the value of the fitness function for that state.

What would be a good fitness function for the 8-queens problem?

Here you can find an example of how to apply genetic algorithms to solve the 8-queens problem.

The proposed fitness function is based on the chessboard arrangement, and in particular, it is inversely proportional to the number of clashes amongst attacking positions of queens; thus, a high fitness value implies a low number of clashes.

This can be calculated quite easily in the context of 8-queen problem. Just start with a particular configuration. Starting from the queen in the left-most column just keep on counting the non-attacking positions (pairs) on the right with each queen. Carry on column by column towards your right until you reach the last queen. As a special case for the last queen the non-attacking pairs will be zero as their are no other queens after that.

• This describes how to solve the problem, but it doesn't answer the question which is about formulating this as a fitness function to use in evolutionary computing. Dec 2, 2019 at 11:23