[Coin-discuss] bringing a matrix into block angular form

Matthew Galati Matthew.Galati at sas.com
Thu Sep 24 14:35:12 EDT 2009


FYI. The following seems to work. Feel free to add to some CoinUtils code or maybe there should be a repository for "scripts"?


// to build:
// g++ main.cpp -L ~/COIN/coin-Decomp/build-g/lib -I ~/COIN/coin-Decomp/build-g\
/include/coin -lCoinUtils

// mps to matrix-market format
//   http://math.nist.gov/MatrixMarket/formats.html#mtx


#include "CoinMpsIO.hpp"
#include "CoinPackedMatrix.hpp"

#include <string>
#include <fstream>
#include <iomanip>
using namespace std;

int main(int argc, char ** argv){

   CoinMpsIO mps;
   mps.readMps(argv[1]);

   const CoinPackedMatrix * mat   = mps.getMatrixByCol();
   const int                nCols = mat->getNumCols();
   const int                nRows = mat->getNumRows();
   const int                nEls  = mat->getNumElements();
   const double           * els   = mat->getElements();
   const int              * ind   = mat->getIndices();
   const int              * beg   = mat->getVectorStarts();
   const int              * len   = mat->getVectorLengths();

   string mmName = (string)(argv[1]) + ".mtx";
   ofstream os(mmName.c_str());

   os << "%%MatrixMarket matrix coordinate real general" << endl;
   os << "%From mps file: " << argv[1] << endl;
   os << nRows << " " << nCols << " " << nEls << endl;

   int            lenI = 0;
   const int    * indI = NULL;
   const double * elsI = NULL;

   os << setiosflags(ios::fixed|ios::showpoint);
   os << setprecision(7);

   int i,k;
   for(i = 0; i < nCols; i++){
      lenI = len[i];
      indI = ind + beg[i];
      elsI = els + beg[i];
      for(k = 0; k < lenI; k++){
         os << indI[k]+1 << " " << i+1 << " " << elsI[k] << endl;
      }
   }







From: coin-discuss-bounces at list.coin-or.org [mailto:coin-discuss-bounces at list.coin-or.org] On Behalf Of magh
Sent: Thursday, September 24, 2009 11:40 AM
To: coin-discuss at list.coin-or.org
Subject: Re: [Coin-discuss] bringing a matrix into block angular form

This looks fairly easy to use so I was going to try it:
  http://www.math.uu.nl/people/bisseling/Mondriaan/

It wants this format:
  http://math.nist.gov/MatrixMarket/formats.html#mtx

Has anyone written a MPS to MatrixMarket format convertor? I just figured I'd ask before I write it - I think it will be easy.

Thanks,
Matt



Has anyone used COIN together with some package (MeTiS? or any other?) to bring a matrix into block angular form? I am looking to read in an MPS file - into OSI or CoinMpsIO or something like this, run one of these heuristic methods and then return the rows/cols in each block.

Thanks,
Matt

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/coin-discuss/attachments/20090924/06a804cb/attachment.html>


More information about the Coin-discuss mailing list