Skip to content

Commit

Permalink
Improve glpk behavior (bug #66010).
Browse files Browse the repository at this point in the history
* libinterp/dldfcn/__glpk__.cc (glpk): Align default parameter tolpiv to
current glpk version (v 5.0) default value 1e-9. Implement support of msglev
setting when calling glpk subroutines. Sort the constraints for better
presolving analogue to the glpk provided glpsol code.
* scripts/optimization/glpk.m: Reflect updated default parameter in
documentation.
  • Loading branch information
koerhen committed Aug 7, 2024
1 parent 004094b commit 397bcb2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions libinterp/dldfcn/__glpk__.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ glpk (int sense, int n, int m, double *c, int nz, int *rn, int *cn,
{
int typx = 0;
int errnum = 0;
int tout = 0; // to save and restore msglev settings

time = 0.0;
status = -1; // Initialize status to "bad" value
Expand Down Expand Up @@ -173,13 +174,23 @@ glpk (int sense, int n, int m, double *c, int nz, int *rn, int *cn,

glp_load_matrix (lp, nz, rn, cn, a);

// sort the constraints for better presolving analogue to the code
// sample provided by glpk
glp_sort_matrix (lp);

if (save_pb)
{
static char tmp[] = "outpb.lp";
if (glp_write_lp (lp, nullptr, tmp) != 0)
error ("__glpk__: unable to write problem");
}

// direct calling glp_subroutines requires explicit msglev setting
if (par.msglev < 3)
tout = glp_term_out (GLP_OFF);
else
tout = glp_term_out (GLP_ON);

// scale the problem data
if (! par.presol || lpsolver != 1)
glp_scale_prob (lp, scale);
Expand All @@ -188,6 +199,8 @@ glpk (int sense, int n, int m, double *c, int nz, int *rn, int *cn,
if (lpsolver == 1 && ! par.presol)
glp_adv_basis (lp, 0);

glp_term_out (tout); // restore previous msglev status

// For MIP problems without a presolver, a first pass with glp_simplex
// is required
if ((! isMIP && lpsolver == 1)
Expand Down Expand Up @@ -586,8 +599,8 @@ Undocumented internal function.
OCTAVE_GLPK_GET_REAL_PARAM ("toldj", par.toldj);

// Relative tolerance used to choose eligible pivotal elements of
// the simplex table in the ratio test
par.tolpiv = 1e-10;
// the simplex table in the ratio test
par.tolpiv = 1e-9;
OCTAVE_GLPK_GET_REAL_PARAM ("tolpiv", par.tolpiv);

par.objll = -std::numeric_limits<double>::max ();
Expand Down
2 changes: 1 addition & 1 deletion scripts/optimization/glpk.m
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@
## feasible. It is not recommended that you change this parameter unless you
## have a detailed understanding of its purpose.
##
## @item tolpiv (default: 1e-10)
## @item tolpiv (default: 1e-9)
## Relative tolerance used to choose eligible pivotal elements of the simplex
## table. It is not recommended that you change this parameter unless you have
## a detailed understanding of its purpose.
Expand Down

0 comments on commit 397bcb2

Please sign in to comment.