void runTests9 (int argc, char* argv[]) { ExpressionListPtr pRowPermutations = Util::quickPerm(5); ExpressionListPtr pColPermutations = Util::quickPerm(2); ExpressionListPtr pVarPermutations = Util::quickPerm(1); ilog("row permutations"); pRowPermutations->print(); ilog("col permutations"); pColPermutations->print(); ilog("outcome permutations"); pVarPermutations->print(); ilog("---- p: ----"); ExpressionPtr p = new Expression; p->set(0, 0, 0, 1); p->set(0, 1, 0, 1); p->set(1, 0, 0, 1); p->set(1, 1, 0, -1); p->set(2, 0, 0, 0); p->set(2, 1, 0, 0); p->set(3, 0, 0, -1); p->set(3, 1, 0, 1); p->set(4, 0, 0, -1); p->set(4, 1, 0, -1); p->printMatrix(); //-1 -1 1 1 -1 1 1 -1 0 0 ExpressionPtr p2 = new Expression; p2->set(0, 0, 0, -1); p2->set(0, 1, 0, 1); p2->set(1, 0, 0, 1); p2->set(1, 1, 0, 1); p2->set(2, 0, 0, -1); p2->set(2, 1, 0, 1); p2->set(3, 0, 0, 1); p2->set(3, 1, 0, -1); p2->set(4, 0, 0, 0); p2->set(4, 1, 0, 0); ilog("---- p2: ----"); p2->printMatrix(); p2->isBetter(p); ExpressionPtr pExp = p->findSpecialEquivalent(pRowPermutations, pColPermutations, pVarPermutations); ilog("---- result: ----"); pExp->printMatrix(); ilog("--------"); }
bool parsePorta(ExpressionList* pList, N32 preparations, N32 measurements) { char str[0x10000]; FILE* pF = fopen("porta.poi.ieq", "r"); if (!pF) { errorExit("must have a porta.poi.ieq in the folder"); } int dim = 0; while(fgets(str, sizeof(str), pF)) { #ifdef _PARSE_LOG ilog(""); #endif int nLen = strlen(str); char* p = str; XK(str[nLen - 1] == '\n'); str[nLen - 1] = 0; char* pDim = strstr(p, "DIM = "); if (pDim) { pDim += 6; readNumber(pDim, dim); #ifdef _PARSE_LOG log("Dimension is %d:", dim); #endif continue; } if (!readChar(p, '(')) continue; int nVertex; if (!readNumber(p, nVertex)) errorExit("couldn't find a vertex number"); if (!readChar(p, ')')) continue; #ifdef _PARSE_LOG log("%d:", nVertex); #endif N32 a[256]; for (int n = 0; n < 256; ++n) a[n] = 0; ExpressionPtr pIneq = new Expression(); pList->pushBack(pIneq); int varIndexMax = -1; while(true) { int sign; int ine; int rhs; if(!readBlks(p)) errorExit("incomplet"); if (readIne(p, ine)) { if (!readNumber(p, rhs)) errorExit("couldn't find lrs"); #ifdef _PARSE_LOG log(" rhs: %d .... %s", rhs, str); #endif pIneq->setRHS(rhs); pIneq->setIne(ine); pIneq->setPortaExp(str); break; } if (!readSign(p, sign)) errorExit("couldn't find a sign (+/-)"); int factor = 1; readNumber(p, factor); if (!readChar(p, 'x')) errorExit("couldn't find a x"); int varIndex; if (!readNumber(p, varIndex)) errorExit("couldn't find a >"); if (varIndex > varIndexMax) varIndexMax = varIndex; N32 termState = (sign == '-') ? -factor : factor; //fprintf(pLog, " %dx%d", termState, varIndex); //TermPtr p = new Term(); //p->setState(termState); //pIneq->pushBack(p); a[varIndex - 1] = termState; } for (int n = 0; n < dim; ++n) { TermPtr p = new Term(); p->setState(a[n]); pIneq->set(n / measurements, n % measurements, p); #ifdef _PARSE_LOG log(" %dx%d", a[n], n); #endif } } fclose(pF); return true; }
static bool parseLRS(ExpressionList* pList, N32 preparations, N32 measurements) { static char szRepresentation[] = "H-representation"; bool bFoundRepresentation = false; bool bBegin = false; char str[0x10000]; FILE* pF = fopen("lrs.hf", "r"); if (!pF) { errorExit("This program uses always uses lrs.hf as input which I couldn't find"); } while(fgets(str, sizeof(str), pF)) { #ifdef _PARSE_LOG ilog(""); #endif int nLen = strlen(str); char* p = str; if(str[nLen - 1] == '\n') str[nLen - 1] = 0; if (*p == '#' || *p == '*') continue; if (!bFoundRepresentation) { char* pPresentation = strstr(p, szRepresentation); if (pPresentation) bFoundRepresentation = true; continue; } if (!bBegin) { char* pBegin = strstr(p, "begin"); if (pBegin) bBegin = true; continue; } char* pEnd = strstr(p, "end"); if (pEnd) break; #ifdef _PARSE_LOG ilog(""); #endif N32 a[256]; for (int n = 0; n < 256; ++n) a[n] = 0; ExpressionPtr pIneq = new Expression(); pList->pushBack(pIneq); int dPlusOne = 0; while(true) { int ine; int rhs; N32 v = 0; if(!readBlks(p)) break; if (*p == 0) break; if (!readNumber2(p, v)) errorExit("error"); a[dPlusOne] = v; ++dPlusOne; } // in lrs the const is in LHS we need to change it to RHS pIneq->setRHS(a[0]); pIneq->setIne(-1); for (int i = 1; i < dPlusOne; ++i) { TermPtr p = new Term(); p->setState(a[i]); int n = i - 1; pIneq->set( n / measurements, n % measurements, p); #ifdef _PARSE_LOG log(" %dx%d", -a[n], n); #endif } } fclose(pF); return true; }