Changeset a7efc97 in git
- Timestamp:
- Jan 11, 2010, 1:19:18 PM (13 years ago)
- Branches:
- (u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
- Children:
- 230d827d0f5f0d0063755ae4baf1c60f8945d447
- Parents:
- 9524c6afef1a341d40fe3a65abdd25dd91db5ff2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/gfan.cc
r9524c6 ra7efc97 661 661 aktpoly=pNext(aktpoly); 662 662 int *tailexpv=(int*)omAlloc(((this->numVars)+1)*sizeof(int)); 663 pGetExpV(aktpoly,tailexpv); 663 pGetExpV(aktpoly,tailexpv); 664 664 for(int kk=1;kk<=this->numVars;kk++) 665 { 665 { 666 666 dd_set_si(ddineq->matrix[(dd_rowrange)aktmatrixrow][kk],leadexpv[kk]-tailexpv[kk]); 667 667 } … … 990 990 dd_MatrixPtr ddakt; 991 991 ddakt = dd_CopyMatrix(ddineq); 992 ddakt->representation=dd_Inequality; 992 // ddakt->representation=dd_Inequality; //Not using this makes it faster. But why does the quick check below still work? 993 993 set_addelem(ddakt->linset,ii+1);/*Now set appropriate linearity*/ 994 994 #ifdef gfanp … … 996 996 gettimeofday(&t_ddMC_start,0); 997 997 #endif 998 / *dd_MatrixCanonicalize(&ddakt, &impl_linset, &redset, &newpos, &err);*/998 //dd_MatrixCanonicalize(&ddakt, &impl_linset, &redset, &newpos, &err); 999 999 // set_copy(LL,ddakt->linset); 1000 1000 dd_PolyhedraPtr ddpolyh; 1001 1001 ddpolyh=dd_DDMatrix2Poly(ddakt, &err); 1002 // ddpolyh=dd_DDMatrix2Poly2(ddakt, dd_MaxCutoff, &err); 1002 1003 dd_MatrixPtr P; 1003 P=dd_CopyGenerators(ddpolyh); 1004 P=dd_CopyGenerators(ddpolyh); 1004 1005 dd_FreePolyhedra(ddpolyh); 1006 // ddpolyh=dd_DDMatrix2Poly(P,&err); 1007 // dd_MatrixPtr R; 1008 // R=dd_CopyInequalities(ddpolyh); 1009 // dd_FreePolyhedra(ddpolyh); 1005 1010 #ifdef gfanp 1006 1011 gettimeofday(&t_ddMC_end,0); … … 1047 1052 * linearity for ddakt above. 1048 1053 */ 1049 intvec *iv_intPoint = new intvec(this->numVars); 1050 dd_MatrixPtr shiftMatrix; 1051 dd_MatrixPtr intPointMatrix; 1052 shiftMatrix = dd_CreateMatrix(this->numVars,this->numVars+1); 1053 for(int kk=0;kk<this->numVars;kk++) 1054 { 1055 dd_set_si(shiftMatrix->matrix[kk][0],1); 1056 dd_set_si(shiftMatrix->matrix[kk][kk+1],1); 1057 } 1058 intPointMatrix=dd_MatrixAppend(ddakt,shiftMatrix); 1054 // intvec *iv_intPoint = new intvec(this->numVars); 1055 // dd_MatrixPtr shiftMatrix; 1056 // dd_MatrixPtr intPointMatrix; 1057 // shiftMatrix = dd_CreateMatrix(this->numVars,this->numVars+1); 1058 // for(int kk=0;kk<this->numVars;kk++) 1059 // { 1060 // dd_set_si(shiftMatrix->matrix[kk][0],1); 1061 // dd_set_si(shiftMatrix->matrix[kk][kk+1],1); 1062 // } 1063 // intPointMatrix=dd_MatrixAppend(ddakt,shiftMatrix); 1064 // #ifdef gfanp 1065 // timeval t_iP_start, t_iP_end; 1066 // gettimeofday(&t_iP_start, 0); 1067 // #endif 1068 // interiorPoint(intPointMatrix,*iv_intPoint); 1069 // // dd_rowset impl_linste,lbasis; 1070 // // dd_LPSolutionPtr lps=NULL; 1071 // // dd_ErrorType err; 1072 // // dd_FindRelativeInterior(intPointMatrix, &impl_linset, &lbasis, &lps, &err); 1073 // #ifdef gfanp 1074 // gettimeofday(&t_iP_end, 0); 1075 // t_iP += (t_iP_end.tv_sec - t_iP_start.tv_sec + 1e-6*(t_iP_end.tv_usec - t_iP_start.tv_usec)); 1076 // #endif 1077 // for(int ll=0;ll<this->numVars;ll++) 1078 // { 1079 // if( (*iv_intPoint)[ll] < 0 ) 1080 // { 1081 // fAct->isFlippable=FALSE; 1082 // break; 1083 // } 1084 // } 1085 /*End of check*/ 1086 /*This test should be way less time consuming*/ 1059 1087 #ifdef gfanp 1060 1088 timeval t_iP_start, t_iP_end; 1061 1089 gettimeofday(&t_iP_start, 0); 1062 #endif 1063 interiorPoint(intPointMatrix,*iv_intPoint); 1064 // dd_rowset impl_linste,lbasis; 1065 // dd_LPSolutionPtr lps=NULL; 1066 // dd_ErrorType err; 1067 // dd_FindRelativeInterior(intPointMatrix, &impl_linset, &lbasis, &lps, &err); 1090 #endif 1091 bool containsStrictlyPosRay=TRUE; 1092 for(int ii=0;ii<ddakt->rowsize;ii++) 1093 { 1094 containsStrictlyPosRay=TRUE; 1095 for(int jj=1;jj<this->numVars;jj++) 1096 { 1097 if(ddakt->matrix[ii][jj]<=0) 1098 { 1099 containsStrictlyPosRay=FALSE; 1100 break; 1101 } 1102 } 1103 if(containsStrictlyPosRay==TRUE) 1104 break; 1105 } 1106 if(containsStrictlyPosRay==FALSE) 1107 fAct->isFlippable=FALSE; 1068 1108 #ifdef gfanp 1069 1109 gettimeofday(&t_iP_end, 0); 1070 1110 t_iP += (t_iP_end.tv_sec - t_iP_start.tv_sec + 1e-6*(t_iP_end.tv_usec - t_iP_start.tv_usec)); 1071 1111 #endif 1072 for(int ll=0;ll<this->numVars;ll++) 1073 { 1074 if( (*iv_intPoint)[ll] < 0 ) 1075 { 1076 fAct->isFlippable=FALSE; 1077 break; 1078 } 1079 } 1080 /*End of check*/ 1112 /**/ 1081 1113 fAct = fAct->next; 1082 1114 dd_FreeMatrix(ddakt); 1083 dd_FreeMatrix(shiftMatrix);1084 dd_FreeMatrix(intPointMatrix);1085 delete iv_intPoint;1115 // dd_FreeMatrix(shiftMatrix); 1116 // dd_FreeMatrix(intPointMatrix); 1117 // delete iv_intPoint; 1086 1118 dd_FreeMatrix(P); 1087 1119 // set_free(impl_linset); … … 1288 1320 markingsAreCorrect=TRUE; 1289 1321 } 1290 1322 int ctr=0; 1291 1323 for (int jj=0;jj<this->numVars;jj++) 1292 1324 { 1293 /*Store into ddMatrix*/ 1325 /*Store into ddMatrix*/ 1326 if(leadExpV[jj+1]-v[jj+1]) 1327 ctr++; 1294 1328 dd_set_si(intPointMatrix->matrix[aktrow][jj+1],leadExpV[jj+1]-v[jj+1]); 1295 1329 } 1296 aktrow +=1; 1330 /*It ought to be more sensible to avoid 0-rows in the first place*/ 1331 // if(ctr==this->numVars)//We have a 0-row 1332 // dd_MatrixRowRemove(&intPointMatrix,aktrow); 1333 // else 1334 aktrow +=1; 1297 1335 omFree(v); 1298 1336 } … … 1306 1344 /*Now it is safe to idDelete(H)*/ 1307 1345 idDelete(&H); 1346 /*Preprocessing goes here since otherwise we would delete the constraint 1347 * for the standard simplex. 1348 */ 1349 preprocessInequalities(intPointMatrix); 1308 1350 /*Now we add the constraint for the standard simplex*/ 1309 // #ifdef gfanp 1310 // timeval t_dd_start, t_dd_end; 1311 // gettimeofday(&t_dd_start, 0); 1312 // #endif 1313 dd_set_si(intPointMatrix->matrix[aktrow][0],-1); 1314 for (int jj=1;jj<=this->numVars;jj++) 1315 { 1316 dd_set_si(intPointMatrix->matrix[aktrow][jj],1); 1317 } 1351 // dd_set_si(intPointMatrix->matrix[aktrow][0],-1); 1352 // for (int jj=1;jj<=this->numVars;jj++) 1353 // { 1354 // dd_set_si(intPointMatrix->matrix[aktrow][jj],1); 1355 // } 1318 1356 //Let's make sure we compute interior points from the positive orthant 1319 dd_MatrixPtr posRestr=dd_CreateMatrix(this->numVars,this->numVars+1); 1320 1321 int jj=1; 1322 for (int ii=0;ii<this->numVars;ii++) 1323 { 1324 dd_set_si(posRestr->matrix[ii][jj],1); 1325 jj++; 1326 } 1357 // dd_MatrixPtr posRestr=dd_CreateMatrix(this->numVars,this->numVars+1); 1358 // 1359 // int jj=1; 1360 // for (int ii=0;ii<this->numVars;ii++) 1361 // { 1362 // dd_set_si(posRestr->matrix[ii][jj],1); 1363 // jj++; 1364 // } 1365 /*We create a matrix containing the standard simplex 1366 * and constraints to assure a strictly positive point 1367 * is computed 1368 */ 1369 dd_MatrixPtr posRestr = dd_CreateMatrix(this->numVars+1, this->numVars+1); 1370 for(int ii=0;ii<posRestr->rowsize;ii++) 1371 { 1372 if(ii==0) 1373 { 1374 dd_set_si(posRestr->matrix[ii][0],-1); 1375 for(int jj=1;jj<=this->numVars;jj++) 1376 dd_set_si(posRestr->matrix[ii][jj],1); 1377 } 1378 else 1379 { 1380 dd_set_si(posRestr->matrix[ii][0],-1); 1381 dd_set_si(posRestr->matrix[ii][ii],1); 1382 } 1383 } 1384 /**/ 1327 1385 dd_MatrixAppendTo(&intPointMatrix,posRestr); 1328 1386 dd_FreeMatrix(posRestr); … … 1330 1388 * Otherwise things will go pear shaped if called after the standard simplex constraints are added 1331 1389 */ 1332 preprocessInequalities(intPointMatrix);1390 // preprocessInequalities(intPointMatrix); 1333 1391 intvec *iv_weight = new intvec(this->numVars); 1334 1392 #ifdef gfanp … … 1341 1399 1342 1400 // dd_MatrixCanonicalize(&intPointMatrix,&implLin,&redrows,&newpos,&err); 1343 dd_MatrixCanonicalizeLinearity(&intPointMatrix,&implLin, &newpos,&err);1401 // dd_MatrixCanonicalizeLinearity(&intPointMatrix,&implLin, &newpos,&err); 1344 1402 //dd_MatrixRedundancyRemove is our time sink! 1345 1403 // dd_MatrixRedundancyRemove(&intPointMatrix,&redrows,&newpos,&err); … … 1538 1596 void gcone::preprocessInequalities(dd_MatrixPtr &ddineq) 1539 1597 { 1540 //Remove strictly positive rows 1541 int *posRowsArray=NULL; 1598 /* int *posRowsArray=NULL; 1542 1599 int num_alloc=0; 1543 1600 int num_elts=0; 1544 // for(int ii=0;ii<ddineq->rowsize;ii++) 1545 // { 1546 // intvec *ivPos = new intvec(pVariables); 1547 // for(int jj=0;jj<pVariables;jj++) 1548 // (*ivPos)[jj]=(int)mpq_get_d(ddineq->matrix[ii][jj+1]); 1549 // bool isStrictlyPos=FALSE; 1550 // int posCtr=0; 1551 // for(int jj=0;jj<pVariables;jj++) 1552 // { 1553 // intvec *ivCanonical = new intvec(pVariables); 1554 // jj==0 ? (*ivCanonical)[ivPos->length()-1]=1 : (*ivCanonical)[jj-1]=1; 1555 // if(dotProduct(*ivCanonical,*ivPos)!=0) 1556 // { 1557 // if ((*ivPos)[jj]>=0) 1558 // { 1559 // posCtr++; 1560 // } 1561 // } 1562 // delete ivCanonical; 1563 // } 1564 // if(posCtr==ivPos->length()) 1565 // isStrictlyPos=TRUE; 1566 // if(isStrictlyPos==TRUE) 1567 // { 1568 // if(num_alloc==0) 1569 // num_alloc += 1; 1570 // else 1571 // num_alloc += 1; 1572 // void *tmp = realloc(posRowsArray,(num_alloc*sizeof(int))); 1573 // if(!tmp) 1574 // { 1575 // WerrorS("Woah dude! Couldn't realloc memory\n"); 1576 // exit(-1); 1577 // } 1578 // posRowsArray = (int*)tmp; 1579 // posRowsArray[num_elts]=ii; 1580 // num_elts++; 1581 // } 1582 // delete ivPos; 1583 // } 1584 int offset=0; 1585 // for(int ii=0;ii<num_elts;ii++) 1586 // { 1587 // dd_MatrixRowRemove(&ddineq,posRowsArray[ii]+1-offset); 1588 // offset++; 1589 // } 1590 // free(posRowsArray); 1591 //Remove zeroes 1592 // int rowsize=ddineq->rowsize; 1601 int offset=0;*/ 1602 //Remove zeroes (and strictly pos rows?) 1593 1603 for(int ii=0;ii<ddineq->rowsize;ii++) 1594 1604 { … … 1598 1608 { 1599 1609 (*iv)[jj]=(int)mpq_get_d(ddineq->matrix[ii][jj+1]); 1600 // if((*iv)[ii]>0) 1601 // posCtr++; 1610 if((*iv)[jj]>0)//check for strictly pos rows 1611 posCtr++; 1612 //Behold! This will delete the row for the standard simplex! 1602 1613 } 1603 if( (iv->compare(0)==0) )//|| (posCtr==iv->length()) ) 1614 // if( (iv->compare(0)==0) || (posCtr==iv->length()) ) 1615 if( (posCtr==iv->length()) || (iv->compare(0)==0) ) 1604 1616 { 1605 1617 dd_MatrixRowRemove(&ddineq,ii+1); 1606 ii--; 1607 // rowsize=ddineq->rowsize; 1618 ii--;//Yes. This is on purpose 1608 1619 } 1609 1620 delete iv;
Note: See TracChangeset
for help on using the changeset viewer.