Пример #1
0
void FireflyOptimizator::run() {

    optmized = false;


    beta = 1.0;

    ranks.clear();
    ranks.resize(population.size());
    markers.clear();
    markers.resize(population.size());

    vector<Segmentation>::iterator ffI;
    int idx_ffI =0;


    for (gen = 1; gen <= MaxGenerations; gen++)
    {
        cout<<">>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
        cout<<"GENERATION "<<gen<<endl;

        cout<< "Starting generation. Updating population ";
        startClock();

        startGeneration();

        endClock();
        cout << " - end ( "<<  elapsed_secs<< " sec )" << endl;

        for( ffI = population.begin(),idx_ffI=0; ffI != population.end(); idx_ffI++,ffI++)
        {

            startClock();

            computeFirefly(*ffI,idx_ffI);

            endClock();
            cout << " - end ( "<<  elapsed_secs<< " sec )" << endl;


        }
        cout<< "Generation done. Updating population ";
        startClock();

        updateGeneration();

        endClock();
        cout<< " - OK "<<" ( "<<  elapsed_secs << " sec )" << endl;;


        finishGeneration();

    }

    cout<<"Final result "<<(generationBest.end()-1)->second<<endl;

    optmized = true;

}
Пример #2
0
int main(int argc, char **argv)
{
    long l, limit = 8 * 1024 * 1024, size = 1;
    int zero = open("/dev/zero", O_RDONLY); // file descriptor
    if (argc > 2)
	limit = strtol(argv[2], 0, 0);
    if (argc > 1)
	size = strtol(argv[1], 0, 0);
    char *buffer = (char *)malloc(size * sizeof(char));
    printf("Timing read()\n");
    volatile long x = 0;
    startClock();
    for (l = 0; l < limit; l += size) {
		read(zero,buffer,size);
		x += size;
    }
    endClock();
    if (x != (limit / size) * size)
	printf("Got the wrong answer\n");

    printf("%ld invocations of read(%ld) took: %ld usec\n", (limit / size), size, usecClock());
    
    close(zero);
	free(buffer);
    return 0;
}
Пример #3
0
int main(int argc, char **argv)
{
    long l, limit = LIMIT, size = 1;
    FILE *fnull = fopen("/dev/null", "wb");
    FILE *fzero = fopen("/dev/zero", "rb");
    int null = open("/dev/null", O_WRONLY);
    int zero = open("/dev/zero", O_RDONLY);
    
	if (argc > 2)
		limit = strtol(argv[2], 0, 0);
    if (argc > 1)
		size = strtol(argv[1], 0, 0);
    
	char *buffer = (char *)malloc(size * sizeof(char));
    printf("Timing nothing\n");
    volatile long x = 0;
	
    startClock();
    for (l = 0; l < limit; l += size) {
		x += size;
    }
    endClock();
    
	if (x != (limit / size) * size)
	printf("Got the wrong answer\n");

    printf("%ld invocations of nothing(%ld) took: %ld usec\n", (limit / size), size, usecClock());
    close(null);
    close(zero);
    fclose(fnull);
    fclose(fzero);
	
	free(buffer);
    return 0;
}