[Osi] [osi] Loading large LP using appendRows( )

John Forrest john.forrest at fastercoin.com
Tue Nov 6 12:15:53 EST 2018


As you copied me on this, I thought I should look at it.  First of all, 
this coding is not mine and the coding in appendRows does not look very 
efficient, so I would try doing it another way.

You are correct that the answer to Q2 is to do with Q1 - information on 
the vectors gets lost.

What seems to work, although I don't like it is -

  CoinPackedVectorBase** rows = new CoinPackedVectorBase*[n_rows];

then after forming coeff_list

     CoinPackedVector * newRow = new CoinPackedVector();
     for (int i = 0; i < numberColumns; i++){
       newRow->insert(i, std::stod(coeff_list[i]));


   matrix->appendRows(n_rows, rows);

Your code looks as if it is inserting zero coefficients - for any large 
problem this is impossible and you should only insert non-zero coefficients.

I would look at Clp/examples/addRows.cpp and use CoinBuild.

John Forrest
On 06/11/2018 13:57, Isaac HUANG wrote:
> Hi,
> I am a new cbc user and I am trying to load large LP using the OSI-CLP 
> interface. I read from the article 
> (https://biarri.com/re-solving-linear-programs-with-coin-or/) and 
> notice that I should better use appendRows() method to load the large LP.
> A relevant part of my code is as follows:
> CoinPackedVector* rows = new CoinPackedVector[n_rows];
> CoinPackedVectorBase* const* rows_ptr = (CoinPackedVectorBase**)(&rows);
> while (getline(constr_file, line)){
> std::vector<std::string> coeff_list;
> std::istringstream coeff_stream(line);
> for (std::string s; coeff_stream >> s;)
> coeff_list.push_back(s);
> for (int i = 0; i < n_cols; i++){
> rows[rowCount].insert(i, std::stod(coeff_list[i]));
> }
> row_lb[rowCount] = (-1) * si->getInfinity();
> row_ub[rowCount] = std::stod(coeff_list[n_cols]);
> rowCount++;
> }
> matrix->appendRows(n_rows, rows_ptr);
> si->loadProblem(*matrix, col_lb, col_ub, objective, row_lb, row_ub);
> the program reads the coefficient from a file, and store them in the 
> array of CoinPackedVector. After loading all these, I tried using 
> appendRows() method.
> Here are my questions:
> Q1: Originally, I thought I shall use matrix->appendRows(n_rows, 
> rows), which looks natural. But the compiler complains that the second 
> argument should be CoinPackedVectorBase * const *, which looks like a 
> pointer to a pointer to CoinPackedVectorBase, so I take the point of 
> rows as the second argument (the second line of my code). This passes 
> the compilation, but I wonder is it the right way?
> Q2: Even my code passes compilation, the execution still prompts 
> segmentation fault when it goes to the line matrix->appendRows(n_rows, 
> rows_ptr). I am pretty sure that I do have n_rows rows in the array, 
> so I wonder why it prompts segmentation fault? Is it related to Q1?
> My cbc is built from compiling the source of CBC 2.9.9 and I am 
> running it on a Linux machine.
> Thank you very much for the help. I appreciate any help or reference 
> to examples regarding the correct use the appendRows()
> All the best,
> Isaac

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/osi/attachments/20181106/695176e0/attachment.html>

More information about the Osi mailing list