Пример #1
0
unsigned long long TomKva_v5(char* aname, char* cname, int seconds)
{
    FILE*       afile = fopen(aname, "r");
    FILE*       cfile = fopen(cname, "r");

    fm_count = 0;

    if (afile == NULL)
    {
        fprintf(stderr, "could not open file A\n");
        exit(1);
    }

    if (cfile == NULL)
    {
        fprintf(stderr, "could not open file c\n");
        exit(1);
    }

    _matrix* matA = parseMatrix(afile);
    _vector* vecC = parseVector(cfile);

    fclose(afile);
    fclose(cfile);

    Arena* arena = init_arena_basic(6, 6);

    if (seconds == 0)
    {
        /* Just run once for validation. */

        // Uncomment when your function and variables exist...
        int result = fm_elim(arena, matA->rows, matA->columns, matA->cells, vecC->elements);
        free_up(matA,vecC);
        destroy_arena(arena);
        return result;
        //return 1; // return one, i.e. has a solution for now...
    }

    /* Tell operating system to call function DONE when an ALARM comes. */
    signal(SIGALRM, done);
    alarm(seconds);

    /* Now loop until the alarm comes... */
    proceed = true;
    while (proceed)
    {
        // Uncomment when your function and variables exist...
        // fm_elim(rows, cols, a, c);
        fm_elim(arena, matA->rows, matA->columns, matA->cells, vecC->elements);
        fm_count++;
    }

    // Clean up
    free_up(matA,vecC);
    destroy_arena(arena);

    return fm_count;
}
Пример #2
0
unsigned long long
dt08rf1(char* aname, char* cname, int seconds)
{
	FILE*		afile = fopen(aname, "r");
	FILE*		cfile = fopen(cname, "r");

	fm_count = 0;

	if (afile == NULL) {
		fprintf(stderr, "could not open file A\n");
		exit(1);
	}

	if (cfile == NULL) {
		fprintf(stderr, "could not open file c\n");
		exit(1);
	}
    /*fm_system* system = (fm_system*)malloc(sizeof(fm_system));
    system->rows = parse_files(afile, cfile);
    system->nbr_rows = count_rows(afile);*/
	fm_system* system = parse_files(afile, cfile);
	print_system(system);

    //TODO: move
    f_m_elim(system);
    elim_2(system);

	if (seconds == 0) {
		/* Just run once for validation. */
			
		// Uncomment when your function and variables exist...
		// return fm_elim(rows, cols, a, c);

		fm_elim(NULL, 0);
		return 1; // return one, i.e. has a solution for now...
	}

	/* Tell operating system to call function DONE when an ALARM comes. */
	signal(SIGALRM, done);
	alarm(seconds);

	/* Now loop until the alarm comes... */
	proceed = true;
	while (proceed) {
		// Uncomment when your function and variables exist...
		// fm_elim(rows, cols, a, c);

		fm_elim(NULL, 0);

		fm_count++;
	}

	return fm_count;
}
Пример #3
0
unsigned long long tna11hau_fm(char* aname, char* cname, int seconds)
{
	char helpStr[BUFSIZ], *line;
	int rows, cols, k, n;
	rational *A, *c;

	FILE*		afile = fopen(aname, "r");
	FILE*		cfile = fopen(cname, "r");

	fm_count = 0;

	if (afile == NULL) {
		fprintf(stderr, "could not open file A\n");
		exit(1);
	}

	if (cfile == NULL) {
		fprintf(stderr, "could not open file c\n");
		exit(1);
	}

	// Read the right number of numbers in each row
	if(!fgets(helpStr, BUFSIZ, afile)) {
		fprintf(stderr, "Something is wrong in file A\n");
		exit(1);
	}

	line = helpStr;
	rows = strtol(line, &line, 0);
	cols = strtol(line, &line, 0);
	// Initialize the correct data structure

	A = calloc(rows*cols, sizeof(rational));

	for(k = 0; k < rows; k++) {
		fgets(helpStr, BUFSIZ, afile);
		line = helpStr;
		for (n=0; n < cols; n++) {
			A[k*cols + n].enu = strtol(line, &line, 0);
			A[k*n + n].den = 1;
		}
	}

	if (!fgets(helpStr, BUFSIZ, cfile)) {
		fprintf(stderr, "Something is wrong in file C\n");
		exit(1);
	}

	line = helpStr;

	if (strtol(line, &line, 0) != rows) {
		fprintf(stderr, "A and C files do not match\n");
		exit(1);
	}

	c = calloc(rows, sizeof(rational));

	for (k=0; k < rows; k++) {
		fgets(helpStr, BUFSIZ, cfile);
		line = helpStr;
		c[k].enu = strtol(line, &line, 0);
		c[k].den = 1;
	}

	fclose(afile);
	fclose(cfile);

	if (seconds == 0) {
		/* Just run once for validation. */

		// Uncomment when your function and variables exist...
		return fm_elim(rows, cols, A, c);
	}

	/* Tell operating system to call function DONE when an ALARM comes. */
	signal(SIGALRM, done);
	alarm(seconds);

	/* Now loop until the alarm comes... */
	proceed = true;
	while (proceed) {
		// Uncomment when your function and variables exist...
		fm_elim(rows, cols, A, c);
		fm_count++;
	}
	free(A);
	free(c);
	return fm_count;
}