# Suppress mixed integer programming output [closed]

I am running code on a remote server in which I solve many small mixed integer programs(using the .solve() method). I tested my code on my local machine with no issues. However, when I run it remotely it seems that the Sage installation there does not suppress output from .solve(). I get many, many prints to the console which look like:

glp_exact: 224 rows, 196 columns, 588 non-zeros
GNU MP bignum library is being used
0:   infsum =                      2   (11)
47:   infsum =                      0   (11)
*    47:   objval =       1.39285714285714   (12)
*   205:   objval =      0.660714285714286   (5)
OPTIMAL SOLUTION FOUND


It would be very helpful to not have Sage constantly printing to the console; is there a way to suppress this output? Some sort of flag, maybe, when I run Sage?

EDIT: In response to David Coudert's comment, here is the kind of behavior I'm seeing, on a relevant snippet:

sage: def opt(x):
....:     mip = MixedIntegerLinearProgram(maximization=False, solver="GLPK/exact")
....:     mip.add_constraint(mip[0]+mip[1] <= 1)
....:     mip.add_constraint(mip[0]-mip[1] <= 1)
....:     mip.add_constraint(-mip[0]-mip[1] <= 1)
....:     mip.add_constraint(-mip[0]+mip[1] <= 1)
....:     mip.set_objective(mip[0]+x*mip[1])
....:     return mip.solve()
....:
sage: [opt(n) for n in range(3)]
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
*     0:   objval =                      0   (0)
*     2:   objval =                     -1   (0)
OPTIMAL SOLUTION FOUND
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
*     0:   objval =                      0   (0)
*     1:   objval =                     -1   (0)
OPTIMAL SOLUTION FOUND
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
*     0:   objval =                      0   (0)
*     2:   objval =                     -2   (0)
OPTIMAL SOLUTION FOUND
[-1.0, -1.0, -2.0]


I would only like to have the final line of output printed to the console, yet am also finding the three pieces from GLPK put there too.

EDIT 2: I realized I forgot to mention that I'm running Sage 7.4 and that I may have trouble installing CPLX or Gurobi on the server since I do not have admin privileges there. These appear to be the only solvers which allow for the "logfile" approach.

edit retag reopen merge delete

### Closed for the following reason the question is answered, right answer was accepted by zjs close date 2021-09-22 03:30:19.642868

Can you give a (minimal) example of the kind of code you use ? Also, have you tried to set the log filename p.solver_parameter("logfile", "/path/to/some/logfile.txt") or p.solver_parameter("logfile", "/dev/null") ? it seems that the output you get is what should be in the log file.

( 2021-09-20 18:20:47 +0100 )edit

@David Coudert, I have added a code snippet and output sample to the main post. Just to be totally certain, changing .solver_parameter will only do so for the GLPK output, yes? Since I am still interested in printing other content to the console.

( 2021-09-20 19:16:22 +0100 )edit
1

Since you use "GLPK/exact", can you try mip.solver_parameter("verbosity_simplex", "GLP_MSG_OFF").

You can find the list of parameters you can modify at https://doc.sagemath.org/html/en/refe...

I checked the interfaces we other solvers and currently we can only set the log file for cplex and gurobi.

( 2021-09-21 15:28:08 +0100 )edit

I can not reproduce your issue with Sage 9.5.beta1, i do not have any such noise. Perhaps could you just upgrade your version of Sage.

( 2021-09-21 17:00:25 +0100 )edit
1

@David Coudert, thank you very much! The following indeed seems to work (inserted immediately following the declaration of the MixedIntegerLinearProgram):

mip.solver_parameter("simplex_or_intopt", "simplex_only")
mip.solver_parameter("verbosity_simplex", "GLP_MSG_OFF")


@tmonteil I am not sure if I will be able to upgrade Sage on the server because I do not have admin privileges.

( 2021-09-22 03:25:41 +0100 )edit