dummyVecMatr.cpp
Go to the documentation of this file.
1 /* $Id: dummyVecMatr.cpp 490 2011-01-14 16:07:12Z pbelotti $
2  *
3  * Name: dummyVecMatr.cpp
4  * Author: Pietro Belotti
5  * Purpose: fill in empty or single valued vectors and matrices
6  *
7  * (C) Carnegie-Mellon University, 2008.
8  * This file is licensed under the Eclipse Public License (EPL)
9  */
10 
11 #include "OsiSolverInterface.hpp"
12 #include "CoinPackedVector.hpp"
13 #include "CoinPackedMatrix.hpp"
14 #include "CoinHelperFunctions.hpp"
15 #include "CouennePrecisions.hpp"
16 
17 using namespace Couenne;
18 
19 // take columns of matrix and add each to arrays for matrix under construction
20 void addSubMatr (int *start, int *len, int *ind, double *el,
21  CoinPackedMatrix &A,
22  CoinPackedVector &v,
23  int &cur,
24  int &ncols,
25  int dispM,
26  int dispVec,
27  int finalrow) {
28 
29  const int
30  *aLe = A.getVectorLengths (),
31  *aIn = A.getIndices (),
32  *vIn = v.getIndices (),
33  aCol = A.getMajorDim ();
34 
35  int vNum = v.getNumElements ();
36 
37  const double
38  *aEl = A.getElements (),
39  *vEl = v.getElements ();
40 
41  // add each column
42  for (int i=0; i<aCol; i++, len++) {
43 
44  *start++ = cur;
45  *len = *aLe++;
46 
47  // matrix entries
48  for (int j = 0; j < *len; j++) {
49  *ind++ = dispM + *aIn++;
50  *el++ = *aEl++;
51  }
52 
53  cur += *len;
54 
55  // check if there is a corresponding rhs
56  if (vNum && (*vIn == i)) {
57 
58  ++*len;
59  cur++;
60  *ind++ = dispVec;
61  *el++ = *vEl;
62 
63  vIn++;
64  vEl++;
65  --vNum;
66  }
67 
68  // normalization entry
69  ++*len;
70  cur++;
71  *ind++ = finalrow;
72  *el++ = 1.;
73 
74  ++ncols;
75  }
76 
77  *start = cur;
78 }
79 
80 
81 // debug functions
82 void printMatrix (int nrows, int ncols, int nel,
83  const int *start, const int *len,
84  const int *ind, const double *el) {
85 
86  printf ("------------------- %d rows, %d columns, %d nz\n", nrows, ncols, nel);
87 
88  for (int i=0, cur = 0; i<nrows; i++) {
89 
90  printf ("%2d [%2d -> %2d] (%2d): ", i, start [i], start [i+1] - 1, len [i]);
91 
92  for (int j=0; j < len [i]; j++)
93  printf ("%d ", ind [start [i] + j]);
94 
95  printf (" | --- | ");
96 
97  for (int j=0, indice = 0; j < len [i] && j < 1000; j++) {
98  while (indice < ind [cur]) {indice++; printf (". ");}
99  indice++;
100  printf ("%2g ", el [cur++]);
101  }
102 
103  printf ("\n");
104  }
105  printf ("-#-\n");
106 }
107 
108 void printMatrix (const CoinPackedMatrix *A) {
109 
110  int
111  nrows = A -> getMajorDim (),
112  ncols = A -> getMinorDim (),
113  nel = A -> getNumElements ();
114 
115  const double
116  *el = A -> getElements ();
117 
118  const int
119  *len = A -> getVectorLengths (),
120  *start = A -> getVectorStarts (),
121  *ind = A -> getIndices ();
122 
123  printMatrix (nrows, ncols, nel, start, len, ind, el);
124 }
125 
126 void printLPMatrix (const OsiSolverInterface &si) {
127 
128  // the coefficient matrix
129  const CoinPackedMatrix *A = si.getMatrixByCol ();
130 
131  printMatrix (A);
132 }
void printLPMatrix(const OsiSolverInterface &si)
void printMatrix(int nrows, int ncols, int nel, const int *start, const int *len, const int *ind, const double *el)
static char * j
Definition: OSdtoa.cpp:3622
void addSubMatr(int *start, int *len, int *ind, double *el, CoinPackedMatrix &Astd, CoinPackedVector &rstd, int &cur, int &curCol, int dispM, int dispVec, int nrows)