static int minimize() { int i, ipivot, jpivot; mpfr_t t, u; mpfr_inits(t, u, (mpfr_ptr)0); for (;;) { for (jpivot = 1; jpivot <= jmax; jpivot++) { if (row[jpivot] == 0) { tableau(pivotcolumn[0], 0, jpivot); if (mpfr_cmp(pivotcolumn[0], minuseps) < 0) break; } } if (jpivot > jmax) { mpfr_clears(t, u, (mpfr_ptr)0); return 1; } mpfr_set(u, large, GMP_RNDN); ipivot = 0; for (i = 1; i <= m; i++) { tableau(pivotcolumn[i], i, jpivot); if (mpfr_cmp(pivotcolumn[i], eps) > 0) { tableau(t, i, 0); mpfr_div(t, t, pivotcolumn[i], GMP_RNDN); if (mpfr_cmp(t, u) < 0) { ipivot = i; mpfr_set(u, t, GMP_RNDN); } } } if (ipivot == 0) { mpfr_clears(t, u, (mpfr_ptr)0); return 0; // the objective function can be minimized to -infinite } pivot(ipivot, jpivot); } }
int maps(SDL_Surface *ecran, int premiere_fois) { SDL_Surface *tileset, *menu_jeu; SDL_Rect recup [NB_TILES_HAUTEUR] [NB_TILES_LARGEUR] = {0}; SDL_Rect carte[NB_TILES_HAUTEUR][NB_TILES_LARGEUR] = {0}; tileset = IMG_Load("wastelandtiles.png"); menu_jeu = IMG_Load("menu_jeu.png"); if (premiere_fois) { SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0)); } tableau(ecran, tileset); menuJeu(ecran, menu_jeu); SDL_Flip (ecran); SDL_FreeSurface(tileset); SDL_FreeSurface(menu_jeu); return 0; }
static int phase1() { int i, j; mpfr_t u; mpfr_zinit(u); jmax = n3; for (i = 0; i <= m; i++) { if (col[i] > n2) mpfr_set_d(q[0][i], -1, GMP_RNDN); } minimize(); tableau(u, 0, 0); if (mpfr_cmp(u, minuseps) < 0) { mpfr_clear(u); return 0; } for (i = 1; i <= m; i++) { if (col[i] > n2) { col[i] = -1; } } mpfr_set_d(q[0][0], 1, GMP_RNDN); for (j = 1; j <= m; j++) mpfr_set_d(q[0][j], 0, GMP_RNDN); for (i = 1; i <= m; i++) { if ((j = col[i]) > 0 && j <= n && mpfr_cmp_d(c[j], 0) != 0) { mpfr_set(u, c[j], GMP_RNDN); for (j = 1; j <= m; j++) { mpfr_fms(q[0][j], q[i][j], u, q[0][j], GMP_RNDN); mpfr_neg(q[0][j], q[0][j], GMP_RNDN); } } } mpfr_clear(u); return 1; }
int main() { tableau(); return (0); }
int solve_fr(mpfr_t *result, int n0, int m0, mpfr_t **a0, int *ineq0, mpfr_t *c0) { int i,j; m = m0; // number of inequations n = n0+1; // number of variables init(n, m); mpfr_t csum; mpfr_zinit(csum); for(j=0;j<n0+1;j++) { mpfr_set(c[j], c0[j], GMP_RNDN); } for(j=1;j<n0+1;j++) { mpfr_add(csum, csum, c0[j], GMP_RNDN); } mpfr_set(c[n], csum, GMP_RNDN); mpfr_neg(c[n], c[n], GMP_RNDN); for(i=0;i<m;i++) { mpfr_set_d(csum, 0, GMP_RNDN); for(j=0;j<n0+1;j++) mpfr_set(a[i+1][j], a0[i][j], GMP_RNDN); mpfr_neg(a[i+1][0], a[i+1][0], GMP_RNDN); for(j=1;j<n0+1;j++) { mpfr_add(csum, csum, a0[i][j], GMP_RNDN); } mpfr_set(a[i+1][n], csum, GMP_RNDN); mpfr_neg(a[i+1][n], a[i+1][n], GMP_RNDN); inequality[i+1] = ineq0[i]; if (mpfr_cmp_d(a[i+1][0], 0) < 0) { if (inequality[i+1] == GEQ) inequality[i+1] = LEQ; else if (inequality[i+1] == LEQ) inequality[i+1] = GEQ; for (j = 0; j <= n; j++) mpfr_neg(a[i+1][j], a[i+1][j], GMP_RNDN); } else if (mpfr_cmp_d(a[i+1][0], 0) == 0 && inequality[i+1] == GEQ) { inequality[i+1] = LEQ; for (j = 1; j <= n; j++) mpfr_neg(a[i+1][j], a[i+1][j], GMP_RNDN); } } int p1r = 1; prepare(); if (n3 != n2) p1r = phase1(); if (!p1r) { dispose(); return NOT_FEASIBLE; } int b = phase2(); mpfr_t *s = calloc(sizeof(mpfr_t), n); for(j=0;j<n;j++) { mpfr_zinit(s[j]); } for (j = 1; j < n; j++) { if ((i = row[j]) != 0) { tableau(s[j], i, 0); } } mpfr_t cs; mpfr_zinit(cs); if (row[n] != 0) tableau(cs, row[n], 0); for (j = 1; j < n; j++) { mpfr_sub(s[j], s[j], cs, GMP_RNDN); } for(j=0;j<n;j++) { mpfr_set(result[j], s[j], GMP_RNDN); } mpfr_clear(cs); for(j=0;j<n;j++) mpfr_clear(s[j]); free(s); dispose(); return b ? OK : MAXIMIZABLE_TO_INFINITY; }