lis-epfl / robogen

RoboGen - Robot generation through artificial evolution
http://www.robogen.org
GNU General Public License v3.0
27 stars 16 forks source link

Change on fitness function #37

Closed nrontsis closed 11 years ago

nrontsis commented 11 years ago

In our experiments, we observed that the robot is very reluctant on moving forward. So it ends up, moving practically in circles. That's, i think, because if evolution makes some robot move towards the light source for some initial position, that change will generally make the robot go away from it, for the other initial positions. Because we have 3 initial positions, that makes the robot reluctant to changes that make it move straight.

I changed the fitness function, to address the problem, adding a bonus when the robot ends up being in a position that is closer to the light source than the one it started. Basically i replaced the ChasingScenario::getFitness() function to this:

double ChasingScenario::getFitness() {
    // Get ligth source position
    osg::Vec3 lightSourcePos = this->getEnvironment()->getLightSources()[0]->getPosition();

    // Get initial positions 
    boost::shared_ptr<StartPositionConfig> initialPositions=
        this->getRobogenConfig()->getStartingPos();
    const std::vector<osg::Vec2>& inPos = initialPositions->getStartPosition();

    double fitness = 0;
    for (unsigned int i = 0; i < distances_.size(); ++i) {
        osg::Vec3 inPos3d(inPos[i].x(), inPos[i].y(), lightSourcePos.z());

        osg::Vec3 temp = inPos3d - lightSourcePos;
        double initialDistance = temp.length();

        if (initialDistance < distances_[i])
            fitness += distances_[i]/this->getRobogenConfig()->getTimeSteps();
        else {
            fitness += (4*(distances_[i] - initialDistance) + distances_[i])/this->getRobogenConfig()->getTimeSteps();
        }

    }

    // We transform everything into a maximization problem
    return -1*(fitness/distances_.size());
}
amaesani commented 11 years ago

Are you observing any improvement adding this bonus?

tcies commented 11 years ago

Note that distances[i] is the integral over all distances to the light the robot ever has (that's why it's divided by the number of time steps - to yield the average distance). You probably also want to modify afterSimulationStep as I did here: https://github.com/amaesani/robogen-simulator/compare/master...chasingfitnessmod in order to obtain the final position only (you could actually do it smarter than I do as I just overwrite the val on every timestep... not a big penalty though). Else initialDistance < distances[i] will always be true.

cheers

nrontsis commented 11 years ago

Thanks a lot tcies. I will try to use this instead:

        double meanDistance = distances_[i])/this->getRobogenConfig()->getTimeSteps();
        if (initialDistance < meanDistance)
            fitness += meanDistance;
        else {
            fitness += 4*(meanDistance-initialDistance) + meanDistance;
        }

@amaesani Nothing yet, maybe because of the problem tcies indicated. I will know in the morning.