Designing a good fitness function is not a trivial task, and, in fact, it is usually the central task for creating a successful genetic algorithm. You have not provided much detail, but I will try to provide some useful analysis.
One requirement of a good fitness function is that it must provide a smooth path to where you want to go from at least some of the starting points in gene-space. That is, if you start at a random point in gene-space, can you mostly, incrementally migrate to better and better places in gene-space using the fitness function as a guide.
Looking at your fitness function, my inclination is that the easiest solution to find is simply not moving much. Let's break the fitness function down into its components:
1/(1 + distance-travelled)
1/(1 + distance-to-target)
1/(1 + number-collisions)
sensor-average
- not sure what this is?
Let's suppose distance-to-target
is 10. The first three components are 1 + 1/10 + 1
. If you move one-step closer to the target without colliding with anything, the first three components are 1/2 + 1/9 + 1
which is less than before. That is obviously not the feedback you want to be giving for making a correct move.
For this task, I think you want distance-to-target
to dominate the fitness, i.e. if you get closer to the target, regardless of the other factors, fitness should increase.
I don't have an ideal fitness function off the top of my head, but I will give it some thought.
Assuming equivalent distance-to-taret
's, distance-travelled
should be the next most important factor. Assuming two results get to 5
for distance-to-target
, the one that travelled less distance should score higher.
number-collision
needs to be relative to the distance-travelled
, otherwise, you can minimize number-collisions
by not traveling.
The idea is that you need to work through the details of the fitness function and make sure that it is always providing the correct feedback. This is not as easy as it sounds since most fitness functions have several variables.
If there is a pernicious solution that finds a local maximum in the fitness function without actually solving the problem, the algorithm will probably find it.