coin-or/Clp

Using a CoinBuild to add a batch of columns results in 2 times the columns being added to the ClpPackedMatrix

Closed this issue · 1 comments

I'm trying to use a CoinBuild to add a batch of columns in a ClpModel, because adding them one by one is inefficient.
Calling initialSolve after results in a CoinError "Bad new colnum (less than current)".

When I tried to debug it, I found that when I'm adding all the columns from my CoinBuild object into the ClpModel, the columns are being added two times in the ClpPackedMatrix. The "majorDim_" variable of the matrix is set to 108 instead of 54 columns added, hence the CoinError thrown after.

Here is the code I'm using to add my columns in batch.

CoinBuild* BuildObject = NULL;

[...]

COINLIBAPI int COINLINKAGE AddOneColumn(const double colLower, 
    const double colUpper, const double objective,
    const int* rows, const double* elements) {
    if (BuildObject == NULL) {
        BuildObject = new CoinBuild(1);
    }

    BuildObject->addColumn(1, rows, elements, colLower, colUpper, objective);
    return 0;
}

COINLIBAPI int COINLINKAGE BuildAllColumns(Clp_Simplex* model) {
    if (BuildObject != NULL) {
        int result = model->model_->addColumns(*BuildObject);

        delete BuildObject;
        BuildObject = NULL;

        return result;
    }

    return 0;
}

Duplicate of #130