Esempio n. 1
0
int main(int argc, char** argv)
{
    Timer mainTimer(Timer::Mode::Single);
	mainTimer.Start();
    
    int population, generation, elite, numberOfThreads;
    char *imageFile;
    if(argc != 6)
    {
        printf("Wrong number of arguments, correct number is: 1 population, 2 generation, 3 elite, 4 image file\n");
        return 0;
    }

    population = atoi(argv[1]);
    generation = atoi(argv[2]);
    elite = atoi(argv[3]);
    imageFile = argv[4];
    numberOfThreads = atoi(argv[5]);

    GeneticAlgorithm *geneticAlgorithm = new GeneticAlgorithm(population, generation, elite, imageFile, numberOfThreads);
    geneticAlgorithm->Calculate();
    delete geneticAlgorithm;
    
    mainTimer.Stop();
    printf("%lu,", mainTimer.Get());

    return 0;
}
Esempio n. 2
0
void Render::updateGraph() {
    GeneticAlgorithm *algorithm = world->getAlgorithm();
    int count = algorithm->getGenerationNum();
    if (!count)
        return;
    if (avgScore) {
        delete []avgScore;
        delete []maxScore;
    }
    int width = this->width() - 400;
    int height = 200;
    float dx = float(width)/count;
    float max = algorithm->getMaxScore(count);
    if (max < 1)
        max = 1;
    count++;
    avgScore = new float[count*2];
    maxScore = new float[count*2];
    for (int i = 0; i < count; i++) {
        avgScore[i*2] = 200 + i*dx;
        avgScore[i*2 + 1] = 230 - height*(algorithm->getAvgScore(i)/max);
        maxScore[i*2] = 200 + i*dx;
        maxScore[i*2 + 1] = 230 - height*(algorithm->getMaxScore(i)/max);
    }
}
Esempio n. 3
0
int main (int argc, char * argv[])
{
    if (argc < 2)
    {
        showUsage ();
        return 0;
    }

    if (string (argv[1]) == "-l")
    {
        unsigned int nof_beams = 0;
        if (argc < 3)
        {
            showUsage ();
            return 0;
        }
        else
        {
            nof_beams = atoi (argv[2]);
        }
        LocalBeam hc (nof_beams);
        LBMultiplier * multiplier = hc.bestMultiplier ();
        LBMultiplier * solution;
        solution = multiplier;

        cout << "Solution: " << endl;
        cout << solution->toString () << endl;
        set<pair<unsigned int, unsigned int> > correct_cases = 
                solution->getCorrectAnswers ();

        for (set<pair<unsigned int, unsigned int> >::iterator it = correct_cases.begin ();
                it != correct_cases.end (); ++it)
            cout << it->first << " x " << it->second << endl;

        
    }

    else if (string (argv[1]) == "-g")
    {
        GeneticAlgorithm ga (300);
        GAMultiplier * multiplier = ga.bestMultiplier ();
        GAMultiplier * solution;
        solution = multiplier;

        cout << "Solution: " << endl;
        cout << solution->toString () << endl;
        set<pair<unsigned int, unsigned int> > correct_cases = 
                solution->getCorrectAnswers ();

        for (set<pair<unsigned int, unsigned int> >::iterator it = correct_cases.begin ();
                it != correct_cases.end (); ++it)
            cout << it->first << " x " << it->second << endl;

        delete solution;
    }


    return 0;
}
Esempio n. 4
0
int main() 
{
	GeneticAlgorithm ga;
	ga.run();
	bool pause;
	cin >> pause;
	return 0;
}
void tryReadFremExistMusicFile(const string& music_file_name)
{
    readFromFile(music_file_name);
    Main_Genetic_Algorithm.setMaxGeneration(Max_Generation);
    Main_Genetic_Algorithm.setCrossoverRate(Crossover_Rate);
    Main_Genetic_Algorithm.setMutationRate(Mutation_Rate);
    Main_Genetic_Algorithm.setIndexElitismIndividual(Index_Elitism_Individual);
}
Esempio n. 6
0
void GeneticAlgorithmTest::test_from_XML(void)
{
    message += "test_from_XML\n";

    GeneticAlgorithm ga;

    tinyxml2::XMLDocument* document = ga.to_XML();
    ga.from_XML(*document);

    delete document;
}
Esempio n. 7
0
void GeneticAlgorithmTest::test_to_XML(void)
{
    message += "test_to_XML\n";

    GeneticAlgorithm ga;

    tinyxml2::XMLDocument* document = ga.to_XML();
    assert_true(document != NULL, LOG);

    delete document;
}
Esempio n. 8
0
void Render::createCarCallList() {
    GeneticAlgorithm *algorithm = world->getAlgorithm();
    unsigned int oldCallListNubmer = algorithm->getCarCallListNuber();
    if (oldCallListNubmer)
        glDeleteLists(oldCallListNubmer, 1);
    unsigned int listNubmer = glGenLists(1);
    algorithm->setCarCallList(listNubmer);
    glNewList(listNubmer, GL_COMPILE);
    drawCar();
    glEndList();
}
Esempio n. 9
0
int main (void)
{	
	ShootingField myShooter;
	GeneticAlgorithm myPopulation;

	int targetX; 
	int targetY;

	myShooter.clearField();
	
	myPopulation.runGeneticAlgo(myShooter.myTarget->TargetLocX, myShooter.myTarget->TargetLocY);

	return 0;
	
}
void main()
{ // Creates the algorithm object, initialise the methods to be used this run
  // of the genetic algorithm then call the main running of the genetic
  // algorithm loop

  GeneticAlgorithm theGA;                       // Create algorithm object
  bool isSuccess = true;                        // Algorithm can solve

  theGA.setup(&isSuccess);                      // Read algorithms settings

  if (isSuccess == true)
  { // If everything loaded fine or user wants to use defaults, run algorithm
    theGA.runGA();                                
  }

} // main()
int main(int argc, char *argv[])
{
    const string music_file_name = "Music";
    readMusicFileOrNewAlgorithm(music_file_name);
    Main_Genetic_Algorithm.run();
    outputToFile(music_file_name);
    writeToPy();
    return EXIT_SUCCESS;
}
Esempio n. 12
0
void Render::drawGraph() {
    GeneticAlgorithm *algorithm = world->getAlgorithm();
    int count = algorithm->getGenerationNum();
    if (!count)
        return;
    if (genrationNum != count) {
        genrationNum = count;
        updateGraph();
    }
    count++;
    glLineWidth(2);
    qglColor(Qt::black);
    glVertexPointer(2, GL_FLOAT, 0, avgScore);
    glEnableClientState(GL_VERTEX_ARRAY);
    glDrawArrays(GL_LINE_STRIP, 0, count);
    qglColor(Qt::red);
    glVertexPointer(2, GL_FLOAT, 0, maxScore);
    glDrawArrays(GL_LINE_STRIP, 0, count);
    glDisableClientState(GL_VERTEX_ARRAY);
    glLineWidth(1);
}
Esempio n. 13
0
void Render::drawTable() {
    int stepY = qMin((height() - 1)/33, 14);
    qglColor(QColor(255, 255, 200, 192));
    glBegin(GL_QUADS);
        glVertex2f(5, 1);
        glVertex2f(135, 1);
        glVertex2f(135, 33*stepY);
        glVertex2f(5, 33*stepY);
    glEnd();
    qglColor(Qt::gray);
    glVertexPointer(2, GL_FLOAT, 0, tableBoard);
    glEnableClientState(GL_VERTEX_ARRAY);
    glDrawArrays(GL_LINES, 0, 76);
    glDisableClientState(GL_VERTEX_ARRAY);
    qglColor(Qt::black);
    font.setPixelSize(12);
    QFontMetrics fm(font);
    int y = 2 + fm.ascent();
    renderText(15, y, "#", font);
    renderText(40, y, "Score", font);
    renderText(90, y, "Time", font);
    y += stepY;
    GeneticAlgorithm *algorithm = world->getAlgorithm();
    for (int i = 0; i < 32; i++) {
        qglColor(Qt::black);
        if (!algorithm->getCarNum() && algorithm->getGenerationNum()) {
            switch (algorithm->getOffspringsCount(i)) {
            case 0: qglColor(Qt::red);
                break;
            case 1: qglColor(Qt::black);
                break;
            case 2: qglColor(Qt::darkGreen);
                break;
            }
        }
        renderText(15, y + i*stepY, QString::number(i), font);
        float score = algorithm->getScore(i);
        if (score >= 0) {
            renderText(40, y + i*stepY, QString::number(score, '0', 1), font);
            int ss = algorithm->getTime(i);
            QTime time(0, ss/60, ss%60);
            renderText(90, y + i*stepY, time.toString("m:ss"), font);
        }
    }
}
int main( int argc, char ** argv ) {

    std::string *filename = NULL;
    int times = 0, cost = 0, innerTimes = 0;
    bool mazeValid = false;
    FileHandler *file = NULL;
    Maze *maze = new Maze( ROWS, COLS );
    GeneticAlgorithm *algorithm = new GeneticAlgorithm( maze );
    Search *search = new Search( maze );
    Agent *agent = new Agent( maze );

    if( argc == 2 ) {
        filename = new std::string( argv[1] );
    } else {
        filename = new std::string( "maze.txt" );
    }

    algorithm->setMinIterations( MIN_ITERATIONS );
    algorithm->setMutationRate( MUTATION_RATE );
    algorithm->setCrossOverRate( CROSS_OVER_RATE );

    maze->setRandomRate( RANDOM_RATE );
    maze->generateFirstPopulation();

    do {
        times++;
        algorithm->run();

        mazeValid = maze->searchDoors();
        // Se ele nao tem portas suficientes para testar
        // Executa o A.G denovo
        if( ! mazeValid ) {
            continue;
        }

        while( ( mazeValid = maze->selectDoors( MIN_COST, MAX_COST ) ) ) {

            // Se a menor distancia entre a entrada e saida for maior
            // que o MAX_COST, entao nao ha caminho valido
            if( ! maze->validDistance( MIN_COST, MAX_COST ) ) {
                continue;
            }

            cost = search->hasSolution( true ); // Usa o algoritmo A*, mais rapido a convergencia...
            if( cost >= MIN_COST && cost <= MAX_COST ) {
                break;
            }
            innerTimes++;
        }
        if( times % 10 == 0 ) {
            std::cout << times << ": " << DataNode::ctor << ", " << DataNode::dtor << std::endl;
        }

    } while( ! mazeValid );

    agent->run();

    try {
        file = new FileHandler( filename->c_str() );
        file->printMaze( maze );
        std::cout << "Maze dump in " << *filename << std::endl;
    } catch( int e ) {
        std::cout << file->getErrorMessage();
    }

    delete agent;
    delete search;
    delete maze;
    delete filename;
    delete algorithm;
    delete file;

    return 0;
}
Esempio n. 15
0
/**
 * Entry point for the program.
 */
