c++loggingcoin-or-cbc

How to completely omit CBC loggings in C++?


I'm using the CBC solver to solve a program, and the method model.branchAndBound is called for multiple times(quite many). Because the log messages have to be written to file, so it is actually slowing down the program. I wonder is it possible to ommit the log messages entirely? This is in c++, and I now think that many suggested answer pulp is only possible for python. Also, in case pulp is the solution to this problem I'm not so sure about how pulp is used. Is there any good documentation to help understand the relationship between pulp and CBC, and how to use them? If anyone could help me with this, I'd be real grateful!

For example(this is an example from github):

// Copyright (C) 2009, International Business Machines
// Corporation and others.  All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).
// For Branch and bound
#include "OsiSolverInterface.hpp"
#include "CbcModel.hpp"

// Methods of building

#include "CoinBuild.hpp"
#include "CoinModel.hpp"

int main(int argc, const char *argv[])
{
    OsiClpSolverInterface model;
    double objValue[] = { 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, -1.0 };
    // Lower bounds for columns
    double columnLower[] = { 2.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0 };
    // Upper bounds for columns
    double columnUpper[] = { COIN_DBL_MAX, 4.1, 1.0, 1.0, 4.0,
    COIN_DBL_MAX, COIN_DBL_MAX, 4.3 };
    // Lower bounds for row activities
    double rowLower[] = { 2.5, -COIN_DBL_MAX, 4.0, 1.8, 3.0 };
    // Upper bounds for row activities
    double rowUpper[] = { COIN_DBL_MAX, 2.1, 4.0, 5.0, 15.0 };
    // Matrix stored packed
    int column[] = { 0, 1, 3, 4, 7,
    1, 2,
    2, 5,
    3, 6,
    0, 4, 7 };
    double element[] = { 3.0, 1.0, -2.0, -1.0, -1.0,
    2.0, 1.1,
    1.0, 1.0,
    2.8, -1.2,
    5.6, 1.0, 1.9 };
    int starts[] = { 0, 5, 7, 9, 11, 14 };
    // Integer variables (note upper bound already 1.0)
    int whichInt[] = { 2, 3 };
    int numberRows = (int)(sizeof(rowLower) / sizeof(double));
    int numberColumns = (int)(sizeof(columnLower) / sizeof(double));
    CoinModel build;
    // First do columns (objective and bounds)
    int i;
    for (i = 0; i < numberColumns; i++) {
    build.setColumnBounds(i, columnLower[i], columnUpper[i]);
    build.setObjective(i, objValue[i]);
    }
    // mark as integer
    for (i = 0; i < (int)(sizeof(whichInt) / sizeof(int)); i++)
    build.setInteger(whichInt[i]);
    // Now build rows
    for (i = 0; i < numberRows; i++) {
    int startRow = starts[i];
    int numberInRow = starts[i + 1] - starts[i];
    build.addRow(numberInRow, column + startRow, element + startRow,
        rowLower[i], rowUpper[i]);
    }
    // add rows into solver
    model.loadFromCoinModel(build);
    CbcModel model2(model);
    model2.branchAndBound();
    return 0;
}

and the log outputs are:

Clp0000I Optimal - objective value 3.2368421
Clp0000I Optimal - objective value 3.2368421
Node 0 depth 0 unsatisfied 0 sum 0 obj 3.23684 guess 3.23684 branching on -1
Clp0000I Optimal - objective value 3.2368421
Cbc0004I Integer solution of 3.2368421 found after 0 iterations and 0 nodes (0.13 seconds)
Cbc0001I Search completed - best objective 3.236842105263158, took 0 iterations and 0 nodes (0.14 seconds)
Cbc0035I Maximum depth 0, 0 variables fixed on reduced cost
Clp0000I Optimal - objective value 3.2368421
Clp0000I Optimal - objective value 3.2368421

Solution

  • Adding this to the code solves everything:

    model.setLogLevel(0);