Ejemplo n.º 1
0
//void *lazyStart(void *n) {
//	int tid = (uintptr_t) n;
//#ifdef THREAD_ENABLE
//	while (1) {
//#endif
//	QueryDescriptor* queryDescriptor = cir_queue_remove(cirq_busy_docs);
void lazyStart(QueryDescriptor* queryDescriptor) {
#ifdef THREAD_ENABLE
	waitTillFull(&cirq_free_docs);
#endif
	int in, numOfWords = queryDescriptor->numWords, query_id =
			queryDescriptor->queryId;

	for (in = 0; in < numOfWords; in++) {
		SegmentData *sd = &(queryDescriptor->segments[in]);
		sd->parentQuery = queryDescriptor;
		sd->queryId = query_id;
		sd->wordIndex = in;
		cir_queue_remove(&cirq_free_segments);
		cir_queue_insert(&cirq_busy_segments, sd);
#ifndef THREAD_ENABLE
		generate_candidates(0);
#endif
//			generate_candidates(queryDescriptor->words[in],
//					queryDescriptor->words[in + 1] - queryDescriptor->words[in],
//					match_dist, sd);
	}
//		continue;
	return;
//#ifdef THREAD_ENABLE
//}
//#endif
//	return 0;
}
Ejemplo n.º 2
0
static void backtrack(int a[], int k, int n)
{
    int c[CANDIDATES_MAX + 1];
    int nr_candidates;
    int i;

    if (is_a_solution(a, k, n))
        process_solution(a, k);
    else {
        k += 1;
        generate_candidates(a, k, n, c, &nr_candidates);
        for (i = 0; i < nr_candidates; i++) {
            a[k] = c[i];
            backtrack(a, k, n);
            if (finished)
                return;
        }
    }
}
int main(int argc, char **argv)
{
	FILE *input;
	FILE *repeats = 0;
	FILE *output;

	int start_x, end_x, start_y, end_y;

	debug_config(progname);
	get_options(argc, argv, progname);

	unsigned long start_mem, cand_mem, table_mem;

	input = fopen(sequence_filename, "r");
	if(!input) fatal("couldn't open %s: %s\n",sequence_filename,strerror(errno));

	if(repeat_filename) {
		repeats = fopen(repeat_filename, "r");
		if(!repeats) fatal("couldn't open %s: %s\n",repeat_filename,strerror(errno));
	}

	if(output_filename) {
		output = fopen(output_filename, "w");
	} else {
		output = stdout;
	}

	// Data is in the form:
	// >id metadata
	// data
	// >id metadata
	// data
	// >>
	// ...

	set_k(kmer_size);
	set_window_size(window_size);

	// If we only give one file, do an all vs. all
	// on them.
	if(!second_sequence_filename) {
		num_seqs = load_seqs(input);
		start_x = 0;
		end_x = num_seqs;
		start_y = 0;
		end_y = num_seqs;
	}
	// If we had two files, do not compare ones from
	// the same file to each other.
	else {
		FILE *input2 = fopen(second_sequence_filename, "r");
		if(!input2) {
			fprintf(stderr, "Could not open file %s for reading.\n", second_sequence_filename);
			exit(1);
		}
		num_seqs = load_seqs_two_files(input, &end_x, input2, &end_y);
		start_x = 0;
		start_y = end_x;
		debug(D_DEBUG,"First file contains %d sequences, stored from (%d,%d].\n", end_x, start_x, end_x);
		debug(D_DEBUG,"Second file contains %d sequences, stored from (%d,%d].\n", end_y-end_x, start_y, end_y);
	}
	fclose(input);

	debug(D_DEBUG,"Loaded %d sequences\n",num_seqs);

	init_cand_table(num_seqs * 5);
	init_mer_table(num_seqs * 5);

	if(repeats) {
		int repeat_count = init_repeat_mer_table(repeats, 2000000, 0);
		fclose(repeats);
		debug(D_DEBUG,"Loaded %d repeated mers\n", repeat_count);
	}

	if(rectangle_size == -1) {
		// Do get_mem_avail*0.95 to leave some memory for overhead
		rectangle_size = DYNAMIC_RECTANGLE_SIZE(max_mem_kb);
		debug(D_DEBUG,"Mem avail: %lu, rectangle size: %d\n",(unsigned long)MEMORY_FOR_MERS(max_mem_kb), rectangle_size);
	}

	int curr_start_x = start_x;
	int curr_start_y = start_y;

	candidate_t *output_list = 0;
	int num_in_list;

	while(curr_start_y < end_y) {
		while(curr_start_x < end_x) {
			if(start_x == start_y) {
				debug(D_DEBUG,"Loading mer table (%d,%d)\n", curr_rect_x, curr_rect_y);
			} else {
				debug(D_DEBUG,"Loading mer table for [%d,%d) and [%d,%d)\n",curr_start_x, MIN(curr_start_x + rectangle_size, end_x), curr_start_y, MIN(curr_start_y + rectangle_size, end_y));
			}

			start_mem = get_mem_usage();

			load_mer_table_subset(curr_start_x, MIN(curr_start_x + rectangle_size, end_x), curr_start_y, MIN(curr_start_y + rectangle_size, end_y), (curr_start_x == curr_start_y));

			table_mem = get_mem_usage();

			debug(D_DEBUG,"Finished loading, now generating candidates\n");
			debug(D_DEBUG,"Memory used: %lu\n", table_mem - start_mem);

			generate_candidates();
			cand_mem = get_mem_usage();

			debug(D_DEBUG,"Total candidates generated: %llu\n", (long long unsigned int) total_cand);
			debug(D_DEBUG,"Candidate memory used: %lu\n", cand_mem - table_mem);

			output_list = retrieve_candidates(&num_in_list);
			output_candidate_list(output, output_list, num_in_list);
			free(output_list);
			fflush(output);

			debug(D_DEBUG,"Now freeing\n");

			free_cand_table();
			free_mer_table();

			debug(D_DEBUG,"Successfully output and freed!\n");

			curr_rect_x++;
			curr_start_x += rectangle_size;
		}
		curr_rect_y++;
		curr_start_y += rectangle_size;
		curr_rect_x = curr_rect_y;
		if(start_y == 0) {
			curr_start_x = curr_start_y;
		} else {
			curr_start_x = start_x;
		}
	}

	fclose(output);

	return 0;
}
Ejemplo n.º 4
0
Graph* tabu_search(Graph* graph, int tabu_len, int candidates_len, int max_iter, 
        int* colors){
    Graph* best = initial_solution(graph);
    int best_cost = cost(best);

    int new_best_cost = best_cost - 1;
    Graph* s = reduce_color(best, new_best_cost);

    int conflict_c;
    char** conflict_vt = conflict_vertices(s, &conflict_c);

    int tabu_pos = 0;
    tabu_t** tabu_list = (tabu_t**) malloc(sizeof(tabu_t*) * candidates_len 
            * graph->iterator_size);

    int iter = 0;

    while (iter < max_iter){
        Graph** candidates = (Graph**) malloc(sizeof(Graph*) * candidates_len);
        
        if (conflict_c > 0){
            for (int i = 0; i < candidates_len; i++){
                candidates[i] = generate_candidates(s, conflict_vt, conflict_c,
                        tabu_list, &tabu_pos, new_best_cost);
            }

            int conflict_cand_c;
            Graph* best_candidate = get_best_candidate(candidates, candidates_len, 
                    conflict_vt, conflict_c, &conflict_cand_c);

            if (conflict_c > conflict_cand_c){
                free_graph(s);
                free(conflict_vt);
                s = best_candidate;
                conflict_vt = conflict_vertices(s, &conflict_c);
            }
            else if (best_candidate != NULL)
                free_graph(best_candidate);
        }

        if (conflict_c == 0){
            best_cost = new_best_cost;
            free_graph(best);
            best = s;

            new_best_cost = best_cost - 1;
            s = reduce_color(best, new_best_cost);
            free(conflict_vt);
            conflict_vt = conflict_vertices(s, &conflict_c);
        }

        if (tabu_pos > tabu_len)
            update_tabu_list(tabu_list, &tabu_pos, tabu_len);

        free(candidates);
        iter++;
    }

    free(conflict_vt);
    free(tabu_list);
    if (colors != NULL)
        *colors = best_cost;

    return best;
}