Example #1
0
void GeneticAlgorithm::run()
{
    initGenerator();

    for (int i = 0; i < GA_MAXITER; i++) {

        QList<double> *points = new QList<double>();
        for( int j = 0; j < GA_POWER; j++){
            points->append(m_genotype.at(j).x);
        }
        emit updatePoints(points);
        reproductionOperator();
        mutationOperator();
        reductionOperator();


        QVector<gene> tmp = m_genotype;
        tmp.removeAll(tmp.first());
        if (tmp.isEmpty()) {
            qDebug() << "EARLY END";
            qDebug() << "Total iterations: " << i;
            break;
        }
    }

    qDebug() << "Result:" << m_genotype.last().fitness;

}