2
\$\begingroup\$

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;
        }
    }
}

return totalDistance + totalWallsCollision;

Thanks for your help.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

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();
}

return totalDistance + totalWallsCollision + 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.

\$\endgroup\$
4
  • \$\begingroup\$ 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. \$\endgroup\$
    – Vodemki
    Dec 12, 2012 at 18:05
  • \$\begingroup\$ 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. \$\endgroup\$
    – House
    Dec 12, 2012 at 18:19
  • \$\begingroup\$ Thanks. My agent has a velocity which is a Vector2D, is there a way to get the acceleration with that ? \$\endgroup\$
    – Vodemki
    Dec 12, 2012 at 18:28
  • \$\begingroup\$ There was recently a question that will help you: How can I derive force vectors from velocity vectors \$\endgroup\$
    – House
    Dec 12, 2012 at 18:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .