[Cbc] The Silence of the LPs
Dirk Eßer
essdir at web.de
Wed Jan 22 12:37:01 EST 2014
Hi everybody!
I just started porting an application of mine from lpsolver to CBC and
things work fine so far. There is one minor annoyance, though: despite
me defining my own "CoinMessageHandler" subclass and
"passInMessageHandler"-ing it into any "OsiSolverInterface" I can find,
there seems to be some code in the CBC library, which doesn't care about
my efforts, and insists on making itself heard.
This is slightly annoying, since the application is a server
application, which solves a lot of (small to medium size) MIPs in a row
on client requests, and the messages from CBC tend to blow up the log
files considerably with noise, we are not interested in.
The messages generated are "Cbc3007W" ("No integer variables - nothing
to do"), "Cbc0004I" ("Integer solution of x found after x iterations and
x nodes (x seconds)"), "Cbc0001I" ("Search completed - best objective x,
took x iterations and x nodes (x seconds)"), and "Cbc0035I" ("Maximum
depth x, x variables fixed on reduced cost").
I'd rather not resolve this issue by brute force (say, via "FILE* p =
fopen("/dev/null", "w"); CoinMessageHandler printer(p); ..." -- if
that's at all viable).
I am not using the "CbcSolver" class, only the "CbcModel" and
"Osi[Cbc]SolverInterface" and related APIs. The MIPs are generated
on-the-fly from data passed in by the client.
Any input on this is greatly appreciated.
Cheers,
Dirk
P.S. For reference, here's my message handler and set-up code.
class MessageHandler: public CoinMessageHandler
{
public:
MessageHandler(): CoinMessageHandler() {}
MessageHandler(const MessageHandler& r): CoinMessageHandler(r) {}
MessageHandler& operator= (const MessageHandler& r) {
CoinMessageHandler::operator=(r); return *this; }
virtual CoinMessageHandler* clone() { return new
MessageHandler(*this); }
virtual int print() { return 0; }
};
which is injected before and after model construction:
void
matrix_builder::set_printer(OsiSolverInterface* pf, MessageHandler&
printer)
{
if (pf) pf->passInMessageHandler(&printer);
}
and
OsiCbcSolverInterface iface;
CoinPackedMatrix pmx(false, num_columns, num_rows, num_elements,
matrix, columns, starts, lengths);
iface.setObjSense(-1.0);
iface.loadProblem(pmx, 0, 0, objective, senses, rights, 0);
iface.passInMessageHandler(&printer);
CbcModel model* = new CbcModel(iface);
... a few more things to set up SOS and integer declarations ...
set_printer(model->solver(), printer);
set_printer(model->continuousSolver(), printer);
set_printer(model->referenceSolver(), printer);
where "printer" is a reference to an instance of "MessageHandler".
More information about the Cbc
mailing list