void mpq_ILLutil_EGlpNum_rselect (int *arr, int l, int r, int m, mpq_t * coord, ILLrandstate * rstate) { mpq_t *samplevals = mpq_EGlpNumAllocArray (mpq_NSAMPLES); int i; int st, en; int n; arr += l; n = r - l + 1; m -= l; while (n > mpq_SORTSIZE) { for (i = 0; i < mpq_NSAMPLES; i++) { mpq_EGlpNumCopy (samplevals[i], coord[arr[ILLutil_lprand (rstate) % n]]); } mpq_select_EGlpNum_sort_dsample (samplevals, mpq_NSAMPLES); mpq_select_EGlpNum_split (arr, n, &(samplevals[(mpq_NSAMPLES - 1) / 2]), &st, &en, coord); if (st > m) { n = st; } else if (en <= m) { arr += en; n -= en; m -= en; } else { return; } } mpq_select_EGlpNum_sort (arr, n, coord); mpq_EGlpNumFreeArray (samplevals); return; }
/* ========================================================================= */ int main (int ac, char **av) { int rval = 0, status = 0; mpq_QSdata *p_mpq = 0; QSbasis *basis = 0; ILLutil_timer timer_solve; ILLutil_timer timer_read; int ftype = 0; /* 0 mps, 1 lp */ mpq_t *y_mpq = 0, *x_mpq = 0; QSopt_ex_version(); QSexactStart(); /* parse arguments and initialize EGlpNum related things */ rval = parseargs (ac, av); QSexact_set_precision (precision); if (rval) goto CLEANUP; if (writebasis) { basis = EGsMalloc (QSbasis, 1); memset (basis, 0, sizeof (QSbasis)); } /* just for the bell's and wistle */ if (showversion) { char *buf = 0; buf = mpq_QSversion (); if (buf == 0) { ILL_CLEANUP; } else { printf ("%s\n", buf); mpq_QSfree ((void *) buf); } } /* get the file type */ if (lpfile) ftype = 1; else get_ftype (fname, &ftype); /* read the mpq problem */ ILLutil_init_timer (&timer_read, "SOLVER_READ_MPQ"); ILLutil_start_timer (&timer_read); if (ftype == 1) { p_mpq = mpq_QSread_prob ((const char *) fname, "LP"); if (p_mpq == 0) { fprintf (stderr, "Could not read lp file.\n"); rval = 1; ILL_CLEANUP_IF (rval); } } else { p_mpq = mpq_QSread_prob ((const char *) fname, "MPS"); if (p_mpq == 0) { fprintf (stderr, "Could not read mps file.\n"); rval = 1; ILL_CLEANUP_IF (rval); } } /* and get the basis if needed */ if (readbasis) { rval = mpq_QSread_and_load_basis (p_mpq, (const char *) readbasis); ILL_CLEANUP_IF (rval); if (basis) mpq_QSfree_basis (basis); basis = mpq_QSget_basis (p_mpq); } ILLutil_stop_timer (&timer_read, 1); /* set the readed flags */ rval = mpq_QSset_param (p_mpq, QS_PARAM_SIMPLEX_DISPLAY, 1) || mpq_QSset_param (p_mpq, QS_PARAM_PRIMAL_PRICING, pstrategy) || mpq_QSset_param (p_mpq, QS_PARAM_DUAL_PRICING, dstrategy) || mpq_QSset_param (p_mpq, QS_PARAM_SIMPLEX_SCALING, usescaling); ILL_CLEANUP_IF (rval); if (printsol) { x_mpq = mpq_EGlpNumAllocArray (p_mpq->qslp->ncols); y_mpq = mpq_EGlpNumAllocArray (p_mpq->qslp->nrows); } ILLutil_init_timer (&timer_solve, "SOLVER"); ILLutil_start_timer (&timer_solve); rval = QSexact_solver (p_mpq, x_mpq, y_mpq, basis, simplexalgo, &status); ILL_CLEANUP_IF (rval); ILLutil_stop_timer (&timer_solve, 1); if (printsol) { char out_f_name[1024]; EGioFile_t *out_f; sprintf (out_f_name, "%s", solname); out_f = EGioOpen (out_f_name, "w"); switch (status) { case QS_LP_OPTIMAL: EGioPrintf (out_f, "status = OPTIMAL\n"); rval = QSexact_print_sol (p_mpq, out_f); CHECKRVALG(rval,CLEANUP); break; case QS_LP_INFEASIBLE: EGioPrintf (out_f, "status = INFEASIBLE\n"); break; case QS_LP_UNBOUNDED: EGioPrintf (out_f, "status = UNBOUNDED\n"); break; default: EGioPrintf (out_f, "status = UNDEFINED\n"); break; } EGioClose (out_f); } /* ending */ CLEANUP: EGfree(solname); mpq_EGlpNumFreeArray (x_mpq); mpq_EGlpNumFreeArray (y_mpq); /* free the last allocated basis, and if we wanted to save it, do so */ if (basis) { if (writebasis) rval = mpq_QSwrite_basis (p_mpq, 0, writebasis); } mpq_QSfree_basis (basis); mpq_QSfree_prob (p_mpq); QSexactClear(); return rval; /* main return */ }