Question

I'm running CPLEX through the COIN/OSI interface (OsiCpxSolverInterface). For some large LPs I get an error message CPX0000 CPLEX Error 1001: Out of memory. Despite the error message, no exception (CoinError) is thrown. Looking at the source code of OsiCpxSolverInterface it looks like the return code of CPXlpopt must have been 0.

To be clear: my question is not how to avoid the out-of-memory problem. I'm just looking for a way to detect it from my program.

Was it helpful?

Solution

I found a hack that works for me. Setting an error handlers log level to 0 only allows error messages through. Overwriting the MessageHandler's print method then allows to react to the error. This workaround is definitely a hack. If anyone has any better suggestions, I'd be happy to accept a different answer.

class ErrorCatchingCoinMessageHandler: public CoinMessageHandler {
public:
    ErrorCatchingCoinMessageHandler()
        : CoinMessageHandler() {
        // Would be nice to also overwrite setLogLevel to avoid later changes
        // but its not virtual
        setLogLevel(0);
    }

    virtual int print() __attribute__((noreturn)) {
        CoinMessageHandler::print();
        abort(); // or throw a CoinError
    }
};

// Use it like this

lp_solver->passInMessageHandler(new ErrorCatchingCoinMessageHandler());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top