[Coin-discuss] CoinModel: inconsistency between addRow and getElement

Martin von Gagern Martin.vGagern at gmx.net
Tue May 15 12:49:04 EDT 2007


Hi!

I just stumbled upon what seems a lot like a bug in CoinModel to me.

#include <iostream>
#include <CoinModel.hpp>

int main() {
  CoinModel model;
  for (int row = 0; row < 2; ++row) {
    int columns[2];
    double elements[2];
    for (int col = 0; col < 2; ++col) {
      columns[col] = col;
      elements[col] = 10 * row + col + 11;
    }
    model.addRow(2, columns, elements);
  }
  for (int row = 0; row < model.numberRows(); ++row) {
    for (int col = 0; col < model.numberColumns(); ++col) {
      std::cout << model.getElement(row, col) << '\t';
    }
    std::cout << std::endl;
  }
  model.writeMps("test.mps");
}

This program outputs the matrix
0	0
0	0
although the written MPS file correctly contains the matrix
11	12
21	22

Using setElement instead of addRow seems to work better.

In case it is intentional not to update any hashes when elemnts are
added rowwise, this fact might be stored in some flag, to make
getElement fail (e.g. using an assertion) instead of behave
inconsistently. Also there should be a method to manually start hashing.
 Or is there already such a method? I found none.

Greetings,
 Martin von Gagern

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: <http://list.coin-or.org/pipermail/coin-discuss/attachments/20070515/c5ab1452/attachment.sig>


More information about the Coin-discuss mailing list