|
| 1 | +Support verbosity parameter in glp_exact |
| 2 | + |
| 3 | +Patch based on http://lists.gnu.org/archive/html/help-glpk/2011-10/msg00037.html |
| 4 | + |
| 5 | +diff -ru a/doc/glpk02.tex b/doc/glpk02.tex |
| 6 | +--- a/doc/glpk02.tex 2017-07-25 09:00:00.000000000 +0200 |
| 7 | ++++ b/doc/glpk02.tex 2017-08-31 13:28:11.559220389 +0200 |
| 8 | +@@ -2014,9 +2014,9 @@ |
| 9 | + exact in mathematical sense, i.e. free of round-off errors unlike |
| 10 | + floating-point arithmetic. |
| 11 | + |
| 12 | +-Note that the routine \verb|glp_exact| uses only two control parameters |
| 13 | +-passed in the structure \verb|glp_smcp|, namely, \verb|it_lim| and |
| 14 | +-\verb|tm_lim|. |
| 15 | ++Note that the routine \verb|glp_exact| uses only three control parameters |
| 16 | ++passed in the structure \verb|glp_smcp|, namely, \verb|it_lim|, |
| 17 | ++\verb|tm_lim| and \verb|msg\_lev|. |
| 18 | + |
| 19 | + \returns |
| 20 | + |
| 21 | +diff -ru a/src/glpapi07.c b/src/glpapi07.c |
| 22 | +--- a/src/glpapi07.c 2017-07-25 09:00:00.000000000 +0200 |
| 23 | ++++ b/src/glpapi07.c 2017-08-31 14:03:54.395718543 +0200 |
| 24 | +@@ -267,6 +267,13 @@ |
| 25 | + if (parm == NULL) |
| 26 | + parm = &_parm, glp_init_smcp((glp_smcp *)parm); |
| 27 | + /* check control parameters */ |
| 28 | ++ if (!(parm->msg_lev == GLP_MSG_OFF || |
| 29 | ++ parm->msg_lev == GLP_MSG_ERR || |
| 30 | ++ parm->msg_lev == GLP_MSG_ON || |
| 31 | ++ parm->msg_lev == GLP_MSG_ALL || |
| 32 | ++ parm->msg_lev == GLP_MSG_DBG)) |
| 33 | ++ xerror("glp_simplex: msg_lev = %d; invalid parameter\n", |
| 34 | ++ parm->msg_lev); |
| 35 | + if (parm->it_lim < 0) |
| 36 | + xerror("glp_exact: it_lim = %d; invalid parameter\n", |
| 37 | + parm->it_lim); |
| 38 | +@@ -275,7 +282,8 @@ |
| 39 | + parm->tm_lim); |
| 40 | + /* the problem must have at least one row and one column */ |
| 41 | + if (!(m > 0 && n > 0)) |
| 42 | +- { xprintf("glp_exact: problem has no rows/columns\n"); |
| 43 | ++ { if (parm->msg_lev >= GLP_MSG_ERR) |
| 44 | ++ xprintf("glp_exact: problem has no rows/columns\n"); |
| 45 | + return GLP_EFAIL; |
| 46 | + } |
| 47 | + #if 1 |
| 48 | +@@ -297,31 +305,35 @@ |
| 49 | + ub = lp->col[k-m]->ub; |
| 50 | + } |
| 51 | + if (type == GLP_DB && lb >= ub) |
| 52 | +- { xprintf("glp_exact: %s %d has invalid bounds\n", |
| 53 | ++ { if (parm->msg_lev >= GLP_MSG_ERR) |
| 54 | ++ xprintf("glp_exact: %s %d has invalid bounds\n", |
| 55 | + k <= m ? "row" : "column", k <= m ? k : k-m); |
| 56 | + return GLP_EBOUND; |
| 57 | + } |
| 58 | + } |
| 59 | + /* create the simplex solver workspace */ |
| 60 | +- xprintf("glp_exact: %d rows, %d columns, %d non-zeros\n", |
| 61 | ++ if (parm->msg_lev >= GLP_MSG_ALL) |
| 62 | ++ { xprintf("glp_exact: %d rows, %d columns, %d non-zeros\n", |
| 63 | + m, n, nnz); |
| 64 | + #ifdef HAVE_GMP |
| 65 | +- xprintf("GNU MP bignum library is being used\n"); |
| 66 | ++ xprintf("GNU MP bignum library is being used\n"); |
| 67 | + #else |
| 68 | +- xprintf("GLPK bignum module is being used\n"); |
| 69 | +- xprintf("(Consider installing GNU MP to attain a much better perf" |
| 70 | +- "ormance.)\n"); |
| 71 | ++ xprintf("GLPK bignum module is being used\n"); |
| 72 | ++ xprintf("(Consider installing GNU MP to attain a much better performance.)\n"); |
| 73 | + #endif |
| 74 | ++ } |
| 75 | + ssx = ssx_create(m, n, nnz); |
| 76 | + /* load LP problem data into the workspace */ |
| 77 | + load_data(ssx, lp); |
| 78 | + /* load current LP basis into the workspace */ |
| 79 | + if (load_basis(ssx, lp)) |
| 80 | +- { xprintf("glp_exact: initial LP basis is invalid\n"); |
| 81 | ++ { if (parm->msg_lev >= GLP_MSG_ERR) |
| 82 | ++ xprintf("glp_exact: initial LP basis is invalid\n"); |
| 83 | + ret = GLP_EBADB; |
| 84 | + goto done; |
| 85 | + } |
| 86 | + /* inherit some control parameters from the LP object */ |
| 87 | ++ ssx->msg_lev = parm->msg_lev; |
| 88 | + #if 0 |
| 89 | + ssx->it_lim = lpx_get_int_parm(lp, LPX_K_ITLIM); |
| 90 | + ssx->it_cnt = lpx_get_int_parm(lp, LPX_K_ITCNT); |
| 91 | +diff -ru a/src/glpssx02.c b/src/glpssx02.c |
| 92 | +--- a/src/glpssx02.c 2017-07-25 09:00:00.000000000 +0200 |
| 93 | ++++ b/src/glpssx02.c 2017-08-31 13:28:11.559220389 +0200 |
| 94 | +@@ -132,7 +132,7 @@ |
| 95 | + ssx_eval_pi(ssx); |
| 96 | + ssx_eval_cbar(ssx); |
| 97 | + /* display initial progress of the search */ |
| 98 | +- show_progress(ssx, 1); |
| 99 | ++ if (ssx->msg_lev >= GLP_MSG_ON) show_progress(ssx, 1); |
| 100 | + /* main loop starts here */ |
| 101 | + for (;;) |
| 102 | + { /* display current progress of the search */ |
| 103 | +@@ -141,7 +141,7 @@ |
| 104 | + #else |
| 105 | + if (xdifftime(xtime(), ssx->tm_lag) >= ssx->out_frq - 0.001) |
| 106 | + #endif |
| 107 | +- show_progress(ssx, 1); |
| 108 | ++ if (ssx->msg_lev >= GLP_MSG_ON) show_progress(ssx, 1); |
| 109 | + /* we do not need to wait until all artificial variables have |
| 110 | + left the basis */ |
| 111 | + if (mpq_sgn(bbar[0]) == 0) |
| 112 | +@@ -243,7 +243,7 @@ |
| 113 | + ssx->it_cnt++; |
| 114 | + } |
| 115 | + /* display final progress of the search */ |
| 116 | +- show_progress(ssx, 1); |
| 117 | ++ if (ssx->msg_lev >= GLP_MSG_ON) show_progress(ssx, 1); |
| 118 | + /* restore components of the original problem, which were changed |
| 119 | + by the routine */ |
| 120 | + for (k = 1; k <= m+n; k++) |
| 121 | +@@ -282,7 +282,7 @@ |
| 122 | + int ssx_phase_II(SSX *ssx) |
| 123 | + { int ret; |
| 124 | + /* display initial progress of the search */ |
| 125 | +- show_progress(ssx, 2); |
| 126 | ++ if (ssx->msg_lev >= GLP_MSG_ON) show_progress(ssx, 2); |
| 127 | + /* main loop starts here */ |
| 128 | + for (;;) |
| 129 | + { /* display current progress of the search */ |
| 130 | +@@ -291,7 +291,7 @@ |
| 131 | + #else |
| 132 | + if (xdifftime(xtime(), ssx->tm_lag) >= ssx->out_frq - 0.001) |
| 133 | + #endif |
| 134 | +- show_progress(ssx, 2); |
| 135 | ++ if (ssx->msg_lev >= GLP_MSG_ON) show_progress(ssx, 2); |
| 136 | + /* check if the iterations limit has been exhausted */ |
| 137 | + if (ssx->it_lim == 0) |
| 138 | + { ret = 2; |
| 139 | +@@ -347,7 +347,7 @@ |
| 140 | + ssx->it_cnt++; |
| 141 | + } |
| 142 | + /* display final progress of the search */ |
| 143 | +- show_progress(ssx, 2); |
| 144 | ++ if (ssx->msg_lev >= GLP_MSG_ON) show_progress(ssx, 2); |
| 145 | + /* return to the calling program */ |
| 146 | + return ret; |
| 147 | + } |
| 148 | +@@ -419,15 +419,15 @@ |
| 149 | + ret = 0; |
| 150 | + break; |
| 151 | + case 1: |
| 152 | +- xprintf("PROBLEM HAS NO FEASIBLE SOLUTION\n"); |
| 153 | ++ if (ssx->msg_lev >= GLP_MSG_ALL) xprintf("PROBLEM HAS NO FEASIBLE SOLUTION\n"); |
| 154 | + ret = 1; |
| 155 | + break; |
| 156 | + case 2: |
| 157 | +- xprintf("ITERATIONS LIMIT EXCEEDED; SEARCH TERMINATED\n"); |
| 158 | ++ if (ssx->msg_lev >= GLP_MSG_ALL) xprintf("ITERATIONS LIMIT EXCEEDED; SEARCH TERMINATED\n"); |
| 159 | + ret = 3; |
| 160 | + break; |
| 161 | + case 3: |
| 162 | +- xprintf("TIME LIMIT EXCEEDED; SEARCH TERMINATED\n"); |
| 163 | ++ if (ssx->msg_lev >= GLP_MSG_ALL) xprintf("TIME LIMIT EXCEEDED; SEARCH TERMINATED\n"); |
| 164 | + ret = 5; |
| 165 | + break; |
| 166 | + default: |
| 167 | +@@ -446,19 +446,19 @@ |
| 168 | + ret = ssx_phase_II(ssx); |
| 169 | + switch (ret) |
| 170 | + { case 0: |
| 171 | +- xprintf("OPTIMAL SOLUTION FOUND\n"); |
| 172 | ++ if (ssx->msg_lev >= GLP_MSG_ALL) xprintf("OPTIMAL SOLUTION FOUND\n"); |
| 173 | + ret = 0; |
| 174 | + break; |
| 175 | + case 1: |
| 176 | +- xprintf("PROBLEM HAS UNBOUNDED SOLUTION\n"); |
| 177 | ++ if (ssx->msg_lev >= GLP_MSG_ALL) xprintf("PROBLEM HAS UNBOUNDED SOLUTION\n"); |
| 178 | + ret = 2; |
| 179 | + break; |
| 180 | + case 2: |
| 181 | +- xprintf("ITERATIONS LIMIT EXCEEDED; SEARCH TERMINATED\n"); |
| 182 | ++ if (ssx->msg_lev >= GLP_MSG_ALL) printf("ITERATIONS LIMIT EXCEEDED; SEARCH TERMINATED\n"); |
| 183 | + ret = 4; |
| 184 | + break; |
| 185 | + case 3: |
| 186 | +- xprintf("TIME LIMIT EXCEEDED; SEARCH TERMINATED\n"); |
| 187 | ++ if (ssx->msg_lev >= GLP_MSG_ALL) xprintf("TIME LIMIT EXCEEDED; SEARCH TERMINATED\n"); |
| 188 | + ret = 6; |
| 189 | + break; |
| 190 | + default: |
| 191 | +diff -ru a/src/glpssx.h b/src/glpssx.h |
| 192 | +--- a/src/glpssx.h 2017-07-25 09:00:00.000000000 +0200 |
| 193 | ++++ b/src/glpssx.h 2017-08-31 13:59:05.577754269 +0200 |
| 194 | +@@ -25,6 +25,7 @@ |
| 195 | + #ifndef GLPSSX_H |
| 196 | + #define GLPSSX_H |
| 197 | + |
| 198 | ++#include "glpk.h" |
| 199 | + #include "bfx.h" |
| 200 | + #include "env.h" |
| 201 | + |
| 202 | +@@ -337,6 +338,12 @@ |
| 203 | + #endif |
| 204 | + /* the most recent time, in seconds, at which the progress of the |
| 205 | + the search was displayed */ |
| 206 | ++ int msg_lev; |
| 207 | ++ /* sets the verbosity of simplex solver |
| 208 | ++ GLP_MSG_OFF no output |
| 209 | ++ GLP_MSG_ERR report errors and warnings |
| 210 | ++ GLP_MSG_ON normal output |
| 211 | ++ GLP_MSG_ALL highest verbosity */ |
| 212 | + }; |
| 213 | + |
| 214 | + #define ssx_create _glp_ssx_create |
0 commit comments