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;
}
Beispiel #2
0
// ----------------------------------------------------------------
f2npoly_t f2pm_char_poly(
	tmatrix<f2polymod_t> & A)
{
	if (!A.is_square()) {
		std::cerr << "f2pm_char_poly():  non-square input.\n";
		exit(1);
	}

	int i, j;
	int n = A.get_num_rows();
	tmatrix<f2npoly_t> tI_A(n, n);
	f2poly_t m = A[0][0].get_modulus();
	f2polymod_t  c1(f2poly_t(1), m);
	f2polymod_t  c0(f2poly_t(0), m);
	f2npoly_t    t(c1, c0);
	f2npoly_t    pol1(c1);
	f2npoly_t    det;

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			tI_A[i][j] = - f2npoly_t(A[i][j]);
			if (i == j)
				tI_A[i][j] += t;
		}
	}

	det = tI_A.ed_det();
	return det;
}
Beispiel #3
0
pqPoint HitCollection::drawHits(bool fit, bool draw, bool rz) {
	unsigned int hits_n = hitCollection.size();
	TGraph hits_h(hits_n);
	hits_h.SetTitle("Hits");
	for (unsigned int hit_i = 0; hit_i < hits_n; hit_i++) {
		hits_h.SetPoint(hit_i, hitCollection[hit_i].x, hitCollection[hit_i].y);
	}
	TCanvas c("c", "c", 600, 600);
	hits_h.GetXaxis()->SetLimits(-1.1*zmax, 1.1*zmax);
	hits_h.GetYaxis()->SetRangeUser(0., 1.1*rmax);
	hits_h.GetXaxis()->SetTitle("x[cm]");
	hits_h.GetYaxis()->SetTitle("y[cm]");
	hits_h.Draw("A*");
	pqPoint pqpoint;
	if (fit) {
		gStyle->SetOptFit(10001);
		string pol1("[1]*x + [0]");
		if (rz) pol1 = "1./[1]*x - [0]/[1]";
		TF1 * fitfun = new TF1("fitfun", pol1.c_str());
		fitfun->SetParNames("q","p");
		fitfun->SetParameters(1., 1.);
		hits_h.Fit(fitfun, draw ? "" : "q");
		c.Update();

		pqpoint.p = fitfun->GetParameter("p");
//		pqpoint.p = atan(fun->GetParameter("p"));
		pqpoint.q = fitfun->GetParameter("q");
		pqpoint.w = 1.;
	}
	else pqpoint.w = -1.;
	TPaveStats *st = (TPaveStats*)hits_h.FindObject("stats");
	st->SetY1NDC(0.72);
	st->SetY2NDC(0.87);
	st->SetX1NDC(0.13);
	st->SetX2NDC(0.28);

	if (draw) c.Print(Form("figs/hits_%s.pdf", name.c_str()));

	return pqpoint;
}
Beispiel #4
0
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);
}
Beispiel #5
0
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 testExpr1(int errors) {

  std::string expr1 = op_OR + "(1,2,3)";
  BLAccessPolicy pol1(expr1, 5);

  ShareTuple s11(1,0,"1:1");
  ShareTuple s12(2,0,"2:2");
  ShareTuple s13(3,0,"3:3");
  ShareTuple s14(4,0,"4:4");
  ShareTuple s15(5,0,"5:5");

  vector<ShareTuple> ex1Test1;
  vector<ShareTuple> ex1Test2;
  vector<ShareTuple> ex1Test3;
  vector<ShareTuple> ex1Test4;
  vector<ShareTuple> ex1Test5;
  vector<ShareTuple> ex1Test42;
  vector<ShareTuple> ex1Test23;
  vector<ShareTuple> ex1Test231;

  vector<ShareTuple> ex1Witness1;
  vector<ShareTuple> ex1Witness2;
  vector<ShareTuple> ex1Witness3;
  vector<ShareTuple> ex1Witness4;
  vector<ShareTuple> ex1Witness5;
  vector<ShareTuple> ex1Witness42;
  vector<ShareTuple> ex1Witness23;
  vector<ShareTuple> ex1Witness231;

  ex1Test1.push_back(s11);
  ex1Test2.push_back(s12);
  ex1Test3.push_back(s13);
  ex1Test4.push_back(s14);
  ex1Test5.push_back(s15);
  ex1Test42.push_back(s14);
  ex1Test42.push_back(s12);
  ex1Test23.push_back(s12);
  ex1Test23.push_back(s13);
  ex1Test231.push_back(s12);
  ex1Test231.push_back(s13);
  ex1Test231.push_back(s11);

  ex1Witness1.push_back(s11);
  ex1Witness2.push_back(s12);
  ex1Witness3.push_back(s13);
  ex1Witness42.push_back(s12);
  ex1Witness23.push_back(s12);
  ex1Witness231.push_back(s11);

  vector<vector<ShareTuple> > ex1TestRun;
  vector<vector<ShareTuple> > ex1WitnessRun;

  ex1TestRun.push_back(ex1Test1);
  ex1TestRun.push_back(ex1Test2);
  ex1TestRun.push_back(ex1Test3);
  ex1TestRun.push_back(ex1Test4);
  ex1TestRun.push_back(ex1Test5);
  ex1TestRun.push_back(ex1Test42);
  ex1TestRun.push_back(ex1Test23);
  ex1TestRun.push_back(ex1Test231);

  ex1WitnessRun.push_back(ex1Witness1);
  ex1WitnessRun.push_back(ex1Witness2);
  ex1WitnessRun.push_back(ex1Witness3);
  ex1WitnessRun.push_back(ex1Witness4);
  ex1WitnessRun.push_back(ex1Witness5);
  ex1WitnessRun.push_back(ex1Witness42);
  ex1WitnessRun.push_back(ex1Witness23);
  ex1WitnessRun.push_back(ex1Witness231);  

  errors = testVectors(errors, ex1TestRun, ex1WitnessRun, pol1, expr1);

  return errors;
}
Beispiel #7
0
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);
    }

}