std::vector< std::vector<SgMove> > GoAutoBook::ParseWorkList(std::istream& in) { std::vector< std::vector<SgMove> > ret; while (in) { std::string line; std::getline(in, line); if (line == "") continue; std::vector<SgMove> var; std::istringstream in2(line); while (true) { std::string s; in2 >> s; if (! in2 || s == "|") break; std::istringstream in3(s); SgPoint p; in3 >> SgReadPoint(p); if (! in3) throw SgException("Invalid point"); var.push_back(p); } ret.push_back(var); } SgDebug() << "GoAutoBook::ParseWorkList: Read " << ret.size() << " variations.\n"; return ret; }
void System::updateProfileServices(QString name) { QString pathString3; QTextStream pathStream3(&pathString3); pathStream3 << this->systemPath << "/profiles/" << name << "-services.txt"; QFile currentProfileServices(pathString3); currentProfileServices.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream in3(¤tProfileServices); QString serviceName, serviceProtocol, serviceAction, servicePort; int varCount=0; while (in3.atEnd() == false) { QString line = in3.readLine(); // contains several lines of text QStringList service = line.split(",", QString::SkipEmptyParts); foreach (QString var, service) { if ((varCount % 4) == 0) serviceName = var; else if ((varCount % 4) == 1) servicePort = var; else if ((varCount % 4) == 2) serviceProtocol = var; else if ((varCount % 4) == 3) serviceAction = var; varCount++; } this->currentProfile->addService(serviceName, servicePort.toInt(), serviceProtocol, serviceAction); } currentProfileServices.close(); }
int test_colt_nested_cells() { char *outer1[] = { "1962", "1977", "1989", "2010" }; char *outer2[] = { "1990", "2001", "2008", "2015" }; char *outer3[] = { "1993", "2001", "2009", "2013" }; char *inner1[] = { "Jan", "Feb", "March" }; char *inner2[] = { "Apr", "May", "June" }; char *inner3[] = { "July", "August", "September" }; char *inner4[] = { "October", "November", "December" }; char *deep1[] = { "14", "9", "2" }; char *deep2[] = { "25", "4", "0" }; char *head1[] = { "Birth", "start", "better", "bests" }; char *head2[] = { "Mon1", "mon2", "Month3" }; char *head3[] = { "father", "daughter", "son" }; colt_nested_cells deepest1(deep1, 3, head3, "days"); colt_nested_cells deepest2(deep2, 3, head3, "days"); colt_nested_cells in11(inner1, 3, head2, "Months", &deepest1); colt_nested_cells in12(inner1, 3, head2, "Months", &deepest2); colt_nested_cells in2(inner2, 3, head2, "Months"); colt_nested_cells in3(inner3, 3, head2, "Months"); colt_nested_cells in4(inner4, 3, head2, "Months"); colt_nested_cells out11(outer1, 4, head1, "Dates", &in11); colt_nested_cells out11a(outer1, 4, head1, "Dates", &in12); colt_nested_cells out12(outer1, 4, head1, "Dates", &in2); colt_nested_cells out13(outer1, 4, head1, "Dates", &in3); colt_nested_cells out21(outer2, 4, head1, "Dates", &in4); colt_nested_cells out22(outer2, 4, head1, "Dates", &in3); colt_nested_cells out23(outer2, 4, head1, "Dates", &in11); colt_nested_cells out31(outer3, 4, head1, "Dates", &in2); colt_nested_cells out32(outer3, 4, head1, "Dates", &in11); colt_nested_cells out33(outer3, 4, head1, "Dates", &in4); std::ofstream mine("mine.yml"); // out11.start(); out11.nested_output(NULL, 0, &mine); out11a.nested_output(&out11, 0, &mine); out12.nested_output(&out11a, 0, &mine); out23.nested_output(&out12, 0, &mine); out21.nested_output(&out23, 0, &mine); out22.nested_output(&out21, 0, &mine); out31.nested_output(&out22, 0, &mine); out32.nested_output(&out31, 0, &mine); out33.nested_output(&out32, 0, &mine); // out13.end(xxx+1); // out11.end(); }
TEST(RealWordTest, OR) { typedef NeuralNetwork<double, StepActivationFunction<double >> network; network nn; nn.setEntries(2); nn.setExits(1); nn.setLayersCount(1); nn.init(); std::vector<double> in1(2); std::vector<double> in2(2); std::vector<double> in3(2); std::vector<double> in4(2); in1[0] = 0; in1[1] = 0; in2[0] = 1; in2[1] = 0; in3[0] = 0; in3[1] = 1; in4[0] = 1; in4[1] = 1; std::vector<double> out0(1); std::vector<double> out1(1); out0[0] = 0; out1[0] = 1; //uczenie for (int i = 0; i < 100; ++i) { nn.setInput(in1.begin(), in1.end()); nn.calcOutput(); nn.learn(out0.begin(), out0.end()); nn.setInput(in2.begin(), in2.end()); nn.calcOutput(); nn.learn(out1.begin(), out1.end()); nn.setInput(in3.begin(), in3.end()); nn.calcOutput(); nn.learn(out1.begin(), out1.end()); nn.setInput(in4.begin(), in4.end()); nn.calcOutput(); nn.learn(out1.begin(), out1.end()); } //test std::vector<double> out; nn.setInput(in1.begin(), in1.end()); out = nn.calcOutput(); ASSERT_EQ(out[0], 0); nn.setInput(in2.begin(), in2.end()); out = nn.calcOutput(); ASSERT_EQ(out[0], 1); nn.setInput(in3.begin(), in3.end()); out = nn.calcOutput(); ASSERT_EQ(out[0], 1); nn.setInput(in4.begin(), in4.end()); out = nn.calcOutput(); ASSERT_EQ(out[0], 1); }
// test to run processing/example.py TEST_F(SignalProcessingInterfaceTest, exampleTest) { android::String8 functionName("example"); int nInputs = 8; int nOutputs = 4; bool inputTypes[8] = { true, true, true, true, false, false, false, false }; bool outputTypes[4] = { true, true, false, false }; android::sp<Buffer> in0(new Buffer(16, 16, true)); char* data0 = in0->getData(); for (size_t i = 0; i < in0->getSize(); i++) { data0[i] = i; } android::sp<Buffer> in1(new Buffer(16, 16, true)); char* data1 = in1->getData(); for (size_t i = 0; i < in1->getSize(); i++) { data1[i] = i; } android::sp<Buffer> in2(new Buffer(8, 8, false)); char* data2 = in2->getData(); for (size_t i = 0; i < in2->getSize(); i++) { data2[i] = i; } android::sp<Buffer> in3(new Buffer(8, 8, false)); char* data3 = in3->getData(); for (size_t i = 0; i < in3->getSize(); i++) { data3[i] = i; } TaskCase::Value in4((int64_t)100); TaskCase::Value in5((int64_t)100); TaskCase::Value in6(1.0f); TaskCase::Value in7(1.0f); void* inputs[8] = { &in0, &in1, &in2, &in3, &in4, &in5, &in6, &in7 }; android::sp<Buffer> out0(new Buffer(16, 16, true)); char* outdata0 = out0->getData(); for (size_t i = 0; i < out0->getSize(); i++) { outdata0[i] = 0xaa; } android::sp<Buffer> out1(new Buffer(8, 8, false)); char* outdata1 = out1->getData(); for (size_t i = 0; i < out1->getSize(); i++) { outdata1[i] = 0xbb; } TaskCase::Value out2((int64_t)1000); TaskCase::Value out3(-1.0f); void *outputs[4] = { &out0, &out1, &out2, &out3 }; ASSERT_TRUE(mSp->run( functionName, nInputs, inputTypes, inputs, nOutputs, outputTypes, outputs) == TaskGeneric::EResultOK); ASSERT_TRUE(*(in0.get()) == *(out0.get())); ASSERT_TRUE(*(in2.get()) == *(out1.get())); ASSERT_TRUE(in4 == out2); ASSERT_TRUE(in6 == out3); }
int main(int argc, char* argv[]) { setbuf(stdout,NULL) ; init(argv, 0, 0, 0, true, false); double* data = (double*)malloc(4*sizeof(double)); data[0] = 10; data[1] = 20; data[2] = 30; data[3] = 40 ; input<double> in1(1, 1, 4, 1, "pvmtslave1"); input<double*> in2(2, 1, data, 4, "pvmtslave1"); input<double> in3(1, 2, 6, 1, "pvmtslave1"); bool is = INSTANTINATE(":prog1", "group1", 1, in1, in2); //is = SEND("", "pvmtslave", "group1", in1, in2); is = SEND("main:all_tasks.main.1:group1.prog1.pvmtslave.1", "group1", in3); //printlog(DEBUG, "instantinate returns %d\n", is); usleep(6000); input<double> in4_1(1, 1, 4, 1, "pvmtslave1"); input<double*> in5_2(2, 1, data, 4, "pvmtslave1"); is = SEND("main:all_tasks.main.1:group1.prog1.pvmtslave.1", "group1", in4_1, in5_2); free(data); //usleep(3000); //END("group1", true); //is = SEND("main", "group1.main:pvmtslave.1", "group1", in1, in2 ); //printlog(DEBUG, "SEND returns %d\n", is); /*is = SEND("main", "group1.main:pvmtslave.1", "group1", in2 ); printlog(DEBUG, "SEND returns %d\n", is);*/ //int slavetid = 321; //int input = 0 ; //double num = 6 ; ////gs_spawn("pvmtslave", argv, 0, "", 1, &slavetid) ; //gs_pack("%lf", 0, &num) ; //pvm_joingroup("group1"); ////pvm_initsend(PvmDataDefault) ; ////pvm_pkint(&input, 1, 1) ; ////pvm_pkdouble(&num, 1, 1) ; //pvm_send(slavetid, 1) ; //int bufid = pvm_recv(slavetid, 1) ; //pvm_upkdouble(&num, 1, 1) ; ////gs_unpack("lf", bufid, &num ) ; ////int info = pvm_catchout(stdout) ; ////info = pvm_spawn("pvmtslave",argv, 0, "", 1, &slavetid) ; //printf("num = %lf\n", num) ; //pvm_catchout(0) ; //pvm_kill(slavetid) ; ////pvm_exit() ; //system("pause") ; return 0; }
void StatisticManager::load() { QFile file( this->_path ); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { return; } // QTextStream in(&file); QString nameLine = in.readLine(); _names.append( nameLine.split( "\t" ) ); while (!in.atEnd()) { QString line = in.readLine(); QStringList list = line.split( "\t" ); this->_table.append( list ); } //********************************************************** QFile file2( "data/1D_parameterData.txt" ); if (!file2.open(QIODevice::ReadOnly | QIODevice::Text)) { return; } QTextStream in2(&file2); while (!in2.atEnd()) { QString line = in2.readLine(); _1DparaName.append( line ); } QFile file3( "data/1DT_parameterData.txt" ); if (!file3.open(QIODevice::ReadOnly | QIODevice::Text)) { return; } QTextStream in3(&file3); while (!in3.atEnd()) { QString line = in3.readLine(); _1DTparaName.append( line ); } return; }
//void yacobi_process(double* xk0, const int mnum, const int proc_num, const double eps) int main(int argc, char* argv[]) { if(argc != 2 || !isdigit(argv[1][0])) { printf("No argument number of process\nUsage: yacobi_starter 4\n"); return 0; } init(argv, 0, 0, 0, true, false); std::vector<double> x0 = {0, 0 , 0, 0, 0}; int proc_num = atoi(argv[1]), matr_num = 3; double eps = 0.00001; const char grname[] = "group1"; input<double*> in1(1, 1, x0.data(), x0.size()); input<int> in2(2, 1, matr_num, 1); input<int> in3(3, 1, proc_num, 1); input<double> in4(4, 1, eps, 1); INSTANTINATE(":prog_yacobi", "group1", 1, in1, in2, in3, in4); return 0; }
TEST(readBitsTest, orBits) { // NOTE!: In the binary diagrams below, the rightmost bit of each byte // is the LSB. size_t bitSize, bitOffset; char src[2]; char dest[4]; // SUBTEST: src size < 1 byte // // src = 101 // bit offset = 9 // dest = 10101010 10101010 10101010 10101010 // expected result = 10101010 11111010 10101010 10101010 bitSize = 3; bitOffset = 9; memset(src, 0x00, 2); src[0] = BOOST_BINARY(10100000); memset(dest, BOOST_BINARY(10101010), 4); std::istringstream in1(std::string(src, (bitSize + 7)/8)); readBits(in1, dest, bitSize, bitOffset, BITWISE_OR); EXPECT_EQ((char)BOOST_BINARY(10101010), dest[0]); EXPECT_EQ((char)BOOST_BINARY(11111010), dest[1]); EXPECT_EQ((char)BOOST_BINARY(10101010), dest[2]); EXPECT_EQ((char)BOOST_BINARY(10101010), dest[3]); // SUBTEST: byte-aligned with partial last byte // // src = 01010101 010 // bit offset = 8 // dest = 10101010 10101010 10101010 10101010 // expected result = 10101010 11111111 11101010 10101010 bitSize = 11; bitOffset = 8; memset(src, 0x00, 2); src[0] = BOOST_BINARY(01010101); src[1] = BOOST_BINARY(01000000); memset(dest, BOOST_BINARY(10101010), 4); std::istringstream in2(std::string(src, (bitSize + 7)/8)); readBits(in2, dest, bitSize, bitOffset, BITWISE_OR); EXPECT_EQ((char)BOOST_BINARY(10101010), dest[0]); EXPECT_EQ((char)BOOST_BINARY(11111111), dest[1]); EXPECT_EQ((char)BOOST_BINARY(11101010), dest[2]); EXPECT_EQ((char)BOOST_BINARY(10101010), dest[3]); // SUBTEST: not byte-aligned, src size > 1 byte // // src = 01010101 0101010 // bit offset = 4 // dest = 10101010 10101010 10101010 10101010 // expected result = 10101111 11111111 11101010 10101010 bitSize = 15; bitOffset = 4; memset(src, 0x00, 2); src[0] = BOOST_BINARY(01010101); src[1] = BOOST_BINARY(01010100); memset(dest, BOOST_BINARY(10101010), 4); std::istringstream in3(std::string(src, (bitSize + 7)/8)); readBits(in3, dest, bitSize, bitOffset, BITWISE_OR); EXPECT_EQ((char)BOOST_BINARY(10101111), dest[0]); EXPECT_EQ((char)BOOST_BINARY(11111111), dest[1]); EXPECT_EQ((char)BOOST_BINARY(11101010), dest[2]); EXPECT_EQ((char)BOOST_BINARY(10101010), dest[3]); }
TEST(RealWordTest, ORLinear) { typedef NeuralNetwork<double, LinearActivationFunction<double >> network; network nn; nn.setEntries(2); nn.setExits(1); nn.setLayersCount(1); nn.init(); std::vector<double> in1(2); std::vector<double> in2(2); std::vector<double> in3(2); std::vector<double> in4(2); in1[0] = 0; in1[1] = 0; in2[0] = 1; in2[1] = 0; in3[0] = 0; in3[1] = 1; in4[0] = 1; in4[1] = 1; std::vector<double> out0(1); std::vector<double> out1(1); out0[0] = 0; out1[0] = 1; //uczenie for (int i = 0; i < 1000; ++i) { std::vector<double> o; // nn.printWages(); nn.setInput(in1.begin(), in1.end()); o = nn.calcOutput(); // for (auto d : o) // { // std::cout << d << " :answer 0 0 \n"; // } nn.learn(out0.begin(), out0.end()); nn.setInput(in2.begin(), in2.end()); o = nn.calcOutput(); // for (auto d : o) // { // std::cout << d << " :answer 1 0 \n"; // } nn.learn(out1.begin(), out1.end()); nn.setInput(in3.begin(), in3.end()); o = nn.calcOutput(); // for (auto d : o) // { // std::cout << d << " :answer 0 1 \n"; // } nn.learn(out1.begin(), out1.end()); nn.setInput(in4.begin(), in4.end()); o = nn.calcOutput(); // for (auto d : o) // { // std::cout << d << " :answer 1 1 \n"; // } nn.learn(out1.begin(), out1.end()); } // nn.printWages(); //test std::vector<double> out; nn.setInput(in1.begin(), in1.end()); out = nn.calcOutput(); ASSERT_LT(out[0], 0.1); nn.setInput(in2.begin(), in2.end()); out = nn.calcOutput(); ASSERT_GT(out[0], 0.9); nn.setInput(in3.begin(), in3.end()); out = nn.calcOutput(); ASSERT_GT(out[0], 0.9); nn.setInput(in4.begin(), in4.end()); out = nn.calcOutput(); ASSERT_GT(out[0], 0.9); }
TEST(RealWordTest, XORLinear) { typedef NeuralNetwork<double, LinearActivationFunction<double >> network; network nn; //nn.setActivationfunction(LinearActivationFunction<double>(10)); nn.setEntries(2); nn.setExits(1); nn.setLayersCount(2); nn.setNeurons(1, 2); nn.init(); std::vector<double> in1(2); std::vector<double> in2(2); std::vector<double> in3(2); std::vector<double> in4(2); in1[0] = 0; in1[1] = 0; in2[0] = 1; in2[1] = 0; in3[0] = 0; in3[1] = 1; in4[0] = 1; in4[1] = 1; std::vector<double> out0(1); std::vector<double> out1(1); out0[0] = 0; out1[0] = 1; //uczenie for (int i = 0; i < 1000; ++i) { std::vector<double> o(1); nn.setInput(in1.begin(), in1.end()); o = nn.calcOutput(); nn.learn(out0.begin(), out0.end()); // // std::cout << "Wynik0: " << o[0] << "\n"; // nn.printWages(); nn.setInput(in2.begin(), in2.end()); o = nn.calcOutput(); nn.learn(out1.begin(), out1.end()); // // std::cout << "Wynik1: " << o[0] << "\n"; // nn.printWages(); nn.setInput(in3.begin(), in3.end()); o = nn.calcOutput(); nn.learn(out1.begin(), out1.end()); // // std::cout << "Wynik1: " << o[0] << "\n"; // nn.printWages(); nn.setInput(in4.begin(), in4.end()); o = nn.calcOutput(); nn.learn(out0.begin(), out0.end()); // // std::cout << "Wynik0: " << o[0] << "\n"; // nn.printWages(); } //test std::vector<double> out; std::vector<double> o(4); nn.setInput(in1.begin(), in1.end()); out = nn.calcOutput(); o[0] = out[0]; EXPECT_LT(out[0], 0.1); nn.setInput(in2.begin(), in2.end()); out = nn.calcOutput(); o[1] = out[0]; EXPECT_GT(out[0], 0.9); nn.setInput(in3.begin(), in3.end()); out = nn.calcOutput(); o[2] = out[0]; EXPECT_GT(out[0], 0.9); nn.setInput(in4.begin(), in4.end()); out = nn.calcOutput(); o[3] = out[0]; EXPECT_LT(out[0], 0.1); //std::cout << o[0] << " " << o[1] << " " << o[2] << " " << o[3] << "\n"; }
void pardrawscript() { cout<<"start"<<endl; TH1D *h1=new TH1D("h","correction factor for pi",100,0.995,1.005); ifstream in1("parpipill"); ifstream in2("parkpi"); ifstream in3("parkpipi"); double factore; double factormu; double factorpi1; double factorpi2; double factorpi3; //double factorelow; //double factoreup; double factoreerr; double factormuerr; double factorpi1err; double factorpi2err; double factorpi3err; double energy=0; vector<double> x,y1,y2,y3,xe,y1e,y2e,y3e;//y1elow,y1eup; x.clear(); xe.clear(); y1.clear(); y2.clear(); y3.clear(); //y1elow.clear(); //y1eup.clear(); y1e.clear(); y2e.clear(); y3e.clear(); char tmpstr[1000]; getline(in1,tmpstr); while(!in1.eof()){ in1>>energy; //energy+=1; //getline(in,tmpstr); //getline(in,tmpstr); in1>>factore>>factoreerr; in1>>factormu>>factormuerr; in1>>factorpi1>>factorpi1err; //getline(in,tmpstr); getline(in1,tmpstr); //h1->Fill(factore); //h2->Fill(factormu); //h3->Fill(factorpi); //if(fabs(factorpierr)>1) continue; x.push_back(energy); xe.push_back(0.0); y1.push_back(factorpi1); y1e.push_back(factorpi1err); //y1elow.push_back(factorelow); //y1eup.push_back(factoreup); //y2.push_back(factormu); //y2e.push_back(factormuerr); //y3.push_back(factorpi); //y3e.push_back(factorpierr); } getline(in2,tmpstr); while(!in2.eof()){ in2>>energy; //energy+=1; in2>>factorpi2>>factorpi2err; getline(in2,tmpstr); //h1->Fill(factore); //h2->Fill(factormu); //h3->Fill(factorpi); //if(fabs(factorpierr)>1) continue; //x.push_back(energy); //xe.push_back(0.0); y2.push_back(factorpi2); y2e.push_back(factorpi2err); //y1elow.push_back(factorelow); //y1eup.push_back(factoreup); //y2.push_back(factormu); //y2e.push_back(factormuerr); //y3.push_back(factorpi); //y3e.push_back(factorpierr); } getline(in3,tmpstr); while(!in3.eof()){ in3>>energy; //energy+=1; in3>>factorpi3>>factorpi3err; //getline(in,tmpstr); getline(in3,tmpstr); //h1->Fill(factore); //h2->Fill(factormu); //h3->Fill(factorpi); //if(fabs(factorpierr)>1) continue; //x.push_back(energy); //xe.push_back(0.0); y3.push_back(factorpi3); y3e.push_back(factorpi3err); //y1elow.push_back(factorelow); //y1eup.push_back(factoreup); //y2.push_back(factormu); //y2e.push_back(factormuerr); //y3.push_back(factorpi); //y3e.push_back(factorpierr); } //h1->Fit("gaus"); //h2->Fit("gaus"); //h3->Fit("gaus"); const double n=x.size()-1; //const double n=104; double ene[n],enee[n]; double fpi1[n],fpi1e[n],fpi2[n],fpi2e[n],fpi3[n],fpi3e[n]; //double fe[n],feelow[n],feeup[n]; //double fmu[n],fmue[n]; //double fpi[n],fpie[n]; for(int i=0;i<n;i++){ ene[i]=x.at(i); enee[i]=0; fpi1[i] =y1.at(i); fpi1e[i]=y1e.at(i); fpi2[i] =y2.at(i); fpi2e[i]=y2e.at(i); fpi3[i] =y3.at(i); fpi3e[i]=y3e.at(i); } // combine three factors to one //ofstream of("pion.par"); double factor[n],factorerr[n]; for(int i=0;i<n;i++){ factor[i]=(fpi1[i]/fpi1e[i]+fpi2[i]/fpi2e[i]+fpi3[i]/fpi3e[i]) /(1./fpi1e[i]+1./fpi2e[i]+1./fpi3e[i]); factorerr[i]=sqrt(3) /(1./fpi1e[i]+1./fpi2e[i]+1./fpi3e[i]); h1->Fill(factor[i]); //of<<ene[i]<<"\t"<<factor<<"\n"; } //gStyle->SetOptFit(1111); //TF1 *f=new TF1("f","[0]",3800,4600); //f->SetParameter(0,1.0); cout<<"create graph,n point "<<n<<endl; //TGraphAsymmErrors *graph1=new TGraphAsymmErrors(n,ene,fe,enee,enee,feelow,feeup); TGraphErrors *graph1=new TGraphErrors(n,ene,fpi1,enee,fpi1e); TGraphErrors *graph2=new TGraphErrors(n,ene,fpi2,enee,fpi2e); TGraphErrors *graph3=new TGraphErrors(n,ene,fpi3,enee,fpi3e); graph1->SetMinimum(0.995); graph1->SetMaximum(1.005); graph2->SetMinimum(0.995); graph2->SetMaximum(1.005); graph3->SetMinimum(0.995); graph3->SetMaximum(1.005); //TGraphErrors *graph2=new TGraphErrors(n,ene,fmu,enee,fmue); //graph2->SetMarkerStyle(5); //graph2->Fit(f); //graph2->SetMinimum(0.95); //graph2->SetMaximum(1.05); TCanvas *c1=new TCanvas(); graph1->Draw("AP"); graph2->Draw("same"); graph3->Draw("same"); graph1->SetMarkerStyle(2); graph1->SetMarkerColor(2); graph1->SetLineColor(2); graph1->SetFillColor(kWhite); graph2->SetMarkerStyle(4); graph2->SetMarkerColor(3); graph2->SetLineColor(3); graph2->SetFillColor(kWhite); graph3->SetMarkerStyle(5); graph3->SetMarkerColor(4); graph3->SetLineColor(4); graph3->SetFillColor(kWhite); TLegend *legend=new TLegend(0.70,0.75,0.90,0.90); legend->AddEntry(graph1,"#psi' --> #pi^{+}#pi^{-} J/#psi"); legend->AddEntry(graph2,"D^{0} --> K^{+} #pi^{-}"); legend->AddEntry(graph3,"D^{+} --> K^{-} #pi^{+} #pi^{+}"); legend->Draw(); TCanvas *c2 = new TCanvas(); TGraphErrors *graph4=new TGraphErrors(n,ene,factor,enee,factorerr); graph4->Draw("AP"); TCanvas *c3 = new TCanvas(); h1->Draw(); h1->Fit("gaus"); //exit(); }
void graf_test::wczytaj_graf(){ int id, wg, nr; ifstream in1("graf1.txt"); ifstream in2("graf2.txt"); ifstream in3("graf3.txt"); ifstream in4("graf4.txt"); ifstream in5("graf5.txt"); ifstream in6("graf6.txt"); for(int i = 0; i<10; i++) G1.dodaj_wierzcholek(); for(int i = 0; i<100; i++) G2.dodaj_wierzcholek(); for(int i = 0; i<1000; i++) G3.dodaj_wierzcholek(); for(int i = 0; i<10000; i++) G4.dodaj_wierzcholek(); for(int i = 0; i<50000; i++) G5.dodaj_wierzcholek(); for(int i = 0; i<100000; i++) G6.dodaj_wierzcholek(); /*dodano wierzcholki, teraz tworzymy liste incydencji*/ for(int i = 0; i<10; i++){ in1>>nr; for(int k = 0; k<5; k++){ in1>>id>>wg; G1.dodaj_krawedz(i,id,wg); } } for(int i = 0; i<100; i++){ in2>>nr; for(int k = 0; k<5; k++){ in2>>id>>wg; G2.dodaj_krawedz(i,id,wg); } } for(int i = 0; i<1000; i++){ in3>>nr; for(int k = 0; k<5; k++){ in3>>id>>wg; G3.dodaj_krawedz(i,id,wg); } } for(int i = 0; i<10000; i++){ in4>>nr; for(int k = 0; k<5; k++){ in4>>id>>wg; G4.dodaj_krawedz(i,id,wg); } } for(int i = 0; i<50000; i++){ in5>>nr; for(int k = 0; k<5; k++){ in5>>id>>wg; G5.dodaj_krawedz(i,id,wg); } } for(int i = 0; i<100000; i++){ in6>>nr; for(int k = 0; k<5; k++){ in6>>id>>wg; G6.dodaj_krawedz(i,id,wg); } } G1.rysuj(); }
void RenderBrick::getScreenCoordinates( const Frustum& frustum, const PixelViewport& pvp, Vector2i& minScreenPos, Vector2i& maxScreenPos ) const { const Vector3f& minPos = lodNodePtr_->getWorldBox().getMin(); const Vector3f& maxPos = lodNodePtr_->getWorldBox().getMax(); const double x[ 2 ] = { minPos[ 0 ], maxPos[ 0 ] }; const double y[ 2 ] = { minPos[ 1 ], maxPos[ 1 ] }; const double z[ 2 ] = { minPos[ 2 ], maxPos[ 2 ] }; double xMax = -std::numeric_limits< double >::max(); double yMax = -std::numeric_limits< double >::max(); double xMin = -xMax; double yMin = -yMax; for( int32_t i = 0; i < 2; ++i ) { for( int32_t j = 0; j < 2; ++j ) { for( int32_t k = 0; k < 2; ++k ) { // based on gluProject code from SGI implementation const Matrix4d& mv = frustum.getModelViewMatrix(); const Matrix4d& proj = frustum.getProjectionMatrix(); Vector4d in( x[ i ], y[ j ], z[ k ], 1.0 ); Vector4d out = mv * in; in = proj * out; if( in.w() == 0.0 ) continue; in.normalize(); /* The perspective correction is done in the constructor */ Vector3d in3( in ); /* Map x, y and z to range 0-1 */ in3 = in3 * 0.5 + 0.5; /* Map x,y to viewport */ in3[0] = in3[0] * pvp[2] + pvp[0]; in3[1] = in3[1] * pvp[3] + pvp[1]; if( in3[0] > xMax ) xMax = in3[0]; if( in3[1] > yMax ) yMax = in3[1]; if( in3[0] < xMin ) xMin = in3[0]; if( in3[1] < yMin ) yMin = in3[1]; } } } xMin = maths::clamp( xMin + 0.5, (double)pvp[0], (double)pvp[0] + (double)pvp[2] ); yMin = maths::clamp( yMin + 0.5, (double)pvp[1], (double)pvp[1] + (double)pvp[3] ); xMax = maths::clamp( xMax + 0.5, (double)pvp[0], (double)pvp[0] + (double)pvp[2] ); yMax = maths::clamp( yMax + 0.5, (double)pvp[1], (double)pvp[1] + (double)pvp[3] ); minScreenPos = Vector2i( xMin, yMin ); maxScreenPos = Vector2i( xMax, yMax ); }
bool BotanWrapper::DecryptFile(QString Source, QString Destination) { //qDebug() << "\n\n"; QFileInfo name = Source; //qDebug() << Source; QString base = name.baseName(); //qDebug() << base; QString encrypted3 = soutput + base + ".serpentdecrypted"; //qDebug() << soutput; QString encrypted4 = tfoutput + base + ".twofishdecrypted"; //qDebug() << toutput; try { //Setup the key derive functions PKCS5_PBKDF2 pbkdf2(new HMAC(new Keccak_1600)); const u32bit PBKDF2_ITERATIONS = 700000; string inFilename3 = Source.toStdString(); string outFilename3 = encrypted3.toStdString(); std::ifstream in3(inFilename3.c_str(),std::ios::binary); std::ofstream out3(outFilename3.c_str(),std::ios::binary); char* salt3 = new char[256]; in3.read(salt3 , 256 ); qDebug() << "create salt"; SecureVector<byte> salts3((const byte*)salt3, 256 ) ; mSalt3 = salts3; //Create the KEY and IV KDF* kdf3 = get_kdf("KDF2(Tiger)"); qDebug() << "create master key"; //Create the master key SecureVector<byte> mMaster3 = pbkdf2.derive_key(128, mPassword3.toStdString(), &mSalt3[0], mSalt3.size(),PBKDF2_ITERATIONS).bits_of(); SymmetricKey mKey3 = kdf3->derive_key(32, mMaster3, "salt1"); InitializationVector mIV3 = kdf3->derive_key(16, mMaster3, "salt2"); qDebug() << "begin serpent decrypt"; Pipe pipe3(get_cipher("Serpent/CBC/PKCS7", mKey3, mIV3,DECRYPTION),new DataSink_Stream(out3)); pipe3.start_msg(); in3 >> pipe3; pipe3.end_msg(); out3.flush(); out3.close(); in3.close(); /*************************TWOFISH DECRYPTION*************************/ PKCS5_PBKDF2 pbkdf3(new HMAC(new Skein_512)); string inFilename2 = encrypted3.toStdString(); string outFilename2 = encrypted4.toStdString(); std::ifstream in2(inFilename2.c_str(),std::ios::binary); std::ofstream out2(outFilename2.c_str(),std::ios::binary); char* salt2 = new char[256]; in2.read(salt2 , 256 ); SecureVector<byte> salts2((const byte*)salt2, 256 ) ; mSalt2 = salts2; //Create the KEY and IV KDF* kdf2 = get_kdf("KDF2(Whirlpool)"); //Create the master key SecureVector<byte> mMaster2 = pbkdf3.derive_key(128, mPassword2.toStdString(), &mSalt2[0], mSalt2.size(),PBKDF2_ITERATIONS).bits_of(); SymmetricKey mKey2 = kdf2->derive_key(32, mMaster2, "salt1"); InitializationVector mIV2 = kdf2->derive_key(16, mMaster2, "salt2"); qDebug() << "twofish"; Pipe pipe2(get_cipher("Twofish/CFB", mKey2, mIV2,DECRYPTION),new DataSink_Stream(out2)); pipe2.start_msg(); in2 >> pipe2; pipe2.end_msg(); out2.flush(); out2.close(); in2.close(); /************AES DECRYPTION*************************/ string inFilename = encrypted4.toStdString(); string outFilename = Destination.toStdString(); std::ifstream in(inFilename.c_str(),std::ios::binary); std::ofstream out(outFilename.c_str(),std::ios::binary); char* salt = new char[256]; in.read(salt , 256 ); SecureVector<byte> salts((const byte*)salt, 256 ) ; mSalt = salts; //Create the KEY and IV KDF* kdf = get_kdf("KDF2(SHA-512)"); //Create the master key SecureVector<byte> mMaster = pbkdf2.derive_key(128, mPassword.toStdString(), &mSalt[0], mSalt.size(),PBKDF2_ITERATIONS).bits_of(); SymmetricKey mKey = kdf->derive_key(32, mMaster, "salt1"); InitializationVector mIV = kdf->derive_key(16, mMaster, "salt2"); qDebug() << "AES"; Pipe pipe(get_cipher("AES-256/EAX", mKey, mIV,DECRYPTION),new DataSink_Stream(out)); pipe.start_msg(); in >> pipe; pipe.end_msg(); out.flush(); out.close(); in.close(); QMessageBox msgBox; msgBox.setText("Success!"); msgBox.setInformativeText("File successfully decrypted!"); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok); msgBox.exec(); QFile s(encrypted3), t(encrypted4); s.remove(); t.remove(); return true; } catch(...) { return false; } }
/*---------------------------------------------------------------------- | main +---------------------------------------------------------------------*/ int main(int /*argc*/, char** /*argv*/) { // setup debugging #if defined(WIN32) && defined(_DEBUG) int flags = _crtDbgFlag | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF; _CrtSetDbgFlag(flags); //AllocConsole(); //freopen("CONOUT$", "w", stdout); #endif for (unsigned int t=0; t<sizeof(TestVectors)/sizeof(TestVectors[0]); t++) { TestVector* v = &TestVectors[t]; NPT_DataBuffer in1(v->compressed, v->compressed_len); NPT_DataBuffer out1; NPT_Result result = NPT_Zip::Inflate(in1, out1); CHECK(result == NPT_SUCCESS); CHECK(out1.GetDataSize() == v->uncompressed_len); CHECK(NPT_MemoryEqual(out1.GetData(), v->uncompressed, v->uncompressed_len)); NPT_DataBuffer in2(v->uncompressed, v->uncompressed_len); NPT_DataBuffer out2; NPT_DataBuffer out2_check; result = NPT_Zip::Deflate(in2, out2, NPT_ZIP_COMPRESSION_LEVEL_MAX, NPT_Zip::GZIP); CHECK(result == NPT_SUCCESS); result = NPT_Zip::Inflate(out2, out2_check); CHECK(result == NPT_SUCCESS); CHECK(out2_check.GetDataSize() == in2.GetDataSize()); CHECK(NPT_MemoryEqual(v->uncompressed, out2_check.GetData(), in2.GetDataSize())); // try with random data NPT_DataBuffer in3(300000); unsigned char* in3_p = in3.UseData(); for (int i=0; i<300000; i++) { *in3_p++ = NPT_System::GetRandomInteger(); } in3.SetDataSize(300000); NPT_DataBuffer out3; result = NPT_Zip::Deflate(in3, out3); CHECK(result == NPT_SUCCESS); NPT_DataBuffer out3_check; result = NPT_Zip::Inflate(out3, out3_check); CHECK(result == NPT_SUCCESS); CHECK(in3 == out3_check); // try with redundant data in3_p = in3.UseData(); for (int i=0; i<200000; i+=4) { *in3_p++ = NPT_System::GetRandomInteger(); *in3_p++ = 0; *in3_p++ = 0; *in3_p++ = 0; } result = NPT_Zip::Deflate(in3, out3); CHECK(result == NPT_SUCCESS); result = NPT_Zip::Inflate(out3, out3_check); CHECK(result == NPT_SUCCESS); CHECK(in3 == out3_check); // streams for (unsigned int x=0; x<1000; x++) { NPT_MemoryStream* ms_gz = new NPT_MemoryStream(v->compressed, v->compressed_len); NPT_InputStreamReference ms_gz_ref(ms_gz); NPT_ZipInflatingInputStream ziis(ms_gz_ref); NPT_DataBuffer buffer; NPT_Position position = 0; bool expect_eos = false; for (;;) { NPT_Size chunk = NPT_System::GetRandomInteger()%40000; buffer.SetDataSize(chunk); NPT_Size bytes_read = 0; result = ziis.Read(buffer.UseData(), chunk, &bytes_read); if (expect_eos) { CHECK(result == NPT_ERROR_EOS); break; } if (result == NPT_ERROR_EOS) { CHECK(position == v->uncompressed_len); } else { CHECK(result == NPT_SUCCESS); } CHECK(bytes_read <= chunk); if (bytes_read != chunk) expect_eos = true; CHECK(NPT_MemoryEqual(v->uncompressed+position, buffer.GetData(), bytes_read)); position += bytes_read; } CHECK(position == v->uncompressed_len); } for (unsigned int x=0; x<1000; x++) { NPT_MemoryStream* ms = new NPT_MemoryStream(v->uncompressed, v->uncompressed_len); NPT_InputStreamReference ms_ref(ms); NPT_ZipDeflatingInputStream zdis(ms_ref, NPT_ZIP_COMPRESSION_LEVEL_MAX, NPT_Zip::GZIP); NPT_DataBuffer buffer; NPT_Position position = 0; bool expect_eos = false; for (;;) { NPT_Size chunk = NPT_System::GetRandomInteger()%40000; buffer.Reserve(buffer.GetDataSize()+chunk); NPT_Size bytes_read = 0; result = zdis.Read(buffer.UseData()+buffer.GetDataSize(), chunk, &bytes_read); if (expect_eos) { CHECK(result == NPT_ERROR_EOS); break; } CHECK(result == NPT_SUCCESS); CHECK(bytes_read <= chunk); if (bytes_read != chunk) expect_eos = true; position += bytes_read; buffer.SetDataSize(buffer.GetDataSize()+bytes_read); } NPT_DataBuffer out; NPT_DataBuffer check(v->uncompressed, v->uncompressed_len); CHECK(NPT_Zip::Inflate(buffer, out) == NPT_SUCCESS); CHECK(out == check); } } return 0; }
int main(int argc, char** argv) { //Check for arg if(argc < 2) error("no file name provided. Exiting."); //Verify file exists std::filebuf buffer; if(!buffer.open(argv[1],std::ios::in)) error("Error opening file. Verify it exists."); std::istream in(&buffer); //Verify tag structure if(!pass1(&in)) error("mismatched tag brackets. \nPlease verify correct structure."); std::filebuf buffer2; buffer2.open(argv[1],std::ios::in); std::istream in2(&buffer2); if(!pass2(&in2)) error("Mismatched tags. Please verify all tags have matching close tag"); std::filebuf buffer3; buffer3.open(argv[1],std::ios::in); std::istream in3(&buffer3); std::vector<Employee*> employees; //Read in Employees to XML Employee* e; while(!in3.eof()) { char c = in3.peek(); if(isspace(c) || c == EOF) { in3.get(); continue; } //std::cout << in3.peek() << std::endl; // std::cout << in3.eof() << std::endl; e = Employee::fromXML(in3); if(e == nullptr) error("Missing or incorrect employee attribute."); employees.push_back(e); } //delete e; buffer3.close(); //Print out employees to std::cout for(int i=0; i < employees.size(); i++) { employees[i]->display(std::cout); std::cout << std::endl; std::cout.flush(); } std::cout << std::endl; //Print out employees to file // //this is stupid and kind of hack-y but I did it for a good reason. //When opening my fstream below, opening with the 'in' and 'out' params //consistently failed. I presume because when doing so fstream tries to //open an istream from a non-existent file. // //So instead I open, create file, close, and reopen with in,out, and binary. std::fstream fs(OUTPUT_FILE,std::ios::out); fs.close(); fs.open(OUTPUT_FILE,std::ios::in | std::ios::out | std::ios::binary); if(fs.fail()) error("Failed to open fstream."); for(int i = 0; i < employees.size(); i++) { employees[i]->write(fs); fs << "\n"; // delete employees[i]; } fs.flush(); //clear vector employees.clear(); //reset fstream to beginning of file - for whatever reason seekg only wored once. //had to close and reopen for each ensuing operation./ refreshFstream(fs); //repopulate vector with calls to read (from employee.bin...correct???) while(!fs.eof()) { if(isspace(fs.peek())) { fs.get(); continue; } Employee* e = Employee::read(fs); if(e != nullptr) employees.push_back(e); } //print to cout XML representation of employees for(int i = 0; i < employees.size(); i++) { employees[i]->toXML(std::cout); std::cout << "\n"; // delete employees[i]; } std::cout << std::endl; //reset fstream to beginning of file fs.clear(); fs.seekg(0,fs.beg); //find employee 12345 and print out e = Employee::retrieve(fs,12345); std::cout << "Found:" << std::endl; e->display(std::cout); std::cout << std::endl; //update salary e->setSalary(150000.0); //store in XML file refreshFstream(fs); e->store(fs); // delete e; //Retrieve and print salary refreshFstream(fs); e = Employee::retrieve(fs,12345); std::cout << e->getSalary() << "\n" << std::endl; // delete e; //is it awesome or pathetic that I knew these lyrics? I'll let you be the judge. Employee* my_e = new Employee(1987,std::string("Rick Astley"),std::string("Never Gonna Give You Up street"),std::string("Never Gonna Let You Down city"),std::string("Never Gonna Run Around and Desert You state"),std::string("England"),std::string("1-888-RICKROLLED"),1000.0); refreshFstream(fs); my_e->store(fs); fs.flush(); //reset fs for retrieval and printing of Mr. Astley refreshFstream(fs); e = Employee::retrieve(fs,1987); e->display(std::cout); std::cout << std::endl; // delete e; fs.close(); // delete my_e; // delete e; }
void astar::wczytaj_graf(){ int id, wg, nr; ifstream in1("graf1.txt"); ifstream in2("graf2.txt"); ifstream in3("graf3.txt"); ifstream in4("graf4.txt"); ifstream in5("graf5.txt"); ifstream in6("graf6.txt"); for(int i = 0; i<10; i++) G1.dodaj_wierzcholek(i); for(int i = 0; i<100; i++) G2.dodaj_wierzcholek(i); for(int i = 0; i<1000; i++) G3.dodaj_wierzcholek(i); for(int i = 0; i<10000; i++) G4.dodaj_wierzcholek(i); for(int i = 0; i<50000; i++) G5.dodaj_wierzcholek(i); for(int i = 0; i<100000; i++) G6.dodaj_wierzcholek(i); for(int i = 0; i<10; i++){ in1>>nr; for(int k = 0; k<5; k++){ in1>>id>>wg; G1.dodaj_krawedz(i,id); } } for(int i = 0; i<100; i++){ in2>>nr; for(int k = 0; k<5; k++){ in2>>id>>wg; G2.dodaj_krawedz(i,id); } } for(int i = 0; i<1000; i++){ in3>>nr; for(int k = 0; k<5; k++){ in3>>id>>wg; G3.dodaj_krawedz(i,id); } } for(int i = 0; i<10000; i++){ in4>>nr; for(int k = 0; k<5; k++){ in4>>id>>wg; G4.dodaj_krawedz(i,id); } } for(int i = 0; i<50000; i++){ in5>>nr; for(int k = 0; k<5; k++){ in5>>id>>wg; G5.dodaj_krawedz(i,id); } } for(int i = 0; i<100000; i++){ in6>>nr; for(int k = 0; k<5; k++){ in6>>id>>wg; G6.dodaj_krawedz(i,id); } } }
void weightedpar() { cout<<"start"<<endl; //TH1D *h1=new TH1D("h1","factor e",50,0.98,1.02); //TH1D *h2=new TH1D("h2","factor mu",30,0.95,1.05); //TH1D *h3=new TH1D("h3","factor pi(ee)",30,0.95,1.05); //TH1D *h4=new TH1D("h4","factor pi(mumu)",30,0.95,1.05); TH1D *h1=new TH1D("h","correction factor for pi",30,0.95,1.05); ifstream in1("parpipill"); ifstream in2("parkpi"); ifstream in3("parkpipi"); double factore; double factormu; double factorpi1; double factorpi2; double factorpi3; double factoreerr; double factormuerr; double factorpi1err; double factorpi2err; double factorpi3err; double energy=0; vector<double> x,y1,y2,y3,xe,y1e,y2e,y3e;//y1elow,y1eup; x.clear(); xe.clear(); y1.clear(); y2.clear(); y3.clear(); //y1elow.clear(); //y1eup.clear(); y1e.clear(); y2e.clear(); y3e.clear(); char tmpstr[1000]; getline(in1,tmpstr); while(!in1.eof()){ in1>>energy; //energy+=1; //getline(in,tmpstr); //getline(in,tmpstr); in1>>factore>>factoreerr; in1>>factormu>>factormuerr; in1>>factorpi1>>factorpi1err; //getline(in,tmpstr); getline(in1,tmpstr); //h1->Fill(factore); //h2->Fill(factormu); //h3->Fill(factorpi); //if(fabs(factorpierr)>1) continue; x.push_back(energy); xe.push_back(0.0); y1.push_back(factorpi1); y1e.push_back(factorpi1err); //y1elow.push_back(factorelow); //y1eup.push_back(factoreup); //y2.push_back(factormu); //y2e.push_back(factormuerr); //y3.push_back(factorpi); //y3e.push_back(factorpierr); } getline(in2,tmpstr); while(!in2.eof()){ in2>>energy; //energy+=1; in2>>factorpi2>>factorpi2err; getline(in2,tmpstr); //h1->Fill(factore); //h2->Fill(factormu); //h3->Fill(factorpi); //if(fabs(factorpierr)>1) continue; //x.push_back(energy); //xe.push_back(0.0); y2.push_back(factorpi2); y2e.push_back(factorpi2err); //y1elow.push_back(factorelow); //y1eup.push_back(factoreup); //y2.push_back(factormu); //y2e.push_back(factormuerr); //y3.push_back(factorpi); //y3e.push_back(factorpierr); } getline(in3,tmpstr); while(!in3.eof()){ in3>>energy; //energy+=1; in3>>factorpi3>>factorpi3err; //getline(in,tmpstr); getline(in3,tmpstr); //h1->Fill(factore); //h2->Fill(factormu); //h3->Fill(factorpi); //if(fabs(factorpierr)>1) continue; //x.push_back(energy); //xe.push_back(0.0); y3.push_back(factorpi3); y3e.push_back(factorpi3err); //y1elow.push_back(factorelow); //y1eup.push_back(factoreup); //y2.push_back(factormu); //y2e.push_back(factormuerr); //y3.push_back(factorpi); //y3e.push_back(factorpierr); } const double n=x.size()-1; //const double n=104; double ene[n],enee[n]; double fpi1[n],fpi1e[n],fpi2[n],fpi2e[n],fpi3[n],fpi3e[n]; for(int i=0;i<n;i++){ ene[i]=x.at(i); enee[i]=0; fpi1[i] =y1.at(i); fpi1e[i]=y1e.at(i); fpi2[i] =y2.at(i); fpi2e[i]=y2e.at(i); fpi3[i] =y3.at(i); fpi3e[i]=y3e.at(i); } ofstream of("pion.par"); double factor; for(int i=0;i<n;i++){ factor=(fpi1[i]/fpi1e[i]+fpi2[i]/fpi2e[i]+fpi3[i]/fpi3e[i]) /(1./fpi1e[i]+1./fpi2e[i]+1./fpi3e[i]); of<<ene[i]<<"\t"<<factor<<"\n"; } exit(); }