static void luf_adjustsize (void) /* This routine sets the proper working size in the basis. It also checks that the allocated capacity of the basis is sufficient for the current size of the constraint system and increases it if necessary. Parameters: none Returns: undefined */ { double upd_tol,piv_tol,zero_tol,max_gro ; int factor,look,capacity ; # ifndef DYLP_NDEBUG int oldcapacity ; # endif /* Check that we're within the allocated limits, and resize if necessary. Preserve the tolerance settings that we may have tweaked. */ if (dy_sys->concnt > luf_capacity) { factor = luf_basis->hh_max ; upd_tol = luf_basis->upd_tol ; zero_tol = luf_basis->luf->eps_tol ; piv_tol = luf_basis->luf->piv_tol ; look = luf_basis->luf->piv_lim ; max_gro = luf_basis->luf->max_gro ; # ifndef DYLP_NDEBUG oldcapacity = luf_basis->m ; # endif dy_freebasis() ; capacity = (int) (dy_sys->concnt*1.5) ; dy_initbasis(capacity,factor,zero_tol) ; luf_basis->upd_tol = upd_tol ; luf_basis->luf->eps_tol = zero_tol ; luf_basis->luf->piv_tol = piv_tol ; luf_basis->luf->piv_lim = look ; luf_basis->luf->max_gro = max_gro ; # ifndef DYLP_NDEBUG if (dy_opts->print.basis >= 2) { dyio_outfmt(dy_logchn,dy_gtxecho, "\n increased basis capacity from %d to %d constraints", oldcapacity,luf_basis->m) ; dyio_outfmt(dy_logchn,dy_gtxecho,", piv lim %d.",luf_basis->hh_max) ; } # endif } /* Now set the working size. */ luf_basis->m = dy_sys->concnt ; luf_basis->luf->n = dy_sys->concnt ; return ; }
int main (int argc, char **argv) { bool errecho = TRUE ; ioid ttyin,ttyout,outchn ; const char *errmsgpath = DYLP_ERRMSGPATH ; char *errlogpath = NULL ; /* These need to be globals to keep cmdint.c::process_cmds happy. lpopts_struct *main_lpopts ; lptols_struct *main_lptols ; */ consys_struct *main_sys ; lpprob_struct *main_lp ; lpret_enum lpretval ; double z ; int errcnt,cnt ; /* Set this to TRUE if you want to see the solutions for the test lp problems. */ bool dumpsoln = TRUE ; char *rtnnme = argv[0] ; /* dy_basis.c */ extern void dy_initbasis(int concnt, int factor_freq, double zero_tol), dy_freebasis(void) ; /* dytest_problems.c */ extern consys_struct *dytest_exmip1sys(lptols_struct *tols) ; extern consys_struct *dytest_exprimalraysys(lptols_struct *tols) ; extern consys_struct *dytest_exdualraysys(lptols_struct *tols) ; extern consys_struct *dytest_galenetbndssys(lptols_struct *tols) ; extern consys_struct *dytest_galenetleqsys(lptols_struct *tols) ; extern consys_struct *dytest_galenetmixedsys(lptols_struct *tols) ; extern consys_struct *dytest_galenetsys(lptols_struct *tols) ; extern consys_struct *dytest_afirosys(lptols_struct *tols) ; extern consys_struct *dytest_boeing2sys(lptols_struct *tols) ; /* dytest_tableau.c */ extern int dytest_betaj(lpprob_struct *lp, lptols_struct *lptols,lpopts_struct *lpopts) ; extern int dytest_betai(lpprob_struct *lp, lptols_struct *lptols,lpopts_struct *lpopts) ; extern int dytest_abarj(lpprob_struct *lp, lptols_struct *lptols,lpopts_struct *lpopts) ; extern int dytest_abari(lpprob_struct *lp, lptols_struct *lptols,lpopts_struct *lpopts) ; /* dytest_solutions.c */ extern int dytest_rowDuals(lpprob_struct *lp, lptols_struct *lptols,lpopts_struct *lpopts) ; extern int dytest_allDuals(lpprob_struct *lp, lptols_struct *lptols,lpopts_struct *lpopts) ; extern int dytest_colDuals(lpprob_struct *lp, lptols_struct *lptols,lpopts_struct *lpopts) ; extern int dytest_colPrimals(lpprob_struct *lp, lptols_struct *lptols,lpopts_struct *lpopts) ; extern int dytest_rowPrimals(lpprob_struct *lp, lptols_struct *lptols,lpopts_struct *lpopts) ; /* dytest_rays.c */ extern int dytest_primalRays(int *p_numRays,lpprob_struct *lp, lptols_struct *lptols,lpopts_struct *lpopts) ; extern int dytest_dualRays(int *p_numRays,lpprob_struct *lp, lptols_struct *lptols,lpopts_struct *lpopts) ; outchn = IOID_INV ; /* Execute initialization routines for the i/o and error reporting packages. */ errinit(errmsgpath,errlogpath,errecho) ; if (dyio_ioinit() != TRUE) { errmsg(1,rtnnme,__LINE__) ; exit (2) ; } /* Connect ttyout to the standard output. Initialize ttyin, setting the mode to line-oriented. Serious internal confusion if we can't manage these. Set the initial command input channel to stdin. */ ttyout = dyio_openfile("stdout","w") ; if (ttyout == IOID_INV) { errmsg(1,rtnnme,__LINE__) ; exit(3) ; } ttyin = dyio_openfile("stdin","r") ; if (ttyin == IOID_INV) { errmsg(1,rtnnme,__LINE__) ; exit(4) ; } (void) dyio_setmode(ttyin,'l') ; dy_cmdchn = ttyin ; dy_logchn = IOID_NOSTRM ; dy_cmdecho = TRUE ; dy_gtxecho = TRUE ; /* Announce we're running. */ dyio_outfmt(ttyout,dy_gtxecho,"Dylp v%s unit test start.\n",DYLP_VERSION) ; dyio_flushio(ttyout,dy_gtxecho) ; errcnt = 0 ; /* Acquire default option and tolerance structures. Allocate an lpprob_struct to be our top-level handle. */ main_lpopts = NULL ; main_lptols = NULL ; dy_defaults(&main_lpopts,&main_lptols) ; main_lp = (lpprob_struct *) CALLOC(1,sizeof(lpprob_struct)) ; /* Initialise the basis factorisation package with a data structure capable of 50 constraints. The second parameter controls how many basis updates the basis can hold before it requires refactoring. Adding 5 to dylp's refactor interval should give a safety margin. */ dy_initbasis(50,main_lpopts->factor+5,0.0) ; #if RUN_EXMIP1 > 0 /* Load the exmip1 example and see if we can solve it. */ dyio_outfmt(ttyout,dy_gtxecho, "\n\nLoading exmip1 example from static data.\n") ; main_sys = dytest_exmip1sys(main_lptols) ; if (main_sys == NULL) { dyio_outfmt(ttyout,dy_gtxecho, "Failed to load exmip1 constraint system.\n") ; errcnt++ ; } /* Check over the option settings, now that we know how big the constraint system will be. */ else { dy_checkdefaults(main_sys,main_lpopts,main_lptols) ; /* Initialise the main_lp structure to pass the problem in to dylp. * We need to retain the data structures (NOFREE) so that we can consult them when dylp returns. * The phase needs to be dyINV at the start. * We need to specify the constraint system, and its size. * Let dylp work with a partial system and purge at the end. This stresses the routines we're testing; they need to synthesize parts of the values they return. * The remaining options specify an all-logical basis, allow scaling, and force a cold start. */ setflg(main_lp->ctlopts,lpctlNOFREE) ; main_lp->phase = dyINV ; main_lp->consys = main_sys ; main_lp->rowsze = main_sys->rowsze ; main_lp->colsze = main_sys->colsze ; main_lpopts->forcecold = TRUE ; main_lpopts->fullsys = FALSE ; main_lpopts->finpurge.vars = TRUE ; main_lpopts->finpurge.cons = TRUE ; main_lpopts->coldbasis = ibLOGICAL ; main_lpopts->scaling = 0 ; main_lpopts->forcecold = TRUE ; /* main_lpopts->print.major = 1 ; main_lpopts->print.scaling = 1 ; main_lpopts->print.setup = 6 ; main_lpopts->print.crash = 3 ; main_lpopts->print.conmgmt = 3 ; main_lpopts->print.varmgmt = 3 ; main_lpopts->print.soln = 3 ; */ /* Solve. */ dyio_outfmt(ttyout,dy_gtxecho,"Solving exmip1 ... ") ; lpretval = do_lp(main_lp,main_lptols,main_lpopts,1) ; /* And the result is ... */ dyio_outfmt(ttyout,dy_gtxecho,"\n %s, z = %.12f.\n", dy_prtlpret(lpretval),main_lp->obj) ; z = 3.236842105263 ; if (!(fabs(main_lp->obj-z) <= main_lptols->cost)) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: z = %g, expected %g, error %g, tol %g.\n", main_lp->obj,z,fabs(main_lp->obj-z),main_lptols->cost) ; } if (dumpsoln == TRUE) { dy_dumpcompact(dy_logchn,dy_gtxecho,main_lp,FALSE) ; } /* Test the tableau, solution, and ray routines. The tests are predominantly mathematical identities, with a bit of data structure consistency thrown in for good measure. Completely problem-independent. */ errcnt += dytest_betaj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abarj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_betai(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abari(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_allDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colPrimals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowPrimals(main_lp,main_lptols,main_lpopts) ; /* Call dylp to free internal structures, then free main_sys. */ comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; dylp(main_lp,main_lpopts,main_lptols,NULL) ; consys_free(main_sys) ; main_sys = NULL ; main_lp->consys = NULL ; dy_freesoln(main_lp) ; } #endif #if RUN_AFIRO > 0 /* Let's try another. Load and solve afiro. */ dyio_outfmt(ttyout,dy_gtxecho, "\n\nLoading afiro example from static data.\n") ; main_sys = dytest_afirosys(main_lptols) ; if (main_sys == NULL) { dyio_outfmt(ttyout,dy_gtxecho, "Failed to load afiro constraint system.\n") ; errcnt++ ; } else { dy_checkdefaults(main_sys,main_lpopts,main_lptols) ; comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; main_lp->phase = dyINV ; main_lp->consys = main_sys ; main_lp->rowsze = main_sys->rowsze ; main_lp->colsze = main_sys->colsze ; main_lpopts->forcecold = TRUE ; main_lpopts->fullsys = FALSE ; main_lpopts->finpurge.vars = TRUE ; main_lpopts->finpurge.cons = TRUE ; main_lpopts->coldbasis = ibLOGICAL ; main_lpopts->scaling = 2 ; dyio_outfmt(ttyout,dy_gtxecho,"Solving afiro ... ") ; lpretval = do_lp(main_lp,main_lptols,main_lpopts,1) ; dyio_outfmt(ttyout,dy_gtxecho,"\n %s, z = %.12f.\n", dy_prtlpret(lpretval),main_lp->obj) ; z = -464.753142857143 ; if (!(fabs(main_lp->obj-z) <= main_lptols->cost)) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: z = %g, expected %g, error %g, tol %g.\n", main_lp->obj,z,fabs(main_lp->obj-z),main_lptols->cost) ; } if (dumpsoln == TRUE) { dy_dumpcompact(dy_logchn,dy_gtxecho,main_lp,FALSE) ; } errcnt += dytest_betaj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abarj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_betai(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abari(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_allDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colPrimals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowPrimals(main_lp,main_lptols,main_lpopts) ; comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; dylp(main_lp,main_lpopts,main_lptols,NULL) ; consys_free(main_sys) ; main_sys = NULL ; main_lp->consys = NULL ; dy_freesoln(main_lp) ; } #endif #if RUN_BOEING2 > 0 /* Let's try another. Load and solve boeing2. */ dyio_outfmt(ttyout,dy_gtxecho, "\n\nLoading boeing2 example from static data.\n") ; main_sys = dytest_boeing2sys(main_lptols) ; if (main_sys == NULL) { dyio_outfmt(ttyout,dy_gtxecho, "Failed to load boeing2 constraint system.\n") ; errcnt++ ; } else { dy_checkdefaults(main_sys,main_lpopts,main_lptols) ; comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; main_lp->phase = dyINV ; main_lp->consys = main_sys ; main_lp->rowsze = main_sys->rowsze ; main_lp->colsze = main_sys->colsze ; main_lpopts->forcecold = TRUE ; main_lpopts->fullsys = FALSE ; main_lpopts->finpurge.vars = TRUE ; main_lpopts->finpurge.cons = TRUE ; main_lpopts->coldbasis = ibLOGICAL ; main_lpopts->scaling = 2 ; main_lpopts->print.phase2 = 0 ; /* main_lpopts->print.major = 1 ; main_lpopts->print.phase1 = 4 ; main_lpopts->print.dual = 4 ; main_lpopts->print.tableau = 4 ; main_lpopts->print.soln = 3 ; main_lpopts->print.rays = 5 ; */ dyio_outfmt(ttyout,dy_gtxecho,"Solving boeing2 ... ") ; lpretval = do_lp(main_lp,main_lptols,main_lpopts,1) ; dyio_outfmt(ttyout,dy_gtxecho,"\n %s, z = %.12f.\n", dy_prtlpret(lpretval),main_lp->obj) ; z = -315.0187280152 ; if (!(fabs(main_lp->obj-z) <= main_lptols->cost)) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: z = %g, expected %g, error %g, tol %g.\n", main_lp->obj,z,fabs(main_lp->obj-z),main_lptols->cost) ; } if (dumpsoln == TRUE) { dy_dumpcompact(dy_logchn,dy_gtxecho,main_lp,FALSE) ; } errcnt += dytest_betaj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abarj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_betai(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abari(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_allDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colPrimals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowPrimals(main_lp,main_lptols,main_lpopts) ; comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; dylp(main_lp,main_lpopts,main_lptols,NULL) ; consys_free(main_sys) ; main_sys = NULL ; main_lp->consys = NULL ; dy_freesoln(main_lp) ; } #endif #if RUN_EXPRIMALRAY > 0 /* Let's try another. Load and solve exprimalray. The polyhedron for exprimalray is carefully crafted to provide an initial bounded optimum point with two rays that are exposed by the proper change in objective. Force dylp to use the full system for this test and do not allow final purging, lest we miss the point and rays we're aiming for. */ dyio_outfmt(ttyout,dy_gtxecho, "\n\nLoading exprimalray example from static data.\n") ; main_sys = dytest_exprimalraysys(main_lptols) ; if (main_sys == NULL) { dyio_outfmt(ttyout,dy_gtxecho, "Failed to load exprimalray constraint system.\n") ; errcnt++ ; } else { dy_checkdefaults(main_sys,main_lpopts,main_lptols) ; comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; main_lp->phase = dyINV ; main_lp->consys = main_sys ; main_lp->rowsze = main_sys->rowsze ; main_lp->colsze = main_sys->colsze ; main_lpopts->forcecold = TRUE ; main_lpopts->fullsys = TRUE ; main_lpopts->finpurge.vars = FALSE ; main_lpopts->finpurge.cons = FALSE ; main_lpopts->coldbasis = ibLOGICAL ; main_lpopts->scaling = 2 ; dyio_outfmt(ttyout,dy_gtxecho,"Solving exprimalray ... ") ; lpretval = do_lp(main_lp,main_lptols,main_lpopts,1) ; dyio_outfmt(ttyout,dy_gtxecho,"\n %s, z = %.12f.\n", dy_prtlpret(lpretval),main_lp->obj) ; z = -21 ; if (!(fabs(main_lp->obj-z) <= main_lptols->cost)) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: z = %g, expected %g, error %g, tol %g.\n", main_lp->obj,z,fabs(main_lp->obj-z),main_lptols->cost) ; } if (dumpsoln == TRUE) { dy_dumpcompact(dy_logchn,dy_gtxecho,main_lp,FALSE) ; } /* Now tweak the objective to 3x1+x2+x3, giving us two rays. Solve, then test that we have valid primal rays. First ask for just one, then ask for five, expecting two. */ main_sys->obj[1] = -1.0 ; main_sys->obj[2] = -4.0 ; setflg(main_lp->ctlopts,lpctlOBJCHG) ; main_lpopts->forcecold = FALSE ; dyio_outfmt(dy_logchn,dy_gtxecho,"Resolving exprimalray ...") ; lpretval = do_lp(main_lp,main_lptols,main_lpopts,1) ; dyio_outfmt(ttyout,dy_gtxecho,"\n %s, z = %.12f.\n", dy_prtlpret(lpretval),main_lp->obj) ; if (dumpsoln == TRUE) { dy_dumpcompact(dy_logchn,dy_gtxecho,main_lp,FALSE) ; } cnt = 1 ; errcnt += dytest_primalRays(&cnt,main_lp,main_lptols,main_lpopts) ; if (cnt != 1) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: %d primal rays returned, expected %d.\n", cnt,1) ; } cnt = 5 ; errcnt += dytest_primalRays(&cnt,main_lp,main_lptols,main_lpopts) ; if (cnt != 2) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: %d primal rays returned, expected %d.\n", cnt,2) ; } /* Run the remainder of the tests, to make sure they run without error when dylp finishes unbounded. */ errcnt += dytest_betaj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abarj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_betai(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abari(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_allDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colPrimals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowPrimals(main_lp,main_lptols,main_lpopts) ; comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; dylp(main_lp,main_lpopts,main_lptols,NULL) ; consys_free(main_sys) ; main_sys = NULL ; main_lp->consys = NULL ; dy_freesoln(main_lp) ; } #endif #if RUN_EXDUALRAY > 0 /* Let's try another. Load and solve exdualray. Exdualray takes advantage of duality: The dual polyhedron is exactly the primal polyhedron of the previous problem. The symmetry should be clear from the output (objective, dual, and primal values are negated, but otherwise identical) */ dyio_outfmt(ttyout,dy_gtxecho, "\n\nLoading exdualray example from static data.\n") ; main_sys = dytest_exdualraysys(main_lptols) ; if (main_sys == NULL) { dyio_outfmt(ttyout,dy_gtxecho, "Failed to load exdualray constraint system.\n") ; errcnt++ ; } else { dy_checkdefaults(main_sys,main_lpopts,main_lptols) ; comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; main_lp->phase = dyINV ; main_lp->consys = main_sys ; main_lp->rowsze = main_sys->rowsze ; main_lp->colsze = main_sys->colsze ; main_lpopts->forcecold = TRUE ; main_lpopts->fullsys = TRUE ; main_lpopts->finpurge.vars = FALSE ; main_lpopts->finpurge.cons = FALSE ; main_lpopts->coldbasis = ibLOGICAL ; main_lpopts->scaling = 2 ; /* main_lpopts->print.major = 1 ; main_lpopts->print.phase1 = 4 ; main_lpopts->print.phase2 = 4 ; main_lpopts->print.dual = 4 ; main_lpopts->print.tableau = 4 ; main_lpopts->print.soln = 3 ; main_lpopts->print.rays = 5 ; */ dyio_outfmt(ttyout,dy_gtxecho,"Solving exdualray ... ") ; lpretval = do_lp(main_lp,main_lptols,main_lpopts,1) ; dyio_outfmt(ttyout,dy_gtxecho,"\n %s, z = %.12f.\n", dy_prtlpret(lpretval),main_lp->obj) ; z = 21 ; if (!(fabs(main_lp->obj-z) <= main_lptols->cost)) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: z = %g, expected %g, error %g, tol %g.\n", main_lp->obj,z,fabs(main_lp->obj-z),main_lptols->cost) ; } if (dumpsoln == TRUE) { dy_dumpcompact(dy_logchn,dy_gtxecho,main_lp,FALSE) ; } /* Tweak the rhs to (-1)*(-1 -4 1) to produce a pair of rays in the dual. */ main_sys->rhs[2] = 4.0 ; setflg(main_lp->ctlopts,lpctlRHSCHG) ; main_lpopts->forcecold = FALSE ; main_lpopts->print.force = 1 ; dyio_outfmt(dy_logchn,dy_gtxecho,"Resolving exdualray ...") ; lpretval = do_lp(main_lp,main_lptols,main_lpopts,1) ; dyio_outfmt(ttyout,dy_gtxecho,"\n %s, z = %.12f.\n", dy_prtlpret(lpretval),main_lp->obj) ; if (dumpsoln == TRUE) { dy_dumpcompact(dy_logchn,dy_gtxecho,main_lp,FALSE) ; } /* Test that we have valid dual rays. First ask for just one, then ask for five, expecting two. */ errcnt += dytest_rowDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_allDuals(main_lp,main_lptols,main_lpopts) ; cnt = 1 ; errcnt += dytest_dualRays(&cnt,main_lp,main_lptols,main_lpopts) ; if (cnt != 1) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: %d dual rays returned, expected %d.\n", cnt,1) ; } cnt = 5 ; errcnt += dytest_dualRays(&cnt,main_lp,main_lptols,main_lpopts) ; if (cnt != 2) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: %d dual rays returned, expected %d.\n", cnt,2) ; } /* Run the remainder of the tests, to make sure they run without error when dylp finishes infeasible. */ errcnt += dytest_betaj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abarj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_betai(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abari(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colPrimals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowPrimals(main_lp,main_lptols,main_lpopts) ; comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; dylp(main_lp,main_lpopts,main_lptols,NULL) ; consys_free(main_sys) ; main_sys = NULL ; main_lp->consys = NULL ; dy_freesoln(main_lp) ; } #endif #if RUN_GALENETBNDS > 0 /* Now a sequence of three problems based on galenet that really exercise the dual ray code. Galenet is a straightforward primal infeasible / dual unbounded problem. The objective is identically zero, so it's a pure feasibility problem. The objective returned from dylp will be z = 48, the amount of primal infeasibility. The first version is galenetbnds. All equalities from galenet are converted to inequalities, all implicit bounds are converted to explicit bound constraints, and then all >= constraints are converted to <= constraints. This is the simplest possible case for returning dual rays. */ dyio_outfmt(ttyout,dy_gtxecho, "\n\nLoading galenetbnds example from static data.\n") ; main_sys = dytest_galenetbndssys(main_lptols) ; if (main_sys == NULL) { dyio_outfmt(ttyout,dy_gtxecho, "Failed to load galenetbnds constraint system.\n") ; errcnt++ ; } else { dy_checkdefaults(main_sys,main_lpopts,main_lptols) ; comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; main_lp->phase = dyINV ; main_lp->consys = main_sys ; main_lp->rowsze = main_sys->rowsze ; main_lp->colsze = main_sys->colsze ; main_lpopts->forcecold = TRUE ; main_lpopts->fullsys = TRUE ; main_lpopts->finpurge.vars = FALSE ; main_lpopts->finpurge.cons = FALSE ; main_lpopts->coldbasis = ibLOGICAL ; main_lpopts->scaling = 2 ; /* main_lpopts->print.major = 1 ; main_lpopts->print.phase1 = 4 ; main_lpopts->print.phase2 = 4 ; main_lpopts->print.dual = 4 ; main_lpopts->print.tableau = 4 ; main_lpopts->print.soln = 3 ; main_lpopts->print.rays = 5 ; */ dyio_outfmt(ttyout,dy_gtxecho,"Solving galenetbnds ... ") ; lpretval = do_lp(main_lp,main_lptols,main_lpopts,1) ; dyio_outfmt(ttyout,dy_gtxecho,"\n %s, z = %.12f.\n", dy_prtlpret(lpretval),main_lp->obj) ; z = 48.0 ; if (!(fabs(main_lp->obj-z) <= main_lptols->cost)) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: z = %g, expected %g, error %g, tol %g.\n", main_lp->obj,z,fabs(main_lp->obj-z),main_lptols->cost) ; } dumpsoln = TRUE ; if (dumpsoln == TRUE) { dy_dumpcompact(dy_logchn,dy_gtxecho,main_lp,FALSE) ; } /* Test that we have valid dual rays. First ask for just one, then ask for five, expecting three. */ cnt = 1 ; errcnt += dytest_dualRays(&cnt,main_lp,main_lptols,main_lpopts) ; if (cnt != 1) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: %d dual rays returned, expected %d.\n", cnt,1) ; } cnt = 5 ; errcnt += dytest_dualRays(&cnt,main_lp,main_lptols,main_lpopts) ; if (cnt != 3) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: %d dual rays returned, expected %d.\n", cnt,2) ; } /* Run the remainder of the tests, to make sure they run without error when dylp finishes infeasible. */ errcnt += dytest_betaj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abarj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_betai(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abari(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_allDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colPrimals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowPrimals(main_lp,main_lptols,main_lpopts) ; comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; dylp(main_lp,main_lpopts,main_lptols,NULL) ; consys_free(main_sys) ; main_sys = NULL ; main_lp->consys = NULL ; dy_freesoln(main_lp) ; } #endif #if RUN_GALENETLEQ > 0 /* Now load and solve galenetleq --- galenetbnds, but the bound constraints on variables are now handled in the usual manner, as implicit bounds. We'll need the full ray (explicit duals y = c<B>inv(B) as well as duals associated with nonbasic bounded variables) in order to pass the mathematical tests rb < 0, rA > 0. */ dyio_outfmt(ttyout,dy_gtxecho, "\n\nLoading galenetleq example from static data.\n") ; main_sys = dytest_galenetleqsys(main_lptols) ; if (main_sys == NULL) { dyio_outfmt(ttyout,dy_gtxecho, "Failed to load galenetleq constraint system.\n") ; errcnt++ ; } else { dy_checkdefaults(main_sys,main_lpopts,main_lptols) ; comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; main_lp->phase = dyINV ; main_lp->consys = main_sys ; main_lp->rowsze = main_sys->rowsze ; main_lp->colsze = main_sys->colsze ; main_lpopts->forcecold = TRUE ; main_lpopts->fullsys = TRUE ; main_lpopts->finpurge.vars = FALSE ; main_lpopts->finpurge.cons = FALSE ; main_lpopts->coldbasis = ibLOGICAL ; main_lpopts->scaling = 2 ; /* main_lpopts->print.major = 1 ; main_lpopts->print.phase1 = 4 ; main_lpopts->print.phase2 = 4 ; main_lpopts->print.dual = 4 ; main_lpopts->print.tableau = 4 ; main_lpopts->print.soln = 3 ; main_lpopts->print.rays = 5 ; */ dyio_outfmt(ttyout,dy_gtxecho,"Solving galenetleq ... ") ; lpretval = do_lp(main_lp,main_lptols,main_lpopts,1) ; dyio_outfmt(ttyout,dy_gtxecho,"\n %s, z = %.12f.\n", dy_prtlpret(lpretval),main_lp->obj) ; z = 48.0 ; if (!(fabs(main_lp->obj-z) <= main_lptols->cost)) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: z = %g, expected %g, error %g, tol %g.\n", main_lp->obj,z,fabs(main_lp->obj-z),main_lptols->cost) ; } dumpsoln = TRUE ; if (dumpsoln == TRUE) { dy_dumpcompact(dy_logchn,dy_gtxecho,main_lp,FALSE) ; } /* Test that we have valid dual rays. First ask for just one, then ask for five, expecting three. */ cnt = 1 ; errcnt += dytest_dualRays(&cnt,main_lp,main_lptols,main_lpopts) ; if (cnt != 1) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: %d dual rays returned, expected %d.\n", cnt,1) ; } cnt = 5 ; errcnt += dytest_dualRays(&cnt,main_lp,main_lptols,main_lpopts) ; if (cnt != 3) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: %d dual rays returned, expected %d.\n", cnt,2) ; } /* Run the remainder of the tests, to make sure they run without error when dylp finishes infeasible. */ errcnt += dytest_betaj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abarj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_betai(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abari(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_allDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colPrimals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowPrimals(main_lp,main_lptols,main_lpopts) ; comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; dylp(main_lp,main_lpopts,main_lptols,NULL) ; consys_free(main_sys) ; main_sys = NULL ; main_lp->consys = NULL ; dy_freesoln(main_lp) ; } #endif #if RUN_GALENETMIXED > 0 /* Now load and solve galenetmixed --- bound constraints on variables are handled implicitly, and the constraint system is a mix of <= and >= constraints (the equalities are handled as a pair of inequalities). As with galenetleq, we'll need the full ray (explicit duals y = c<B>inv(B) as well as duals associated with nonbasic bounded variables) in order to pass the mathematical tests rb < 0, rA > 0. */ dyio_outfmt(ttyout,dy_gtxecho, "\n\nLoading galenetmixed example from static data.\n") ; main_sys = dytest_galenetmixedsys(main_lptols) ; if (main_sys == NULL) { dyio_outfmt(ttyout,dy_gtxecho, "Failed to load galenetmixed constraint system.\n") ; errcnt++ ; } else { dy_checkdefaults(main_sys,main_lpopts,main_lptols) ; comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; main_lp->phase = dyINV ; main_lp->consys = main_sys ; main_lp->rowsze = main_sys->rowsze ; main_lp->colsze = main_sys->colsze ; main_lpopts->forcecold = TRUE ; main_lpopts->fullsys = TRUE ; main_lpopts->finpurge.vars = FALSE ; main_lpopts->finpurge.cons = FALSE ; main_lpopts->coldbasis = ibLOGICAL ; main_lpopts->scaling = 2 ; /* main_lpopts->print.major = 1 ; main_lpopts->print.phase1 = 4 ; main_lpopts->print.phase2 = 4 ; main_lpopts->print.dual = 4 ; main_lpopts->print.tableau = 4 ; main_lpopts->print.soln = 3 ; main_lpopts->print.rays = 5 ; */ dyio_outfmt(ttyout,dy_gtxecho,"Solving galenetmixed ... ") ; lpretval = do_lp(main_lp,main_lptols,main_lpopts,1) ; dyio_outfmt(ttyout,dy_gtxecho,"\n %s, z = %.12f.\n", dy_prtlpret(lpretval),main_lp->obj) ; z = 48.0 ; if (!(fabs(main_lp->obj-z) <= main_lptols->cost)) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: z = %g, expected %g, error %g, tol %g.\n", main_lp->obj,z,fabs(main_lp->obj-z),main_lptols->cost) ; } dumpsoln = TRUE ; if (dumpsoln == TRUE) { dy_dumpcompact(dy_logchn,dy_gtxecho,main_lp,FALSE) ; } /* Test that we have valid dual rays. First ask for just one, then ask for five, expecting three. */ cnt = 1 ; errcnt += dytest_dualRays(&cnt,main_lp,main_lptols,main_lpopts) ; if (cnt != 1) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: %d dual rays returned, expected %d.\n", cnt,1) ; } cnt = 5 ; errcnt += dytest_dualRays(&cnt,main_lp,main_lptols,main_lpopts) ; if (cnt != 3) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: %d dual rays returned, expected %d.\n", cnt,2) ; } /* Run the remainder of the tests, to make sure they run without error when dylp finishes infeasible. */ errcnt += dytest_betaj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abarj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_betai(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abari(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_allDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colPrimals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowPrimals(main_lp,main_lptols,main_lpopts) ; comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; dylp(main_lp,main_lpopts,main_lptols,NULL) ; consys_free(main_sys) ; main_sys = NULL ; main_lp->consys = NULL ; dy_freesoln(main_lp) ; } #endif #if RUN_GALENET > 0 /* Now load and solve the original galenet --- bound constraints on variables are handled implicitly, and the constraint system is a mix of <=, =, and >= constraints. As with galenetleq, we'll need the full ray (explicit duals y = c<B>inv(B) as well as duals associated with nonbasic bounded variables) in order to pass the mathematical tests rb < 0, rA > 0. */ dyio_outfmt(ttyout,dy_gtxecho, "\n\nLoading galenet example from static data.\n") ; main_sys = dytest_galenetsys(main_lptols) ; if (main_sys == NULL) { dyio_outfmt(ttyout,dy_gtxecho, "Failed to load galenet constraint system.\n") ; errcnt++ ; } else { dy_checkdefaults(main_sys,main_lpopts,main_lptols) ; comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; main_lp->phase = dyINV ; main_lp->consys = main_sys ; main_lp->rowsze = main_sys->rowsze ; main_lp->colsze = main_sys->colsze ; main_lpopts->forcecold = TRUE ; main_lpopts->fullsys = TRUE ; main_lpopts->finpurge.vars = FALSE ; main_lpopts->finpurge.cons = FALSE ; main_lpopts->coldbasis = ibLOGICAL ; main_lpopts->scaling = 2 ; /* main_lpopts->print.major = 1 ; main_lpopts->print.phase1 = 4 ; main_lpopts->print.phase2 = 4 ; main_lpopts->print.dual = 4 ; main_lpopts->print.tableau = 4 ; main_lpopts->print.soln = 3 ; main_lpopts->print.rays = 5 ; */ dyio_outfmt(ttyout,dy_gtxecho,"Solving galenet ... ") ; lpretval = do_lp(main_lp,main_lptols,main_lpopts,1) ; dyio_outfmt(ttyout,dy_gtxecho,"\n %s, z = %.12f.\n", dy_prtlpret(lpretval),main_lp->obj) ; z = 46.0 ; if (!(fabs(main_lp->obj-z) <= main_lptols->cost)) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: z = %g, expected %g, error %g, tol %g.\n", main_lp->obj,z,fabs(main_lp->obj-z),main_lptols->cost) ; } dumpsoln = TRUE ; if (dumpsoln == TRUE) { dy_dumpcompact(dy_logchn,dy_gtxecho,main_lp,FALSE) ; } /* Test that we have valid dual rays. First ask for just one, then ask for five, expecting two. Note that we end up at a different vertex than the previous expanded versions of galenet. */ cnt = 1 ; errcnt += dytest_dualRays(&cnt,main_lp,main_lptols,main_lpopts) ; if (cnt != 1) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: %d dual rays returned, expected %d.\n", cnt,1) ; } cnt = 5 ; errcnt += dytest_dualRays(&cnt,main_lp,main_lptols,main_lpopts) ; if (cnt != 2) { errcnt++ ; dyio_outfmt(ttyout,dy_gtxecho, " ERROR: %d dual rays returned, expected %d.\n", cnt,2) ; } /* Run the remainder of the tests, to make sure they run without error when dylp finishes infeasible. */ errcnt += dytest_betaj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abarj(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_betai(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_abari(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_allDuals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_colPrimals(main_lp,main_lptols,main_lpopts) ; errcnt += dytest_rowPrimals(main_lp,main_lptols,main_lpopts) ; comflg(main_lp->ctlopts,lpctlONLYFREE|lpctlNOFREE) ; dylp(main_lp,main_lpopts,main_lptols,NULL) ; consys_free(main_sys) ; main_sys = NULL ; main_lp->consys = NULL ; dy_freesoln(main_lp) ; } #endif /* Report the result before we shut down. */ if (errcnt > 0) { dyio_outfmt(ttyout,dy_gtxecho, "\n ERROR: %d total errors for all tests.\n\n", errcnt) ; } else { dyio_outfmt(ttyout,dy_gtxecho, "\n All tests completed successfully.\n\n") ; } dy_freebasis() ; /* Final cleanup. Free space used by the remaining main_* structures and close down any i/o. */ if (main_lp != NULL) { dy_freesoln(main_lp) ; if (main_lp->consys != NULL) consys_free(main_lp->consys) ; FREE(main_lp) ; } if (main_lpopts != NULL) FREE(main_lpopts) ; if (main_lptols != NULL) FREE(main_lptols) ; if (outchn != IOID_INV && outchn != ttyout) { (void) dyio_closefile(outchn) ; } if (dy_logchn != IOID_INV && dy_logchn != IOID_NOSTRM) { (void) dyio_closefile(dy_logchn) ; } dyio_ioterm() ; errterm() ; return (errcnt) ; }
int main (int argc, char *argv[]) { time_t timeval ; struct tm *tm ; char runtime[50] ; ioid ttyin,ttyout,outchn ; int optlett,printlvl ; bool silent,terse,swaperrs,errecho,doversion,dohelp ; const char *errmsgpath,*errlogpath,*optpath,*mpspath,*logpath ; struct timeval lptime ; const char *rtnnme = argv[0] ; /* getopt() --- we need explicit declarations under strict ANSI compliance mode. This function seems to be quite common, however. Present in GCC. */ int getopt(int argc, char*const *argv, const char *optstring) ; extern char *optarg ; extern int opterr,optind,optopt ; const char *optstring = "e:stp:E:o:m:L:O:hv"; extern struct tm *localtime(const time_t *clock) ; /* mpsio.c */ extern bool dy_mpsin(const char *mpspath, consys_struct **consys, double infinity); /* dy_basis.c */ extern void dy_initbasis(int concnt, int factor_freq, double zero_tol), dy_freebasis(void) ; /* Set up some defaults, then process the command line options. This is all very specific to Unix and SunOS. */ errmsgpath = DYLP_ERRMSGPATH ; errlogpath = NULL ; optpath = NULL ; mpspath = NULL ; outpath = NULL ; logpath = NULL ; ttyout = IOID_INV ; ttyin = IOID_INV ; dy_logchn = IOID_INV ; outchn = IOID_INV ; silent = FALSE ; terse = FALSE ; dy_gtxecho = TRUE ; dy_cmdecho = FALSE ; doversion = FALSE ; dohelp = FALSE ; printlvl = -1 ; opterr = 0 ; for (optlett = getopt(argc,argv,optstring) ; optlett != -1 ; optlett = getopt(argc,argv,optstring)) switch (optlett) { case 'e': { errmsgpath = optarg ; break ; } case 'E': { errlogpath = optarg ; break ; } case 'o': { optpath = optarg ; break ; } case 'm': { mpspath = optarg ; break ; } case 'L': { logpath = optarg ; break ; } case 'O': { outpath = optarg ; break ; } case 's': { silent = TRUE ; dy_gtxecho = FALSE ; break ; } case 't': { terse = TRUE ; dy_gtxecho = FALSE ; break ; } case 'p': { printlvl = atoi(optarg) ; break ; } case 'v': { doversion = TRUE ; break ; } case 'h': { dohelp = TRUE ; break ; } case '?': { errinit(errmsgpath,errlogpath,TRUE) ; dyio_ioinit() ; errmsg(3,rtnnme,"command line option",optopt) ; exit (1) ; } } /* If there's still a parameter left, it must be the mps file, specified without using the -m option. There should not be more than one parameter remaining. */ if (optind < argc) { mpspath = argv[optind] ; optind++ ; } if (optind < argc) { dohelp = TRUE ; } /* What's our output level? If the user has specified a print level, go with it. Otherwise, take a cue from any -s or -t flags. Default to print level 2. */ if (printlvl < 0) { if (silent == TRUE) printlvl = 0 ; else if (terse == TRUE) printlvl = 1 ; else printlvl = 2 ; } /* Output file name: if the user hasn't specified one, and we're not running silent, default to stdout. */ if (outpath == NULL && silent == FALSE) outpath = "stdout" ; /* Grab the time and format it nicely. */ if (time(&timeval) == (time_t)(-1)) { warn(19,rtnnme) ; osidylp_time = "n/a" ; } else { tm = localtime(&timeval) ; if (tm != NULL) { strftime(runtime,sizeof(runtime),"%A, %B %d, %Y, %I:%M:%S %p",tm) ; osidylp_time = runtime ; } else { osidylp_time = "n/a" ; } } /* Figure out the appropriate settings for silent and terse. silent is set to (silent || terse), and is passed to process_cmds so that it can properly handle dy_cmdecho and dy_gtxecho. terse is set for ease of controlling the output specifically mentioned in conjunction with terse mode (which is controlled from this routine). The proper value is (terse || !silent). The cryptic little if statement below accomplishes this (try a decision tree to convince yourself). */ if (terse == TRUE) { if (silent == TRUE) terse = FALSE ; else silent = TRUE ; } else { if (silent == FALSE) terse = TRUE ; } /* Execute initialization routines for the i/o and error reporting packages. */ if (silent == TRUE) errecho = FALSE ; else errecho = TRUE ; errinit(errmsgpath,errlogpath,errecho) ; if (dyio_ioinit() != TRUE) { errmsg(1,rtnnme,__LINE__) ; exit (2) ; } /* Connect ttyout to the standard output. Initialize ttyin, setting the mode to line-oriented. Serious internal confusion if we can't manage these. Set the initial command input channel to stdin. */ ttyout = dyio_openfile("stdout","w") ; if (ttyout == IOID_INV) { errmsg(1,rtnnme,__LINE__) ; exit(3) ; } ttyin = dyio_openfile("stdin","r") ; if (ttyin == IOID_INV) { errmsg(1,rtnnme,__LINE__) ; exit(4) ; } (void) dyio_setmode(ttyin,'l') ; dy_cmdchn = ttyin ; /* Initialize logging. */ if (logpath != NULL) { dy_logchn = dyio_openfile(logpath,"w") ; if (dy_logchn == IOID_INV) { warn(201,rtnnme,logpath) ; dy_logchn = IOID_NOSTRM ; } } else { dy_logchn = IOID_NOSTRM ; } /* Are we supposed to merge the error messages with the log stream? (Note that errors will be echoed to stderr unless we're running silent. If the user's turned off logging too, well, it's their business.) swaperrs just tells the code that it should reset the error logging channel if it ever resets the main logging channel. */ if (errlogpath == NULL && dy_logchn != IOID_NOSTRM) { swaperrs = TRUE ; errlogpath = logpath ; if (dyio_chgerrlog(errlogpath,errecho) == FALSE) { warn(18,rtnnme,"<null>",errlogpath) ; } } /* Ok, after all that work, check if we've been asked for the version or usage messages. If so, do it and head for the exit. Version preempts help. */ if (doversion == TRUE) { print_version(dy_logchn,dy_gtxecho,argv[0],rtnnme,osidylp_version) ; goto NOOUTFILE_CLEANUP ; } if (dohelp == TRUE) { print_help(dy_logchn,dy_gtxecho,argv[0]) ; goto NOOUTFILE_CLEANUP ; } /* We're up! Banners to the appropriate places. */ dyio_outfmt(dy_logchn,terse,"\n\t\t %s\tV %s\n",rtnnme,osidylp_version) ; dyio_outfmt(dy_logchn,terse,"\n\t\t%s",runtime) ; dyio_outfmt(dy_logchn,terse,"\n\n") ; if (outpath != NULL && strcmp(outpath,"stdout") != 0) { outchn = dyio_pathtoid(outpath,NULL) ; if (outchn == IOID_INV) outchn = dyio_openfile(outpath,"w") ; if (outchn == IOID_INV) { warn(10,rtnnme,outpath,"w") ; } else { dyio_outfmt(outchn,FALSE,"\n\t\t %s\tV %s\n",rtnnme,osidylp_version) ; dyio_outfmt(outchn,FALSE,"\n\t\t%s",runtime) ; dyio_outfmt(outchn,FALSE,"\n\n") ; } } /* Time to set up the lp options. Establish a set of defaults, then read the options file to see what the user has in mind. Because this is a standalone shell, doing a one-time solution for an LP, set up a default of cold start using the full system and a logical basis. This can be overridden in a .spc file if desired. For reasons that escape me at the moment, the parser fails on Windows. This may get fixed eventually. For now, disabled by the simple expedient of forcing optpath to NULL. */ dy_defaults(&main_lpopts,&main_lptols) ; main_lpopts->forcecold = TRUE ; main_lpopts->fullsys = TRUE ; main_lpopts->coldbasis = ibLOGICAL ; # if defined(_MSC_VER) || defined(__MSVCRT__) optpath = NULL ; # endif if (optpath != NULL) { dy_cmdchn = dyio_openfile(optpath,"r") ; if (dy_cmdchn == IOID_INV) exit (1) ; (void) dyio_setmode(dy_cmdchn,'l') ; switch (process_cmds(silent)) { case cmdOK: { break ; } case cmdHALTERROR: { exit (1) ; } case cmdHALTNOERROR: { exit (0) ; } default: { exit (1) ; } } if (dy_cmdchn != ttyin) { (void) dyio_closefile(dy_cmdchn) ; dy_cmdchn = IOID_INV ; } } /* Make an attempt to read the mps input file. */ if (dy_mpsin(mpspath,&main_sys,main_lptols->inf) == FALSE) { exit (10) ;} /* Check over the option settings, now that we know how big the constraint system will be. */ dy_checkdefaults(main_sys,main_lpopts,main_lptols) ; /* Initialise the basis maintenance package. The second parameter controls how many basis updates the basis can hold before it requires refactoring. Adding 5 to dylp's refactor interval should give a safety margin. */ dy_initbasis(2*main_sys->concnt,main_lpopts->factor+5,0.0) ; /* Run the lp. */ if (do_lp(&lptime,printlvl) == FALSE) { errmsg(443,rtnnme,main_sys->nme,dy_prtlpphase(main_lp->phase,TRUE), main_lp->iters) ; } /* Should we produce any output? Print to a file, if requested. */ if (outchn != IOID_INV && outchn != ttyout) { dy_dumpcompact(outchn,FALSE,main_lp,FALSE) ; } /* Any final terminal output we should do? */ if (printlvl >= 1) { if (printlvl >= 2) { dy_dumpcompact(dy_logchn, (dy_logchn == IOID_INV)?TRUE:FALSE,main_lp,FALSE) ; } dyio_outfmt(dy_logchn,TRUE,"\nReturn code %s",dy_prtlpret(main_lp->lpret)) ; if (main_lp->phase == dyDONE) dyio_outfmt(dy_logchn,TRUE," after %d pivots",main_lp->iters) ; if (main_lp->lpret == lpOPTIMAL) { dyio_outfmt(dy_logchn,TRUE,"; objective %.8g",main_lp->obj) ; } dyio_outfmt(dy_logchn,TRUE, " (%.2f sec.)",lptime.tv_sec+lptime.tv_usec/1e6) ; dyio_outfmt(dy_logchn,TRUE,".\n") ; dyio_flushio(dy_logchn,dy_gtxecho) ; } /* Final cleanup. Free space used by the remaining main_* structures. */ dy_freebasis() ; if (main_lp != NULL) { dy_freesoln(main_lp) ; if (main_lp->consys != NULL) consys_free(main_lp->consys) ; FREE(main_lp) ; } if (main_lpopts != NULL) FREE(main_lpopts) ; if (main_lptols != NULL) FREE(main_lptols) ; /* Leap to here for shutdown when we opened the output file but didn't solve an LP. */ if (outchn != IOID_INV && outchn != ttyout) { (void) dyio_closefile(outchn) ; } /* Leap to here for shutdown in cases where we never get as far as opening an output file. We still need to close the log file and shut down the i/o subsystem. */ NOOUTFILE_CLEANUP: if (dy_logchn != IOID_INV && dy_logchn != IOID_NOSTRM) { (void) dyio_closefile(dy_logchn) ; } dyio_ioterm() ; errterm() ; exit(0) ; /* Just to suppress the silly warning from the compiler, which isn't satisfied with the immediately preceding `exit'. */ return (0) ; }