Exemplo n.º 1
0
static void sortResults(SWResult* list[], int start, int end) {

    MatcherScore key;
    int frontIdx;
    int backIdx;
    int pivot;

    if (start < end) {

        pivot = (start + end) / 2;
        swapResults(&list[start], &list[pivot]);
        key = swResultGetScore(list[start]);

        frontIdx = start + 1;
        backIdx = end;

        while (frontIdx <= backIdx) {

            while ((frontIdx <= end) && (swResultGetScore(list[frontIdx]) <= key)) {
                frontIdx++;
            }

            while ((backIdx >= start) && (swResultGetScore(list[backIdx]) > key)) {
                backIdx--;
            }

            if (frontIdx < backIdx) {
                swapResults(&list[frontIdx], &list[backIdx]);
            }
        }

        swapResults(&list[start], &list[backIdx]);

        sortResults(list, start, backIdx - 1);
        sortResults(list, backIdx + 1, end);
    }
}
Exemplo n.º 2
0
extern void swGPUParamSearch(Chain* rowChainL, Chain* columnChainL, 
    SWPrefs* swPrefsL) {

    SWResult* swResult = 
        swDataGetResult(swSolveGPU(rowChainL, columnChainL, swPrefsL), 0);

    rowChain = rowChainL;
    columnChain = columnChainL;
    swPrefs = swPrefsL;
    columns = chainGetLength(columnChainL);
    expectedResult = swResultGetScore(swResult);

    srand(time(NULL));

    Cromosome child;

    initPopulation();
    evaluatePopulation();

    int generationIdx;
    int childIdx;

    for (generationIdx = 0; generationIdx < GENERATION_NMR; ++generationIdx) {

        sortCromosomes(population, 0, POPULATION_NMR - 1);

        printf(".............................................\n");
        printf("Generation: %d\n", generationIdx);

        for (childIdx = 0; childIdx < CHILD_NMR; ++childIdx) {

            child = crossover(selection());
            mutation(&child);

            children[childIdx] = child;
        }

        evaluateChildren();

        for (childIdx = 0; childIdx < CHILD_NMR; ++childIdx) {
            population[POPULATION_NMR - childIdx - 1] = children[childIdx];
        }
    }
}
Exemplo n.º 3
0
static void evaluateCromosome(Cromosome* cromosome) {

    swPrefsSetCudaThreads(swPrefs, cromosome->blocks);
    swPrefsSetCudaThreads(swPrefs, cromosome->threads);

    clock_t start = clock();

    SWResult* swResult = 
        swDataGetResult(swSolveGPU(rowChain, columnChain, swPrefs), 0);

    MatcherScore score = swResultGetScore(swResult);

    if(score != expectedResult) {
        printf("error---> %f", (float) score);
    }

    clock_t finish = clock();

    cromosome->fitness = finish - start;

    printf("eval: %ld %d %d\n", 
        cromosome->fitness, cromosome->blocks, cromosome->threads);
}