int main(int argc, char **argv) {
	GeneticAlgorithm ga;
	double xs[N];
	double mutationRate, crossoverProbability, randomSeed, faithDegree;
	double bounds[N][2];
	int maxGenerations, populationSize;
	
	printf("Population size: ");
	scanf("%d", &populationSize);
	printf("Maximum number of generations: ");
	scanf("%d", &maxGenerations);
	printf("Mutation rate (0..1): ");
	scanf("%lf", &mutationRate);
	printf("Crossover probability (0..1): ");
	scanf("%lf", &crossoverProbability);
	printf("Faith degree (0..1): ");
	scanf("%lf", &faithDegree);
	printf("Random seed: ");
	scanf("%lf", &randomSeed);
	
#ifdef F1
	for (int i = 0; i < N; i++) {
		bounds[i][0] = 0;
		bounds[i][1] = 10;
	}
#else
#ifdef F2
	bounds[0][0] = 0;
	bounds[0][1] = 1200;
	bounds[1][0] = 0;
	bounds[1][1] = 1200;
	bounds[2][0] = -0.55;
	bounds[2][1] = 0.55;
	bounds[3][0] = -0.55;
	bounds[3][1] = 0.55;
#else
#ifdef F3
	for (int i = 0; i < 2; i++) {
		bounds[i][0] = -2.3;
		bounds[i][1] = 2.3;
	}
	for (int i = 2; i < N; i++) {
		bounds[i][0] = -3.2;
		bounds[i][1] = 3.2;
	}
#endif
#endif
#endif
	
	// Solve problem
	ga.setCrossoverProbability(crossoverProbability);
	ga.setMutationProbability(mutationRate);
	ga.setElitism(true);
#ifdef F1
	ga.setMinimizer(false);
#else
	ga.setMinimizer(true);
#endif
	ga.setFaithDegree(faithDegree);
	ga.setRepresentationType(RepresentationType::REAL_REPRESENTATION);
	ga.setSelectionType(SelectionType::BOLTZMANN_SELECTION);
	ga.setCrossoverType(CrossoverType::SIMULATED_BINARY_CROSSOVER);
	ga.setMutationType(MutationType::PARAMETER_BASED_MUTATION);
	ga.solve(xs, N, populationSize, bounds, NULL, maxGenerations, randomSeed, f, g, NG, h, NH);
	double fxs = f(xs);
	
	printf("x* = (%.10f", xs[0]);
	for (int i = 1; i < N; i++)
		printf(", %.10f", xs[i]);
	
	printf(")\nf(x*) = %.10f\n", fxs);
	
	return EXIT_SUCCESS;
}
int main(int argc, char* argv[])
{
srand (time(NULL));
SequenceDiagram seqD("C:/Users/Abhinav/Desktop/BTP/Model Based Testing/test.xml");
//seqD.display();

// Generate List of conditions

for(map<string, CombinedFragment*>::iterator i = Message_List.begin(); i!=Message_List.end(); i++)
{
    if(i->second){
        string id = i->second->getID();
        if((!Num_Part[id]) || Num_Part[id] < Partitions[i->first] )
            Num_Part[id] = Partitions[i->first];
    }
}

for(map<string,int>::iterator i =Num_Part.begin(); i!=Num_Part.end();i++)
    for(int j =1; j<=i->second;j++)
    {
        ostringstream temp;
        temp<<j;
        SeqD_conditions.push_back(i->first+(temp.str()));
    }

// Condition Vector Generated


/*for(unsigned int i =0; i<SeqD_conditions.size();i++)
    cout<<SeqD_conditions[i]<<endl;
*/

// Create List of Test Sequences
SequenceDiagramTester sdt(seqD);
vector<TestSequence> TSList =sdt.generate();
sort(TSList.begin(), TSList.end());
for(unsigned int i =0; i<TSList.size(); i++)
{
    TSList[i].evalConditions();
    TSList[i].setNum(i);
}
//Test Sequence List created

/*
Chromosome C;
C.generate(TSList,2);
cout<<"     "<<C.getWeight()<<"    "<<C.getFitness()<<"  "<<C.getMessageCount()<<endl<<endl;;
*/


/*map<string,int> t = C.getConditionHash();

for(map<string,int>::iterator i =t.begin(); i!=t.end(); i++)
    cout<<i->first<<endl;*/
/*for(unsigned int i =0; i<TSList.size(); i++)
{
    cout<<"TS : "<<TSList[i].getPriority()<<"   ";
    vector<Message> tt = TSList[i].getTestSequence();
    for(unsigned j=0; j<tt.size(); j++)
        cout<<tt[j].getName()<<"  ";
    cout<<endl;
 }*/
/*
 for(unsigned int i =0; i<temp.size(); i++)
{
    cout<<"TS-"<<temp[i].getNum()<<" : "<<temp[i].getPriority()<<"  ";
    vector<Message> tt = temp[i].getTestSequence();
    for(unsigned j=0; j<tt.size(); j++)
        cout<<tt[j].getName()<<"  ";
    cout<<endl;
 }
*/


/*ChromosomeBuilder C;
C.generate(TSList,5);
vector<Chromosome> lis = C.getPopulation();
for(unsigned s = 0; s<2; s++)
{
        cout<<"     "<<lis[s].getCount()<<"    "<<lis[s].getFitness()<<endl<<endl;;
    vector<TestSequence> temp =lis[s].getSequence();
     for(unsigned int i =0; i<temp.size(); i++)
{
    cout<<"TS-"<<temp[i].getNum()<<" : "<<temp[i].getPriority()<<"  ";
    vector<Message> tt = temp[i].getTestSequence();
    for(unsigned j=0; j<tt.size(); j++)
        cout<<tt[j].getName()<<"  ";
    cout<<endl;
 }
}

cout<<endl<<endl<<"Genetic Algo "<<endl;
GeneticAlgorithm GA;
vector<Chromosome> t =GA.crossover(lis[0],lis[1]);
sort(t.begin(),t.end());
 for(unsigned s = 0; s<t.size(); s++)
{
        cout<<"     "<<t[s].getCount()<<"    "<<t[s].getFitness()<<endl<<endl;;
    vector<TestSequence> temp =t[s].getSequence();
     for(unsigned int i =0; i<temp.size(); i++)
{
    cout<<"TS-"<<temp[i].getNum()<<" : "<<temp[i].getPriority()<<"  ";
    vector<Message> tt = temp[i].getTestSequence();
    for(unsigned j=0; j<tt.size(); j++)
        cout<<tt[j].getName()<<"  ";
    cout<<endl;
 }
}

t =GA.mutation(t);
 for(unsigned s = 0; s<t.size(); s++)
{
        cout<<"     "<<t[s].getCount()<<"    "<<t[s].getFitness()<<endl<<endl;;
    vector<TestSequence> temp =t[s].getSequence();
     for(unsigned int i =0; i<temp.size(); i++)
{
    cout<<"TS-"<<temp[i].getNum()<<" : "<<temp[i].getPriority()<<"  ";
    vector<Message> tt = temp[i].getTestSequence();
    for(unsigned j=0; j<tt.size(); j++)
        cout<<tt[j].getName()<<"  ";
    cout<<endl;
 }
}*/

GeneticAlgorithm GA;
GA.generate(TSList,5);
return 0;
}