int32_t pdbm_getInfimum(const PDBM pdbm, cindex_t dim) { assert(pdbm && dim); assert(dbm_isValid(pdbm_matrix(pdbm), dim)); int32_t cache = pdbm_cache(pdbm); if (cache == INVALID) { pdbm_cache((PDBM)pdbm) = cache = pdbm_infimum(pdbm_matrix(pdbm), dim, pdbm_cost(pdbm),pdbm_rates(pdbm)); } return cache; }
bool pdbm_isValid(const PDBM pdbm, cindex_t dim) { assert(dim); if (pdbm == NULL) { return true; } raw_t *dbm = pdbm_matrix(pdbm); int32_t *rates = pdbm_rates(pdbm); int32_t cost = pdbm_cost(pdbm); int32_t cache = pdbm_cache(pdbm); int32_t inf = pdbm_infimum(dbm, dim, cost, rates); return (cache == INVALID || cache == inf) && dbm_isValid(dbm, dim) && rates[0] == 0 && (!pdbm_isUnbounded(pdbm, dim) || pdbm_getSlopeOfDelayTrajectory(pdbm, dim) >= 0); }
/** test shrinkExpand */ static void test_shrinkExpand(uint32_t dim) { uint32_t intSize = bits2intsize(dim); uint32_t tableSize = intSize*32; cindex_t srcTable[tableSize]; cindex_t dstTable[tableSize]; cindex_t checkTable[tableSize]; uint32_t bitString1[intSize]; uint32_t bitString2[intSize]; raw_t *dbm1 = allocDBM(dim); raw_t *dbm2 = allocDBM(dim); uint32_t k; printf("Testing shrinkExpand(%u)\n", dim); for(k = 0; k < 10000; ++k) { cindex_t dim1 = rand()%dim + 1; cindex_t dim2 = rand()%dim + 1; cindex_t i,j; PROGRESS(); test_invalidate(srcTable, tableSize); test_invalidate(dstTable, tableSize); test_invalidate(checkTable, tableSize); /* generate 2 bit tables */ debug_generateBits(bitString1, intSize, dim1, ONE); debug_generateBits(bitString2, intSize, dim2, ONE); assert(base_countBitsN(bitString1, intSize) == dim1); assert(base_countBitsN(bitString2, intSize) == dim2); /* respect precondition */ if (!base_areBitsEqual(bitString1, bitString2, intSize)) { /* generate source DBM */ dbm_generate(dbm1, dim1, 50000); /* unpack */ base_bits2indexTable(bitString1, intSize, srcTable); base_bits2indexTable(bitString2, intSize, checkTable); /* shrinkExpand */ assert(dim2 == dbm_shrinkExpand(dbm1, dbm2, dim1, bitString1, bitString2, intSize, dstTable)); assert(dbm_isValid(dbm2, dim2)); /* check table */ assert(base_areEqual(dstTable, checkTable, intsizeof(cindex_t[dim]))); for(i = 0; i < dim; ++i) { for(j = 0; j < dim; ++j) { /* valid index condition == ~table[i] * because of the invalidate value */ if ((~dstTable[i]) && (~dstTable[j])) { if ((~srcTable[i]) && (~srcTable[j])) { assert(DBM1(srcTable[i], srcTable[j]) == DBM2(dstTable[i], dstTable[j])); } else { if (i == 0 || i == j) { assert(DBM2(dstTable[i], dstTable[j]) == dbm_LE_ZERO); /* new clock */ } else { assert(DBM2(dstTable[i], dstTable[j]) == (j == 0 ? dbm_LS_INFINITY : DBM2(dstTable[i], dstTable[0]))); } } } } } } /* print something to check if (k == 0 && dim1 < 10 && dim2 < 10) { test_debugPrint(dbm1, dim1, dbm2, dim2, srcTable, dstTable, tableSize, 0, 0); } */ } free(dbm2); free(dbm1); }
/* test the 4 extrapolations */ static void test(uint32_t size) { ADBM(dbm1); ADBM(dbm2); ADBM(dbm3); ADBM(dbm4); ADBM(dbm5); ADBM(dbm6); ADBM(dbm7); ADBM(dbm8); ADBM(dbm9); ADBM(dbm10); AVECT(lower); AVECT(upper); AVECT(max); uint32_t k, l; printf("*** Testing size=%u\n", size); for (k = 0; k < 2000; ++k) { PROGRESS(); max[0] = lower[0] = upper[0] = 0; for (l = 1; l < size; l++) { int32_t low = RANGE() - (MAXRANGE / 2); int32_t up = RANGE() - (MAXRANGE / 2); /* low + RANGE()/2; */ lower[l] = (low < 0 ? -dbm_INFINITY : low); upper[l] = (up < 0 ? -dbm_INFINITY : up); max[l] = (lower[l] < upper[l] ? upper[l] : lower[l]); } DBM_GEN(dbm1); dbm_copy(dbm10, dbm1, size); dbm_copy(dbm9, dbm1, size); dbm_copy(dbm8, dbm1, size); dbm_copy(dbm7, dbm1, size); dbm_copy(dbm6, dbm1, size); dbm_copy(dbm5, dbm1, size); dbm_copy(dbm4, dbm1, size); dbm_copy(dbm3, dbm1, size); dbm_copy(dbm2, dbm1, size); assert(dbm_isClosed(dbm1, size)); dbm_extrapolateMaxBounds(dbm2, size, max); dbm_extrapolateLUBounds(dbm3, size, max, max); dbm_extrapolateLUBounds(dbm4, size, lower, upper); dbm_diagonalExtrapolateMaxBounds(dbm5, size, max); test_diagonalExtrapolateMaxBounds(dbm8, size, max); dbm_diagonalExtrapolateLUBounds(dbm6, size, max, max); test_diagonalExtrapolateLUBounds(dbm9, size, max, max); dbm_diagonalExtrapolateLUBounds(dbm7, size, lower, upper); test_diagonalExtrapolateLUBounds(dbm10, size, lower, upper); assert(dbm_areEqual(dbm5, dbm8, size)); assert(dbm_areEqual(dbm6, dbm9, size)); assert(dbm_areEqual(dbm7, dbm10, size)); /* 1 <= 2 == 3 <= 4 <= 7, 1 <= 2 == 3 <= 5 == 6 <= 7 */ assert(dbm_relation(dbm1, dbm2, size) & base_SUBSET); assert(dbm_relation(dbm2, dbm3, size) == base_EQUAL); assert(dbm_relation(dbm3, dbm4, size) & base_SUBSET); assert(dbm_relation(dbm4, dbm7, size) & base_SUBSET); assert(dbm_relation(dbm3, dbm5, size) & base_SUBSET); assert(dbm_relation(dbm5, dbm6, size) == base_EQUAL); assert(dbm_relation(dbm6, dbm7, size) & base_SUBSET); /* further checks */ assert(dbm_isValid(dbm2, size)); assert(dbm_isValid(dbm3, size)); assert(dbm_isValid(dbm4, size)); assert(dbm_isValid(dbm5, size)); assert(dbm_isValid(dbm6, size)); assert(dbm_isValid(dbm7, size)); } ENDL; free(lower); free(upper); free(max); free(dbm10); free(dbm9); free(dbm8); free(dbm7); free(dbm6); free(dbm5); free(dbm4); free(dbm3); free(dbm2); free(dbm1); }
void Clocks::up() { ASSERT( dbm_isValid( data, dim ) ); dbm_up( data, dim ); }