int testGetNumShares() { int errors = 0; std::string base = "TestGetNumShares: "; std::string expr0 = "1"; BLAccessPolicy pol0(expr0, 3); test_diagnosis(base + expr0, pol0.getNumShares() == 1, errors); std::string expr1 = op_OR + "(1,2,3)"; BLAccessPolicy pol1(expr1, 3); test_diagnosis(base + expr1, pol1.getNumShares() == 3, errors); std::string expr2 = op_OR + "(" + op_AND + "(1,2)," + op_AND + "(3,4))"; BLAccessPolicy pol2(expr2, 4); test_diagnosis(base + expr2, pol2.getNumShares() == 4, errors); std::string expr3 = op_OR + "(" + op_AND + "(3,4,5),7," + op_AND + "(1,2)," + op_AND + "(4,1,6,5))"; BLAccessPolicy pol3(expr3, 7); test_diagnosis(base + expr3, pol3.getNumShares() == 10, errors); return errors; }
int main() { //set up basisvectors std::vector<std::vector<double> > basis2(2,std::vector<double>(2)); basis2[0][0] = 1; basis2[0][1] = 0; basis2[1][0] = 0; basis2[1][1] = 1; //define lattice Lattice myLattice(2,basis2); //set up 2d polytopes std::vector<std::vector<double> > ver0(3,std::vector<double>(2)); std::vector<std::vector<double> > ver1(4,std::vector<double>(2)); std::vector<std::vector<double> > ver2(4,std::vector<double>(2)); std::vector<std::vector<double> > ver3(3,std::vector<double>(2)); std::vector<std::vector<double> > ver4(5,std::vector<double>(2)); std::vector<std::vector<double> > ver5(4,std::vector<double>(2)); std::vector<std::vector<double> > ver6(6,std::vector<double>(2)); std::vector<std::vector<double> > ver7(4,std::vector<double>(2)); std::vector<std::vector<double> > ver8(5,std::vector<double>(2)); std::vector<std::vector<double> > ver9(3,std::vector<double>(2)); std::vector<std::vector<double> > ver10(4,std::vector<double>(2)); ver0[0][0] = 1; ver0[0][1] = 0; ver0[1][0] = 0; ver0[1][1] = 1; ver0[2][0] = -1; ver0[2][1] = -1; ver1[0][0] = 1; ver1[0][1] = 0; ver1[1][0] = 0; ver1[1][1] = 1; ver1[2][0] = -1; ver1[2][1] = 0; ver1[3][0] = 0; ver1[3][1] = -1; ver2[0][0] = 1; ver2[0][1] = 0; ver2[1][0] = 0; ver2[1][1] = 1; ver2[2][0] = -1; ver2[2][1] = 0; ver2[3][0] = -1; ver2[3][1] = -1; ver3[0][0] = 1; ver3[0][1] = 0; ver3[1][0] = 0; ver3[1][1] = 1; ver3[2][0] = -2; ver3[2][1] = -1; ver4[0][0] = 1; ver4[0][1] = 0; ver4[1][0] = 1; ver4[1][1] = 1; ver4[2][0] = 0; ver4[2][1] = 1; ver4[3][0] = -1; ver4[3][1] = 0; ver4[4][0] = 0; ver4[4][1] = -1; ver5[0][0] = 1; ver5[0][1] = 0; ver5[1][0] = 0; ver5[1][1] = 1; ver5[2][0] = -1; ver5[2][1] = 1; ver5[3][0] = -1; ver5[3][1] = -1; Polytope pol0(ver0,myLattice); Polytope pol1(ver1,myLattice); Polytope pol2(ver2,myLattice); Polytope pol3(ver3,myLattice); Polytope pol4(ver4,myLattice); Polytope pol5(ver5,myLattice); Polytope pol15 = pol0.getCorrespondingDualPolytope(); Polytope pol14 = pol1.getCorrespondingDualPolytope(); Polytope pol13 = pol2.getCorrespondingDualPolytope(); Polytope pol12 = pol3.getCorrespondingDualPolytope(); Polytope pol11 = pol4.getCorrespondingDualPolytope(); Polytope pol10 = pol5.getCorrespondingDualPolytope(); ver6[0][0] = 1; ver6[0][1] = 0; ver6[1][0] = 1; ver6[1][1] = 1; ver6[2][0] = 0; ver6[2][1] = 1; ver6[3][0] = -1; ver6[3][1] = 0; ver6[4][0] = -1; ver6[4][1] = -1; ver6[5][0] = 0; ver6[5][1] = -1; ver7[0][0] = 1; ver7[0][1] = 0; ver7[1][0] = -1; ver7[1][1] = 1; ver7[2][0] = -1; ver7[2][1] = -1; ver7[3][0] = 1; ver7[3][1] = -1; ver8[0][0] = 1; ver8[0][1] = 0; ver8[1][0] = 1; ver8[1][1] = 1; ver8[2][0] = -1; ver8[2][1] = 1; ver8[3][0] = -1; ver8[3][1] = 0; ver8[4][0] = 0; ver8[4][1] = -1; ver9[0][0] = 1; ver9[0][1] = 0; ver9[1][0] = -1; ver9[1][1] = 2; ver9[2][0] = -1; ver9[2][1] = -1; Polytope pol6(ver6,myLattice); Polytope pol7(ver7,myLattice); Polytope pol8(ver8,myLattice); Polytope pol9(ver9,myLattice); //Polytope polytopes2D[16] = {pol0, pol1, pol2, pol3, pol4, pol5, pol6, pol7, pol8, pol9, pol10, pol11, pol12, pol13, pol14, pol15}; //Polytope polytopes2DDual[16] = {pol15, pol14, pol13, pol12, pol11, pol10, pol6, pol7, pol8, pol9, pol5, pol4, pol3, pol2, pol1, pol0}; std::vector<Polytope > myList = {pol0, pol1, pol2, pol3, pol4, pol5, pol6, pol7, pol8, pol9, pol10, pol11, pol12, pol13, pol14, pol15}; std::vector<Polytope > myFiveVerticesList = {pol0, pol3, pol9, pol12, pol15}; //Construct 4d polytopes from this data std::string fileName = "output"; //pol0.printListFrom2DTo4DPolytopesToFile(fileName, myList); pol0.printListFrom2DTo4DPolytopesToFile("outputForFiveVertices", myFiveVerticesList); }
void Result::showResultLose(int score){ int left = -320; int right = 320; int top = 240; int bot = -240; char strbuffer[64]; // L Point pol1(left+60,top-80); Point pol2(left+60,bot+220); Point pol3(left+180,bot+220); Point pol4(left+180,bot+270); Point pol5(left+110,bot+270); Point pol6(left+110,top-80); Point polc((pol1.x+pol3.x)/2,(pol1.y+pol3.y)/2); vector<Point> pol; pol.push_back(pol1); pol.push_back(pol2); pol.push_back(pol3); pol.push_back(pol4); pol.push_back(pol5); pol.push_back(pol6); if (firsttime){ pol_l.setCorner(pol); pol_l.setCenter(polc); Transform scale = createScale(0.1, 0.1); pol_l.applyTransform(scale); } // O Point poo1(left+190,top-80); Point poo2(left+190,bot+220); Point poo3(left+310,bot+220); Point poo4(left+310,top-80); Point poo5(left+230,top-120); Point poo6(left+230,bot+260); Point poo7(left+270,bot+260); Point poo8(left+270,top-120); Point pooc((poo1.x+poo3.x)/2,(poo1.y+poo3.y)/2); vector<Point> poo, poov; poo.push_back(poo1); poo.push_back(poo2); poo.push_back(poo3); poo.push_back(poo4); poov.push_back(poo5); poov.push_back(poo6); poov.push_back(poo7); poov.push_back(poo8); if (firsttime){ pol_o.setCorner(poo); pol_o.setCenter(pooc); pol_o1.setCorner(poov); pol_o1.setCenter(pooc); Transform scale = createScale(0.1, 0.1); pol_o.applyTransform(scale); pol_o1.applyTransform(scale); } // S Point pos1(left+320,top-80); Point pos2(left+320,top-190); Point pos3(left+410,top-190); Point pos4(left+410,top-220); Point pos5(left+320,top-220); Point pos6(left+320,top-260); Point pos7(left+450,top-260); Point pos8(left+450,top-150); Point pos9(left+360,top-150); Point pos10(left+360,top-120); Point pos11(left+450,top-120); Point pos12(left+450,top-80); Point posc((pos1.x+pos7.x)/2,(pos1.y+pos7.y)/2); vector<Point> pos; pos.push_back(pos1); pos.push_back(pos2); pos.push_back(pos3); pos.push_back(pos4); pos.push_back(pos5); pos.push_back(pos6); pos.push_back(pos7); pos.push_back(pos8); pos.push_back(pos9); pos.push_back(pos10); pos.push_back(pos11); pos.push_back(pos12); if (firsttime){ pol_s.setCorner(pos); pol_s.setCenter(posc); Transform scale = createScale(0.1, 0.1); pol_s.applyTransform(scale); } // E Point poe1(left+460,top-80); Point poe2(left+460,bot+220); Point poe3(left+580,bot+220); Point poe4(left+580,bot+260); Point poe5(left+510,bot+260); Point poe6(left+510,bot+290); Point poe7(left+580,bot+220+70); Point poe8(left+580,bot+260+70); Point poe9(left+510,bot+260+70); Point poe10(left+510,bot+290+70); Point poe11(left+580,bot+220+140); Point poe12(left+580,bot+260+140); Point poec((poe1.x+poe3.x)/2,(poe1.y+poe3.y)/2); vector<Point> poe; poe.push_back(poe1); poe.push_back(poe2); poe.push_back(poe3); poe.push_back(poe4); poe.push_back(poe5); poe.push_back(poe6); poe.push_back(poe7); poe.push_back(poe8); poe.push_back(poe9); poe.push_back(poe10); poe.push_back(poe11); poe.push_back(poe12); if (firsttime){ pol_e.setCorner(poe); pol_e.setCenter(poec); Transform scale = createScale(0.1, 0.1); pol_e.applyTransform(scale); } // Other Point pot1(left+60, top-40); Point pot2(right-60, top-40); Point pot3(right-60, top-60); Point pot4(left+60, top-60); Point potc((pot1.x+pot2.x)/2,(pot2.x+pot3.x)/2); vector<Point> pot; pot.push_back(pot1); pot.push_back(pot2); pot.push_back(pot3); pot.push_back(pot4); if (firsttime){ pol_pot1.setCorner(pot); pol_pot1.setCenter(potc); Transform scale = createScale(0.1, 0.1); pol_pot1.applyTransform(scale); } pot1.set(left+60, bot+180); pot2.set(right-60, bot+180); pot3.set(right-60, bot+200); pot4.set(left+60, bot+200); potc.set((pot1.x+pot2.x)/2,(pot2.x+pot3.x)/2); pot.clear(); pot.push_back(pot1); pot.push_back(pot2); pot.push_back(pot3); pot.push_back(pot4); if (firsttime){ pol_pot2.setCorner(pot); pol_pot2.setCenter(potc); Transform scale = createScale(0.1, 0.1); pol_pot2.applyTransform(scale); } resultframe++; if (resultframe >= 25) resultframe = 25; else { Transform scale = createScale(1.1, 1.1); pol_pot1.applyTransform(scale); pol_pot2.applyTransform(scale); pol_l.applyTransform(scale); pol_o.applyTransform(scale); pol_o1.applyTransform(scale); pol_s.applyTransform(scale); pol_e.applyTransform(scale); } pol_l.draw(WHITE); fill_polygon(pol_l[0].x, pol_l[2].y, pol_l[2].x, pol_l[0].y,WHITE,WHITE); pol_o.draw(WHITE); fill_polygon(pol_o[0].x, pol_o[2].y, pol_o[2].x, pol_o[0].y,WHITE,WHITE); pol_o1.draw(BLACK); fill_polygon(pol_o1[0].x, pol_o1[2].y, pol_o1[2].x, pol_o1[0].y,BLACK,BLACK); pol_s.draw(WHITE); fill_polygon(pol_s[0].x, pol_s[6].y, pol_s[6].x, pol_s[0].y,WHITE,WHITE); pol_e.draw(WHITE); fill_polygon(pol_e[0].x, pol_e[2].y, pol_e[2].x, pol_e[0].y,WHITE,WHITE); pol_pot1.draw(WHITE); pol_pot2.draw(WHITE); settextstyle(7,0,40); setcolor(WHITE); sprintf(strbuffer,"%d",score); outtextxy(getmaxx()/2-50, getmaxy()/2+100, strbuffer); firsttime = false; }
int testExpr2(int errors) { std::string expr2 = op_OR + "(" + op_AND + "(1,2)," + op_AND + "(3,4))"; BLAccessPolicy pol2(expr2, 4); ShareTuple s11(1,0,"1:1"); ShareTuple s12(2,0,"1:2"); ShareTuple s13(3,0,"1:3"); ShareTuple s22(2,0,"2:2"); ShareTuple s23(3,0,"2:3"); ShareTuple s24(4,0,"2:4"); vector<ShareTuple> ex2TestA1; vector<ShareTuple> ex2TestA2; vector<ShareTuple> ex2TestA1A2; vector<ShareTuple> ex2TestB3B4; vector<ShareTuple> ex2TestB2B3B4; vector<ShareTuple> ex2TestA1B4A2; vector<ShareTuple> ex2TestA1B2B3B4; vector<ShareTuple> ex2TestA1A3B4B2; vector<ShareTuple> ex2WitnessA1; vector<ShareTuple> ex2WitnessA2; vector<ShareTuple> ex2WitnessA1A2; vector<ShareTuple> ex2WitnessB3B4; vector<ShareTuple> ex2WitnessB2B3B4; vector<ShareTuple> ex2WitnessA1B4A2; vector<ShareTuple> ex2WitnessA1B2B3B4; vector<ShareTuple> ex2WitnessA1A3B4B2; ex2TestA1.push_back(s11); ex2TestA2.push_back(s12); ex2TestA1A2.push_back(s11); ex2TestA1A2.push_back(s12); ex2TestB3B4.push_back(s23); ex2TestB3B4.push_back(s24); ex2TestB2B3B4.push_back(s22); ex2TestB2B3B4.push_back(s23); ex2TestB2B3B4.push_back(s24); ex2TestA1B4A2.push_back(s11); ex2TestA1B4A2.push_back(s24); ex2TestA1B4A2.push_back(s12); ex2TestA1B2B3B4.push_back(s11); ex2TestA1B2B3B4.push_back(s22); ex2TestA1B2B3B4.push_back(s23); ex2TestA1B2B3B4.push_back(s24); ex2TestA1A3B4B2.push_back(s11); ex2TestA1A3B4B2.push_back(s13); ex2TestA1A3B4B2.push_back(s24); ex2TestA1A3B4B2.push_back(s22); ex2WitnessA1A2.push_back(s11); ex2WitnessA1A2.push_back(s12); ex2WitnessB3B4.push_back(s23); ex2WitnessB3B4.push_back(s24); ex2WitnessB2B3B4.push_back(s23); ex2WitnessB2B3B4.push_back(s24); ex2WitnessA1B4A2.push_back(s11); ex2WitnessA1B4A2.push_back(s12); ex2WitnessA1B2B3B4.push_back(s23); ex2WitnessA1B2B3B4.push_back(s24); vector<vector<ShareTuple> > ex2TestRun; vector<vector<ShareTuple> > ex2WitnessRun; ex2TestRun.push_back(ex2TestA1); ex2TestRun.push_back(ex2TestA2); ex2TestRun.push_back(ex2TestA1A2); ex2TestRun.push_back(ex2TestB3B4); ex2TestRun.push_back(ex2TestB2B3B4); ex2TestRun.push_back(ex2TestA1B4A2); ex2TestRun.push_back(ex2TestA1B2B3B4); ex2TestRun.push_back(ex2TestA1A3B4B2); ex2WitnessRun.push_back(ex2WitnessA1); ex2WitnessRun.push_back(ex2WitnessA2); ex2WitnessRun.push_back(ex2WitnessA1A2); ex2WitnessRun.push_back(ex2WitnessB3B4); ex2WitnessRun.push_back(ex2WitnessB2B3B4); ex2WitnessRun.push_back(ex2WitnessA1B4A2); ex2WitnessRun.push_back(ex2WitnessA1B2B3B4); ex2WitnessRun.push_back(ex2WitnessA1A3B4B2); errors = testVectors(errors, ex2TestRun, ex2WitnessRun, pol2, expr2); return errors; }
void menu_graf(char *file) { FILE * pbm; int flag_opt=0; /* flag_opt = 0 si no entro a ninguna funcion a graficar */ typedef enum {SEN=1,COS,POL0,POL1,POL2,POL3,LN,EXP,DEFAULT,ERROR=255} opt_graf_t; opt_graf_t optgraf; char option[MAX_CHAR]; int matriz[RESOLUCION][RESOLUCION]; float vect_x[RESOLUCION]; float vect_y[RESOLUCION]; cargo_x(vect_x); printf(MENU_GRAF); limpiarbuffer(); fgets(option, MAX_CHAR, stdin); option[strlen(option)-1]='\0'; optgraf=atoi(option); /* si se ingreso algo que no es una opcion debe ir al default */ if (optgraf==0) optgraf=DEFAULT; while (optgraf) { switch(optgraf) { case SEN: seno(vect_x, vect_y); flag_opt=1; break; case COS: coseno(vect_x, vect_y); flag_opt=1; break; case POL0: pol0(vect_x, vect_y); flag_opt=1; break; case POL1: pol1(vect_x, vect_y); flag_opt=1; break; case POL2: pol2(vect_x, vect_y); flag_opt=1; break; case POL3: pol3(vect_x, vect_y); flag_opt=1; break; case LN: ln(vect_x, vect_y); flag_opt=1; break; case EXP: expo(vect_x, vect_y); flag_opt=1; break; default: printf("Entrada inválida!\n"); } /* Este if corta la ejecuccion del programa si ya grafico sale del bucle while(optgraf) */ if(flag_opt==1) break; printf("Presione enter para volver al menu \n"); limpiarbuffer(); system(CLS); printf(MENU_GRAF); fgets(option, MAX_CHAR, stdin); option[strlen(option)-1]='\0'; optgraf=atoi(option); /* Si se ingreso una letra o algo que no es valido*/ if (!optgraf) optgraf=255; } inicializo_matriz(matriz); inicializo_ejes(matriz); cargo_matriz(matriz, vect_y); if(file==NULL) imprimo_matriz(matriz); else { /* Abrimos el pbm para guardar datos como file */ make_pbm_file(&pbm,file); /* grabamos la info y luego cerramos el file* */ write_pbm_file(&pbm, matriz, RESOLUCION, RESOLUCION); close_pbm_file(&pbm); } }