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

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

Generated on Thu Nov 10 03:05:44 2011 by  doxygen 1.4.7