/home/coin/SVN-release/OS-2.1.1/Couenne/src/disjunctive/dummyVecMatr.cpp

Go to the documentation of this file.
00001 /* $Id: dummyVecMatr.cpp 141 2009-06-03 04:19:19Z pbelotti $ */
00002 /*
00003  * Name:    dummyVecMatr.cpp
00004  * Author:  Pietro Belotti
00005  * Purpose: fill in empty or single valued vectors and matrices
00006  *
00007  * (C) Carnegie-Mellon University, 2008. 
00008  * This file is licensed under the Common Public License (CPL)
00009  */
00010 
00011 #include "OsiSolverInterface.hpp"
00012 #include "CoinPackedVector.hpp"
00013 #include "CoinPackedMatrix.hpp"
00014 #include "CoinHelperFunctions.hpp"
00015 #include "CouennePrecisions.hpp"
00016 
00017 
00018 // take columns of matrix and add each to arrays for matrix under construction
00019 void addSubMatr (int *start, int *len, int *ind, double *el,
00020                  CoinPackedMatrix &A, 
00021                  CoinPackedVector &v, 
00022                  int &cur,
00023                  int &ncols,
00024                  int dispM, 
00025                  int dispVec, 
00026                  int finalrow) {
00027 
00028   const int 
00029     *aLe  = A.getVectorLengths (),
00030     *aIn  = A.getIndices  (),
00031     *vIn  = v.getIndices  (),
00032      aCol = A.getMajorDim ();
00033 
00034   int vNum = v.getNumElements ();
00035 
00036   const double 
00037     *aEl = A.getElements (),
00038     *vEl = v.getElements ();
00039 
00040   // add each column
00041   for (int i=0; i<aCol; i++, len++) {
00042 
00043     *start++ = cur;
00044     *len     = *aLe++;
00045 
00046     // matrix entries
00047     for (int j = 0; j < *len; j++) {
00048       *ind++ = dispM + *aIn++;
00049       *el++  = *aEl++;
00050     }
00051 
00052     cur += *len;
00053 
00054     // check if there is a corresponding rhs
00055     if (vNum && (*vIn == i)) {
00056 
00057       ++*len;
00058       cur++;
00059       *ind++ = dispVec;
00060       *el++  = *vEl;
00061 
00062       vIn++;
00063       vEl++;
00064       --vNum;
00065     }
00066 
00067     // normalization entry
00068     ++*len;
00069     cur++;
00070     *ind++ = finalrow;
00071     *el++  = 1.;
00072 
00073     ++ncols;
00074   }
00075 
00076   *start = cur;
00077 }
00078 
00079 
00080 // debug functions
00081 void printMatrix (int nrows, int ncols, int nel, 
00082                   const int *start, const int *len, 
00083                   const int *ind,   const double *el) {
00084 
00085   printf ("------------------- %d rows, %d columns, %d nz\n", nrows, ncols, nel);
00086 
00087   for (int i=0, cur = 0; i<nrows; i++) {
00088 
00089     printf ("%2d [%2d -> %2d] (%2d): ", i, start [i], start [i+1] - 1, len [i]);
00090 
00091     for (int j=0; j < len [i]; j++)
00092       printf ("%d ", ind [start [i] + j]);
00093 
00094     printf (" | --- | ");
00095 
00096     for (int j=0, indice = 0; j < len [i] && j < 1000; j++) {
00097       while (indice < ind [cur]) {indice++; printf (". ");}
00098       indice++;
00099       printf ("%2g ", el [cur++]);
00100     }
00101 
00102     printf ("\n");
00103   }
00104   printf ("-#-\n");
00105 }
00106 
00107 void printMatrix (const CoinPackedMatrix *A) {
00108 
00109   int 
00110     nrows = A -> getMajorDim    (),
00111     ncols = A -> getMinorDim    (),
00112     nel   = A -> getNumElements ();
00113 
00114   const double
00115     *el  = A -> getElements  ();
00116 
00117   const int
00118     *len   = A -> getVectorLengths (),
00119     *start = A -> getVectorStarts  (),
00120     *ind   = A -> getIndices       ();
00121 
00122   printMatrix (nrows, ncols, nel, start, len, ind, el);
00123 }
00124 
00125 void printLPMatrix (const OsiSolverInterface &si) {
00126 
00127   // the coefficient matrix
00128   const CoinPackedMatrix *A = si.getMatrixByCol ();
00129 
00130   printMatrix (A);
00131 }

Generated on Mon May 3 03:05:19 2010 by  doxygen 1.4.7