<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Isaac,</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">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.<br>
    </div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">You are correct that the answer to Q2
      is to do with Q1 - information on the vectors gets lost.</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">What seems to work, although I don't
      like it is -</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix"> CoinPackedVectorBase** rows = new
      CoinPackedVectorBase*[n_rows];<br>
    </div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">then after forming coeff_list</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">    CoinPackedVector * newRow = new
      CoinPackedVector();<br>
          rows[rowCount]=newRow;<br>
          for (int i = 0; i < numberColumns; i++){<br>
            newRow->insert(i, std::stod(coeff_list[i]));<br>
          }</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">and</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">  matrix->appendRows(n_rows, rows);</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">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.</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">I would look at
      Clp/examples/addRows.cpp and use CoinBuild.</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">John Forrest<br>
    </div>
    <div class="moz-cite-prefix">On 06/11/2018 13:57, Isaac HUANG wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAJFNqiF1yaV3hcr5TMt86QLYe1J-xb6=QP4Hdea9Sxw=QtKLdw@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div dir="ltr">
          <div dir="ltr">
            <div dir="ltr">Hi,
              <div><br>
              </div>
              <div>I am a new cbc user and I am trying to load large LP
                using the OSI-CLP interface. I read from the article (<a
href="https://biarri.com/re-solving-linear-programs-with-coin-or/"
                  moz-do-not-send="true">https://biarri.com/re-solving-linear-programs-with-coin-or/</a>)
                and notice that I should better use appendRows() method
                to load the large LP.</div>
              <div><br>
              </div>
              <div>A relevant part of my code is as follows:</div>
              <div><br>
              </div>
              <div>
                <div>CoinPackedVector* rows = new
                  CoinPackedVector[n_rows];</div>
                <div>CoinPackedVectorBase* const* rows_ptr =
                  (CoinPackedVectorBase**)(&rows);</div>
                <div><span style="white-space:pre">       </span>while
                  (getline(constr_file, line)){</div>
                <div><span style="white-space:pre">               </span>std::vector<std::string>
                  coeff_list;</div>
                <div><span style="white-space:pre">               </span>std::istringstream
                  coeff_stream(line);</div>
                <div><span style="white-space:pre">               </span>for
                  (std::string s; coeff_stream >> s;)</div>
                <div><span style="white-space:pre">                       </span>coeff_list.push_back(s);</div>
                <div><br>
                </div>
                <div><span style="white-space:pre">               </span>for (int i =
                  0; i < n_cols; i++){</div>
                <div><span style="white-space:pre">                       </span>rows[rowCount].insert(i,
                  std::stod(coeff_list[i]));</div>
                <div><span style="white-space:pre">               </span>}</div>
                <div><br>
                </div>
                <div><span style="white-space:pre">               </span>row_lb[rowCount]
                  = (-1) * si->getInfinity();</div>
                <div><span style="white-space:pre">               </span>row_ub[rowCount]
                  = std::stod(coeff_list[n_cols]);</div>
                <div><br>
                </div>
                <div><br>
                </div>
                <div><span style="white-space:pre">               </span>rowCount++;</div>
                <div><span style="white-space:pre">       </span>}</div>
                <div><br>
                </div>
                <div><span style="white-space:pre">       </span>matrix->appendRows(n_rows,
                  rows_ptr);</div>
                <div><br>
                </div>
                <div><span style="white-space:pre">       </span>si->loadProblem(*matrix,
                  col_lb, col_ub, objective, row_lb, row_ub);</div>
              </div>
              <div><br>
              </div>
              <div>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.</div>
              <div><br>
              </div>
              <div>Here are my questions:</div>
              <div>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?</div>
              <div><br>
              </div>
              <div>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?</div>
              <div><br>
              </div>
              <div>My cbc is built from compiling the source of CBC
                2.9.9 and I am running it on a Linux machine.</div>
              <div><br>
              </div>
              <div>Thank you very much for the help. I appreciate any
                help or reference to examples regarding the correct use
                the appendRows()</div>
              <div><br>
              </div>
              <div>All the best,</div>
              <div>Isaac</div>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <p><br>
    </p>
  </body>
</html>