Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 4f4fa2c

Browse files
committed
Use verbosity level in glp_exact
1 parent baacd6c commit 4f4fa2c

File tree

5 files changed

+251
-35
lines changed

5 files changed

+251
-35
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.63
1+
4.63.p1
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
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

src/sage/numerical/backends/generic_backend.pyx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,9 +1750,6 @@ cpdef GenericBackend get_solver(constraint_generation = False, solver = None, ba
17501750
....: b.solver_parameter("simplex_or_intopt", "exact_simplex_only")
17511751
....: return b
17521752
sage: codes.bounds.delsarte_bound_additive_hamming_space(11,3,4,solver=glpk_exact_solver) # long time
1753-
glp_exact...
1754-
...
1755-
OPTIMAL SOLUTION FOUND
17561753
8
17571754
17581755
"""

src/sage/numerical/backends/glpk_backend.pyx

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,43 @@ cdef class GLPKBackend(GenericBackend):
395395
396396
EXAMPLES::
397397
398-
sage: from sage.numerical.backends.generic_backend import get_solver
399-
sage: p = get_solver(solver = "GLPK")
400-
sage: p.set_verbosity(2)
398+
sage: p.<x> = MixedIntegerLinearProgram(solver="GLPK")
399+
sage: p.add_constraint(10 * x[0] <= 1)
400+
sage: p.add_constraint(5 * x[1] <= 1)
401+
sage: p.set_objective(x[0] + x[1])
402+
sage: p.solve()
403+
0.30000000000000004
404+
sage: p.get_backend().set_verbosity(3)
405+
sage: p.solve()
406+
GLPK Integer Optimizer, v4.63
407+
2 rows, 2 columns, 2 non-zeros
408+
0 integer variables, none of which are binary
409+
Preprocessing...
410+
Objective value = 3.000000000e-01
411+
INTEGER OPTIMAL SOLUTION FOUND BY MIP PREPROCESSOR
412+
0.30000000000000004
401413
414+
::
415+
416+
sage: p.<x> = MixedIntegerLinearProgram(solver="GLPK/exact")
417+
sage: p.add_constraint(10 * x[0] <= 1)
418+
sage: p.add_constraint(5 * x[1] <= 1)
419+
sage: p.set_objective(x[0] + x[1])
420+
sage: p.solve()
421+
0.3
422+
sage: p.get_backend().set_verbosity(2)
423+
sage: p.solve()
424+
* 2: objval = 0.3 (0)
425+
* 2: objval = 0.3 (0)
426+
0.3
427+
sage: p.get_backend().set_verbosity(3)
428+
sage: p.solve()
429+
glp_exact: 2 rows, 2 columns, 2 non-zeros
430+
GNU MP bignum library is being used
431+
* 2: objval = 0.3 (0)
432+
* 2: objval = 0.3 (0)
433+
OPTIMAL SOLUTION FOUND
434+
0.3
402435
"""
403436
if level == 0:
404437
self.iocp.msg_lev = GLP_MSG_OFF
@@ -910,11 +943,6 @@ cdef class GLPKBackend(GenericBackend):
910943
911944
sage: lp.solver_parameter("simplex_or_intopt", "exact_simplex_only") # use exact simplex only
912945
sage: lp.solve()
913-
glp_exact: 3 rows, 2 columns, 6 non-zeros
914-
GNU MP bignum library is being used
915-
* 2: objval = 2 (0)
916-
* 2: objval = 2 (0)
917-
OPTIMAL SOLUTION FOUND
918946
2.0
919947
sage: lp.get_values([x, y])
920948
[1.5, 0.5]
@@ -947,11 +975,6 @@ cdef class GLPKBackend(GenericBackend):
947975
sage: lp.add_constraint(x <= test)
948976
sage: lp.set_objective(x)
949977
sage: lp.solve() == test # yes, we want an exact comparison here
950-
glp_exact: 1 rows, 1 columns, 1 non-zeros
951-
GNU MP bignum library is being used
952-
* 0: objval = 0 (0)
953-
* 1: objval = 9.00719925474095e+15 (0)
954-
OPTIMAL SOLUTION FOUND
955978
True
956979
sage: lp.get_values(x) == test # yes, we want an exact comparison here
957980
True

src/sage/numerical/backends/glpk_exact_backend.pyx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,7 @@ cdef class GLPKExactBackend(GLPKBackend):
3232
3333
sage: p = MixedIntegerLinearProgram(solver="GLPK/exact")
3434
sage: TestSuite(p.get_backend()).run(skip="_test_pickling")
35-
glp_exact: 5 rows, 1 columns, 4 non-zeros
36-
GNU MP bignum library is being used
37-
* 0: objval = 0 (0)
38-
* 0: objval = 0 (0)
39-
OPTIMAL SOLUTION FOUND
40-
glp_exact: 5 rows, 1 columns, 4 non-zeros
41-
GNU MP bignum library is being used
42-
* 0: objval = 0 (0)
43-
* 0: objval = 0 (0)
44-
PROBLEM HAS UNBOUNDED SOLUTION
45-
glp_exact: 3 rows, 3 columns, 8 non-zeros
46-
GNU MP bignum library is being used
47-
0: infsum = 1 (0)
48-
4: infsum = 0 (0)
49-
* 4: objval = 1.66666666666667 (0)
50-
* 4: objval = 1.66666666666667 (0)
51-
OPTIMAL SOLUTION FOUND
5235
"""
53-
5436
def __cinit__(self, maximization = True):
5537
"""
5638
Constructor

0 commit comments

Comments
 (0)