/* * simple_glpk.c * * A file demonstrating the GLPK API. * */ #include #include #include "glpk.h" int main( void ) { /* Pointer to the lp object */ LPX *lp; int ret; /* return code */ char *filename = "p0033.mps"; int columns[2]; /* Read in an instance from an MPS file */ lp = lpx_read_mps( filename ); /* lp = lpx_read_freemps( filename ); */ /* Check that we read it correctly */ if (lp == NULL) { printf("Error reading file %s\n", filename); exit(1); } /* Solve the (relaxation of the) problem */ ret = lpx_simplex(lp); /* Check the solution */ if ( ret == LPX_E_OK && lpx_get_status(lp) == LPX_OPT ) { printf("Found optimal solution!\n"); printf("Objective value is %lf.\n", lpx_get_obj_val(lp) ); } /***************************/ /* Remove the first column */ /* This will fail, but if you change the index to a 2, it will succeed */ columns[1]=1; lpx_del_cols( lp, 1, columns ); /* Re-solve */ ret = lpx_simplex(lp); /* Check the solution */ if ( ret == LPX_E_OK && lpx_get_status(lp) == LPX_OPT ) { printf("Resolved and found optimal solution!\n"); printf("Objective value is %lf.\n", lpx_get_obj_val(lp) ); } else { printf("Something went wrong during resolve.\n"); } return 0; }