# Steering evaluate fitness

I've made a simple game with a steering model that manage a crowd of agents. I use an genetic algorithm to find the best parameters to use in my system but I need to determine a fitness for each simulation. I know it's something like that:

number of collisions * time to reach goal * effort


But I don't know how to calculate the effort, is there a special way to do that ?

Here is what I've done so far:

// Evaluate the distance from agents to goal
Real totalDistance(0.0);
for (unsigned i=0; i<_agents.size(); i++)
{
totalDistance += _agents[i]->position().distance(_agents[i]->_goal->position());
}

Real totalWallsCollision(0.0);
for (unsigned i=0; i<_agents.size(); i++)
{
for (unsigned j=0; j<walls.size(); j++)
{
if ( walls[j]->inside(_agents[i]->position()) )
{
totalCollision += 1.0;
}
}
}



Effort will be specific to your simulation. You could do something like the sum of the distance each agent traveled. Or the sum of all the direction changes each agent had to make. It depends on what your definition of fitness is.

For either of the two above, you can just keep a running total for each agent, then add them all up, just as you do for distance:

Real totalEffort(0.0)
for (unsigned i=0; i<_agents.size(); i++)
{
totalEffort+= _agents[i]->totalEffort();
}


You could also try keeping a running total of work, so each step of your simulation, calculate aceleration * mass * distanceTraveled. Where distanceTraveled is the distance traveled since the last update. This will give you the total work (effort) that the agent exerted.
• Thanks I already made that but it's not really what I expect. I've found a way to calculate the effort but I don't understand it correctly. It's effort = mass * integral( es + ew * |v|^2 dt ) where es = 2.23 and ew = 1.26 for a "normal" human walking. I don't know how to calculate this integral between 0 and my simulation time with the given speed v. When am I supposed to calculate the speed value because I only know the simulation time when it ends. Thanks. – Vodemki Dec 12 '12 at 18:05
• The speed variable would be calculated per step of your simulation. You may just want to sum mass * acceleration or the force applied on each step. The es and ew are not really important unless you're comparing your results to other simulations that use those values. If you're just comparing to previous results in your own simulation, you shouldn't need them. – MichaelHouse Dec 12 '12 at 18:19