Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "ColPackHeaders.h"
00022
00023 using namespace std;
00024
00025 namespace ColPack
00026 {
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 int JacobianRecovery2D::DirectRecover_RowCompressedFormat(BipartiteGraphBicoloringInterface* g, double** dp2_RowCompressedMatrix, double** dp2_ColumnCompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, double*** dp3_JacobianValue) {
00074 if(g==NULL) {
00075 cerr<<"g==NULL"<<endl;
00076 return _FALSE;
00077 }
00078
00079 if(AF_available) {
00080 cout<<"AF_available="<<AF_available<<endl; Pause();
00081 reset();
00082 }
00083
00084 int rowCount = g->GetRowVertexCount();
00085
00086 vector<int> vi_LeftVertexColors;
00087 g->GetLeftVertexColors(vi_LeftVertexColors);
00088
00089 vector<int> RightVertexColors_Transformed;
00090 g->GetRightVertexColors_Transformed(RightVertexColors_Transformed);
00091
00092 int i_ColumnColorCount = g->GetRightVertexColorCount();
00093 if (g->GetRightVertexDefaultColor() == 1) i_ColumnColorCount--;
00094
00095
00096 int** colorStatistic = new int*[rowCount];
00097
00098
00099 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00100 colorStatistic[i] = new int[i_ColumnColorCount];
00101 for(unsigned int j=0; j < (unsigned int)i_ColumnColorCount; j++) colorStatistic[i][j] = 0;
00102 }
00103
00104
00105 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00106 int numOfNonZeros = uip2_JacobianSparsityPattern[i][0];
00107 for(unsigned int j=1; j <= (unsigned int)numOfNonZeros; j++) {
00108
00109
00110 if (RightVertexColors_Transformed[uip2_JacobianSparsityPattern[i][j]] > 0) {
00111 colorStatistic[i][RightVertexColors_Transformed[uip2_JacobianSparsityPattern[i][j]]-1]++;
00112 }
00113 }
00114 }
00115
00116
00117
00118 *dp3_JacobianValue = new double*[rowCount];
00119 for(int i=0; i < rowCount; i++) {
00120 int numOfNonZeros = uip2_JacobianSparsityPattern[i][0];
00121 (*dp3_JacobianValue)[i] = new double[numOfNonZeros+1];
00122 (*dp3_JacobianValue)[i][0] = numOfNonZeros;
00123 for(int j=1; j <= numOfNonZeros; j++) (*dp3_JacobianValue)[i][j] = 0.;
00124 }
00125
00126
00127
00128 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00129 unsigned int numOfNonZeros = uip2_JacobianSparsityPattern[i][0];
00130 for(unsigned int j=1; j <= numOfNonZeros; j++) {
00131
00132
00133 if (RightVertexColors_Transformed[uip2_JacobianSparsityPattern[i][j]] > 0 &&
00134 colorStatistic[i][RightVertexColors_Transformed[uip2_JacobianSparsityPattern[i][j]] - 1]==1
00135 ) {
00136
00137
00138 (*dp3_JacobianValue)[i][j] = dp2_ColumnCompressedMatrix[i][RightVertexColors_Transformed[uip2_JacobianSparsityPattern[i][j]]-1];
00139 }
00140 else {
00141
00142
00143 (*dp3_JacobianValue)[i][j] = dp2_RowCompressedMatrix[vi_LeftVertexColors[i]-1][uip2_JacobianSparsityPattern[i][j]];
00144 }
00145 }
00146
00147 }
00148
00149
00150 free_2DMatrix(colorStatistic, rowCount);
00151 colorStatistic = NULL;
00152
00153 AF_available = true;
00154 i_AF_rowCount = rowCount;
00155 dp2_AF_Value = *dp3_JacobianValue;
00156
00157 return _TRUE;
00158 }
00159
00160
00161
00162
00163 int JacobianRecovery2D::DirectRecover_SparseSolversFormat(BipartiteGraphBicoloringInterface* g, double** dp2_RowCompressedMatrix, double** dp2_ColumnCompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) {
00164 if(g==NULL) {
00165 cerr<<"g==NULL"<<endl;
00166 return _FALSE;
00167 }
00168
00169 if(SSF_available) {
00170 cout<<"SSF_available="<<SSF_available<<endl; Pause();
00171 reset();
00172 }
00173
00174 int rowCount = g->GetRowVertexCount();
00175
00176 vector<int> vi_LeftVertexColors;
00177 g->GetLeftVertexColors(vi_LeftVertexColors);
00178
00179 vector<int> RightVertexColors_Transformed;
00180 g->GetRightVertexColors_Transformed(RightVertexColors_Transformed);
00181
00182 int i_ColumnColorCount = g->GetRightVertexColorCount();
00183 if (g->GetRightVertexDefaultColor() == 1) i_ColumnColorCount--;
00184
00185
00186
00187 int** colorStatistic = new int*[rowCount];
00188
00189
00190 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00191 colorStatistic[i] = new int[i_ColumnColorCount];
00192 for(unsigned int j=0; j < (unsigned int)i_ColumnColorCount; j++) colorStatistic[i][j] = 0;
00193 }
00194
00195
00196 unsigned int numOfNonZeros = 0;
00197 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00198 numOfNonZeros = (unsigned int)uip2_JacobianSparsityPattern[i][0];
00199 for(unsigned int j=1; j <= numOfNonZeros; j++) {
00200
00201
00202 if (RightVertexColors_Transformed[uip2_JacobianSparsityPattern[i][j]] > 0) {
00203 colorStatistic[i][RightVertexColors_Transformed[uip2_JacobianSparsityPattern[i][j]]-1]++;
00204 }
00205 }
00206 }
00207
00208
00209
00210 g->GetRowVertices(ip2_RowIndex);
00211 numOfNonZeros = g->GetColumnIndices(ip2_ColumnIndex);
00212
00213
00214
00215 (*dp2_JacobianValue) = new double[numOfNonZeros];
00216 for(unsigned int i=0; i < numOfNonZeros; i++) (*dp2_JacobianValue)[i] = 0.;
00217
00218
00219
00220
00221 unsigned int numOfNonZerosInEachRow = 0;
00222 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00223 numOfNonZerosInEachRow = uip2_JacobianSparsityPattern[i][0];
00224 for(unsigned int j=1; j <= numOfNonZerosInEachRow; j++) {
00225
00226
00227 if (RightVertexColors_Transformed[uip2_JacobianSparsityPattern[i][j]] > 0 &&
00228 colorStatistic[i][RightVertexColors_Transformed[uip2_JacobianSparsityPattern[i][j]] - 1]==1
00229 ) {
00230
00231
00232 (*dp2_JacobianValue)[(*ip2_RowIndex)[i]+j-1] = dp2_ColumnCompressedMatrix[i][RightVertexColors_Transformed[uip2_JacobianSparsityPattern[i][j]]-1];
00233 }
00234 else {
00235
00236
00237 (*dp2_JacobianValue)[(*ip2_RowIndex)[i]+j-1] = dp2_RowCompressedMatrix[vi_LeftVertexColors[i]-1][uip2_JacobianSparsityPattern[i][j]];
00238 }
00239 }
00240
00241 }
00242
00243
00244
00245
00246 for(unsigned int i=0; i <= (unsigned int) rowCount ; i++) {
00247 (*ip2_RowIndex)[i]++;
00248 }
00249 for(unsigned int i=0; i < numOfNonZeros; i++) {
00250 (*ip2_ColumnIndex)[i]++;
00251 }
00252
00253
00254 free_2DMatrix(colorStatistic, rowCount);
00255 colorStatistic = NULL;
00256
00257 SSF_available = true;
00258 i_SSF_rowCount = rowCount;
00259 ip_SSF_RowIndex = *ip2_RowIndex;
00260 ip_SSF_ColumnIndex = *ip2_ColumnIndex;
00261 dp_SSF_Value = *dp2_JacobianValue;
00262
00263 return _TRUE;
00264 }
00265
00266
00267
00268
00269
00270 int JacobianRecovery2D::DirectRecover_CoordinateFormat(BipartiteGraphBicoloringInterface* g, double** dp2_RowCompressedMatrix, double** dp2_ColumnCompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) {
00271 if(g==NULL) {
00272 cerr<<"g==NULL"<<endl;
00273 return _FALSE;
00274 }
00275
00276 if(CF_available) reset();
00277
00278 int rowCount = g->GetRowVertexCount();
00279
00280 vector<int> vi_LeftVertexColors;
00281 g->GetLeftVertexColors(vi_LeftVertexColors);
00282
00283 vector<int> RightVertexColors_Transformed;
00284 g->GetRightVertexColors_Transformed(RightVertexColors_Transformed);
00285
00286 int i_ColumnColorCount = g->GetRightVertexColorCount();
00287 if (g->GetRightVertexDefaultColor() == 1) i_ColumnColorCount--;
00288
00289
00290 int** colorStatistic = new int*[rowCount];
00291
00292
00293 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00294 colorStatistic[i] = new int[i_ColumnColorCount];
00295 for(unsigned int j=0; j < (unsigned int)i_ColumnColorCount; j++) colorStatistic[i][j] = 0;
00296 }
00297
00298
00299 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00300 int numOfNonZeros = uip2_JacobianSparsityPattern[i][0];
00301 for(unsigned int j=1; j <= (unsigned int)numOfNonZeros; j++) {
00302
00303
00304 if (RightVertexColors_Transformed[uip2_JacobianSparsityPattern[i][j]] > 0) {
00305 colorStatistic[i][RightVertexColors_Transformed[uip2_JacobianSparsityPattern[i][j]]-1]++;
00306 }
00307 }
00308 }
00309
00310 unsigned int numOfNonZeros = g->GetEdgeCount();
00311 (*ip2_RowIndex) = new unsigned int[numOfNonZeros];
00312 (*ip2_ColumnIndex) = new unsigned int[numOfNonZeros];
00313 (*dp2_JacobianValue) = new double[numOfNonZeros];
00314
00315
00316
00317 unsigned int numOfNonZeros_count = 0;
00318 for(unsigned int i=0; i < (unsigned int)rowCount; i++) {
00319 unsigned int numOfNonZeros = uip2_JacobianSparsityPattern[i][0];
00320 for(unsigned int j=1; j <= numOfNonZeros; j++) {
00321
00322
00323 if (RightVertexColors_Transformed[uip2_JacobianSparsityPattern[i][j]] > 0 &&
00324 colorStatistic[i][RightVertexColors_Transformed[uip2_JacobianSparsityPattern[i][j]] - 1]==1
00325 ) {
00326
00327
00328 (*dp2_JacobianValue)[numOfNonZeros_count] = dp2_ColumnCompressedMatrix[i][RightVertexColors_Transformed[uip2_JacobianSparsityPattern[i][j]]-1];
00329 }
00330 else {
00331
00332
00333 (*dp2_JacobianValue)[numOfNonZeros_count] = dp2_RowCompressedMatrix[vi_LeftVertexColors[i]-1][uip2_JacobianSparsityPattern[i][j]];
00334 }
00335 (*ip2_RowIndex)[numOfNonZeros_count] = i;
00336 (*ip2_ColumnIndex)[numOfNonZeros_count] = uip2_JacobianSparsityPattern[i][j];
00337 numOfNonZeros_count++;
00338 }
00339
00340 }
00341
00342
00343 free_2DMatrix(colorStatistic, rowCount);
00344 colorStatistic = NULL;
00345
00346 CF_available = true;
00347 i_CF_rowCount = rowCount;
00348 ip_CF_RowIndex = *ip2_RowIndex;
00349 ip_CF_ColumnIndex = *ip2_ColumnIndex;
00350 dp_CF_Value = *dp2_JacobianValue;
00351
00352 return _TRUE;
00353 }
00354 }