/home/coin/SVN-release/OS-1.0.0/OS/src/OSUtils/MathUtil.cpp

Go to the documentation of this file.
00001 
00019 #include "OSDataStructures.h" 
00020 #include "MathUtil.h"
00021 #include <iostream>
00022 
00023 
00024 
00025 MathUtil::MathUtil(){
00026 }
00027 
00028 MathUtil::~MathUtil(){
00029 }
00030 
00031 
00032  
00033 SparseMatrix* MathUtil::convertLinearConstraintCoefficientMatrixToTheOtherMajor(
00034         bool isColumnMajor, int startSize, int valueSize, int* start, int* index, 
00035         double* value, int dimension){
00036         if(!start || startSize <= 1 ) return NULL;
00037         if(!value  || !index  ) return NULL;    
00038 
00039         int iStartSize = dimension + 1;
00040         SparseMatrix *matrix ;
00041         matrix = new SparseMatrix( !isColumnMajor, iStartSize, valueSize);              
00042         int i,j, iTemp;
00043         int iNumSource = startSize - 1;
00044         int* miStart = matrix->starts;
00045         int* miIndex = matrix->indexes;
00046         double* mdValue = matrix->values;
00047         
00048         for ( i = 0; i < iStartSize; i++){                      
00049                 miStart [ i ] = 0;
00050         }
00051         // for illustration assume we are converting from column to row major   
00052         // i is indexing columns (variables) and j is indexing row numbers 
00053         for (i = 0; i < iNumSource; i++){       
00054                 for (j = start[i]; j < start[ i + 1 ]; j++){
00055                         // index[ j] is a row index, we have just found an occurance of row index[j]
00056                         // therefore we increase by 1 (or push back) the start of the row indexed by index[j] + 1, 
00057                         // i.e. the start of the next row
00058                         miStart[ index[j] + 1] ++;                              
00059                 }
00060         }
00061         // at this point, miStart[ i] holds the number of columns with a nonzero in row i - 1
00062         // we are not done with the start indicies, if we are here, and we
00063         // knew the correct starting point of row i -1, the correct starting point
00064         // for row i is miStart[i] + miStart [i - 1]
00065         miStart[0] = 0;
00066         for (i = 1; i < iStartSize; i++ ){
00067                 miStart[i] += miStart [i - 1] ;         
00068         }
00069         
00070         // now get the correct values
00071         // again assume we are converting column major to row major
00072         // loop over bariables          
00073         for (i = 0; i < iNumSource; i++){
00074                 // get row indices and values of the A matrix
00075                 for (j = start[i]; j < start[ i + 1 ]; j++){
00076                         iTemp = miStart[ index[j]];
00077                         miIndex [ iTemp] = i;
00078                         mdValue [ iTemp] = value[j];
00079                         miStart[ index[j]] ++;                          
00080                 }                       
00081         } 
00082                 
00083         // miStart[ i] is now equal to miStart[ i + 1], so readjust
00084         for (i = iStartSize - 1; i >= 1; i-- ){
00085                 miStart[i] = miStart [i - 1] ;          
00086         }
00087                 
00088         miStart[0] = 0;
00089         return matrix;          
00090 }//convertLinearConstraintCoefficientMatrixToTheOtherMajor
00091 
00092 
00093 
00094 

Generated on Thu May 15 22:15:05 2008 by  doxygen 1.4.7