void parse(int c) { printf("\x1b[01;31m%c:%c[%.*s]\x1b[00m",state,c,(int)(stack-b_stack),b_stack); switch(state) { case 'C': if(c=='I') { out1("arg"); } if(c=='{') { *stack++='('; state='X'; } break; case 'F': state='X'; if(c=='=' && stack>b_stack && stack[-1]=='v') { out1("local"); } out1(c=='=' ? "ident" : "get"); case 'P': if(c=='(') { *stack++='f'; *stack++='('; outo('('); break; } case 'X': if(c=='N') { out1("num"); } else if(c=='I') { int l=ident-b_ident; if(l==8&&memcmp("function",b_ident,ident-b_ident)==0) { state='C'; outn("def",closuren); outn("args",closuren); *fstack++=closuren++; } else if(l==3&&memcmp("var",b_ident,ident-b_ident)==0) { *stack++='v'; } else if(l==6&&memcmp("return",b_ident,ident-b_ident)==0) { *stack++='r'; } else { state='F'; } } else if(c==';') { unstack(0); outo(';'); } else if(c=='(') { *stack++='('; out1("com ("); } else if(c==')') { unstack(0); stack--; state='P'; } else if(c=='}') { unstack(0); stack--; outn("end",*(--fstack)); } else { unstack(c); *stack++=c; } break; default: goto abort; } return; abort: printf("\n Parse abort: char '%c' state '%c'\n",c,state); abort(); }
static I impl(I begin, I end, C pred, P proj, D len, Pair const p, concepts::ForwardIterator *fi) { // *begin is known to be false // len >= 1 if(len == 1) return begin; if(len == 2) { I tmp = begin; if(invoke(pred, invoke(proj, *++tmp))) { ranges::iter_swap(begin, tmp); return tmp; } return begin; } if(len <= p.second) { // The buffer is big enough to use // Move the falses into the temporary buffer, and the trues to the front of the line // Update begin to always point to the end of the trues auto tmpbuf = make_raw_buffer(p.first); auto buf = tmpbuf.begin(); *buf = iter_move(begin); ++buf; auto res = partition_copy(make_move_iterator(next(begin)), make_move_sentinel(end), begin, buf, std::ref(pred), std::ref(proj)); // All trues now at start of range, all falses in buffer // Move falses back into range, but don't mess up begin which points to first false ranges::move(p.first, res.out2().base().base(), res.out1()); // h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer return res.out1(); } // Else not enough buffer, do in place // len >= 3 D half = len / 2; // half >= 2 I middle = next(begin, half); // recurse on [begin, middle), *begin know to be false // F????????????????? // f m l I begin_false = stable_partition_fn::impl(begin, middle, pred, proj, half, p, fi); // TTTFFFFF?????????? // f ff m l // recurse on [middle, end], except increase middle until *(middle) is false, *end know to be true I m1 = middle; D len_half = len - half; while(invoke(pred, invoke(proj, *m1))) { if(++m1 == end) return ranges::rotate(begin_false, middle, end).begin(); --len_half; } // TTTFFFFFTTTF?????? // f ff m m1 l I end_false = stable_partition_fn::impl(m1, end, pred, proj, len_half, p, fi); // TTTFFFFFTTTTTFFFFF // f ff m sf l return ranges::rotate(begin_false, middle, end_false).begin(); // TTTTTTTTFFFFFFFFFF // | }
int ex2(struct parser* p) { int label_1 = label_count++; int stop = 0; if (ex3(p)) { out3("BF", label_1); } else if (output(p)) { } else { stop = 1; } if (stop) return 0; while (!stop) { if (ex3(p)) { out1("BE"); } else if (output(p)) { } else { stop = 1; } } generate_label(label_1); return 1; }
void System::saveCurrentProfile(std::vector<QString> interfaces, QString defaultPolicyIN, QString defaultPolicyOUT) { //Writing the changes to the profile file QString pathString; QTextStream pathStream(&pathString); pathStream << this->systemPath << "/profiles/" << this->currentProfile->getName() << ".txt"; QFile currentProfile(pathString); currentProfile.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out1(¤tProfile); out1 << this->currentProfile->getName() << "\n"; out1 << defaultPolicyIN << "\n"; out1 << defaultPolicyOUT << "\n"; out1 << this->currentProfile->getCreationDate() << "\n"; out1 << this->currentProfile->getSystemTime() << "\n"; currentProfile.close(); //Writing the changes of interfaces to the profile's interface file QString pathString2; QTextStream pathStream2(&pathString2); pathStream2 << this->systemPath << "/profiles/" << this->currentProfile->getName() << "-interfaces.txt"; QFile currentProfileInterfaces(pathString2); currentProfileInterfaces.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out2(¤tProfileInterfaces); out2 << interfaces.size() << "\n"; for (unsigned int i=0;i<interfaces.size();i++) out2 << interfaces.at(i) << "\n"; currentProfileInterfaces.close(); //Reload the currentProfile with the new changes this->updateProfileInfo(this->currentProfile->getName()); }
int TriangleSetTopologyContainer::getTriangleIndex(PointID v1, PointID v2, PointID v3) { if(!hasTrianglesAroundVertex()) createTrianglesAroundVertexArray(); sofa::helper::vector<unsigned int> set1 = getTrianglesAroundVertex(v1); sofa::helper::vector<unsigned int> set2 = getTrianglesAroundVertex(v2); sofa::helper::vector<unsigned int> set3 = getTrianglesAroundVertex(v3); sort(set1.begin(), set1.end()); sort(set2.begin(), set2.end()); sort(set3.begin(), set3.end()); // The destination vector must be large enough to contain the result. sofa::helper::vector<unsigned int> out1(set1.size()+set2.size()); sofa::helper::vector<unsigned int>::iterator result1; result1 = std::set_intersection(set1.begin(),set1.end(),set2.begin(),set2.end(),out1.begin()); out1.erase(result1,out1.end()); sofa::helper::vector<unsigned int> out2(set3.size()+out1.size()); sofa::helper::vector<unsigned int>::iterator result2; result2 = std::set_intersection(set3.begin(),set3.end(),out1.begin(),out1.end(),out2.begin()); out2.erase(result2,out2.end()); #ifndef NDEBUG if(out2.size() > 1) sout << "Warning. [TriangleSetTopologyContainer::getTriangleIndex] more than one triangle found" << sendl; #endif if (out2.size()==1) return (int) (out2[0]); else return -1; }
// examples might be ".OUT('GN1')" or ".OUT(.LABEL *1)"? // I think I have a typo or three: // OUTPUT = ('.OUT' '(' // \$ OUT1 ')' / '.LABEL' .OUT('LB') OUT1) .OUT('OUT') ., void output() { istoken(TOKEN_OUT); istoken(TOKEN_OPEN_PAREN); is_token(TOKEN_LABEL); emit(OP_LB); out1(); emit(OP_OUT); }
int main() { auto string = QStringLiteral("FooBar"); QByteArray block1, block2; QDataStream out1(&block1, QIODevice::WriteOnly), out2(&block2, QIODevice::WriteOnly); out1 << quint16(0) << string; operator<<(out2.operator<<(quint16(0)), string); Q_ASSERT(block1 == block2); }
void OptionsWindow::SaveAConfig(int step, bool nomesseage = true) { QSettings *GlobalSettings = new QSettings("/root/.WiFiHostapdAP/WiFi_Hostapd_AP.conf",QSettings::NativeFormat); // creating a new object // Функция сохраения конфигурационных файлов по маске // №1 - что сохраняем - 0 = только HOSTAPD; 1 - DNSMASQ QString temp; QDateTime TimeNow; QString dateUNIXNow; if(step == 0) { // Save only HOSTAPD temp = getMaskToConfig(0); QFile::remove("/etc/hostapd/hostapd.conf"); QFile hostapd_config("/etc/hostapd/hostapd.conf"); hostapd_config.open(QIODevice::WriteOnly); QTextStream out(&hostapd_config); out << temp; hostapd_config.close(); dateUNIXNow = QString::number(TimeNow.currentDateTime().toTime_t()); emit toMainLog(QString("%1|%2|%3|%4").arg(tr("Options"), dateUNIXNow, tr("Hostapd config succesfully update."), QString("1"))); // Hostapd if(!nomesseage) { QMessageBox msgBoxHostapd; msgBoxHostapd.setText(tr("The configuration file is updated")); msgBoxHostapd.setIcon(QMessageBox::Information); msgBoxHostapd.setInformativeText(tr("Hostapd Settings saved successfully. To enter into force, please restart the access point.")); msgBoxHostapd.setStandardButtons(QMessageBox::Ok); msgBoxHostapd.setDefaultButton(QMessageBox::Ok); msgBoxHostapd.exec(); } temp.clear(); } else { // Сохраняемфайл DNSMASQ // 1 temp = getMaskToConfig(1); QFile::remove("/etc/dnsmasq.conf"); QFile firstDHCPConfig("/etc/dnsmasq.conf"); firstDHCPConfig.open(QIODevice::WriteOnly); QTextStream out1(&firstDHCPConfig); out1 << temp; firstDHCPConfig.close(); temp.clear(); dateUNIXNow = QString::number(TimeNow.currentDateTime().toTime_t()); emit toMainLog(QString("%1|%2|%3|%4").arg(tr("Options"), dateUNIXNow, tr("DNSMASQ config succesfully update."), QString("1"))); // DHCP if(!nomesseage) { QMessageBox msgBoxDHCP; msgBoxDHCP.setText(tr("The configuration file is updated")); msgBoxDHCP.setIcon(QMessageBox::Information); msgBoxDHCP.setInformativeText(tr("DHCP Settings saved successfully. To enter into force, please restart the access point.")); msgBoxDHCP.setStandardButtons(QMessageBox::Ok); msgBoxDHCP.setDefaultButton(QMessageBox::Ok); msgBoxDHCP.exec(); } temp.clear(); } delete GlobalSettings; }
void OptionsWindow::SaveAConfig(int step, bool nomesseage = true) { QSettings *GlobalSettings = new QSettings("/root/.WiFiHostapdAP/WiFi_Hostapd_AP.conf",QSettings::NativeFormat); // создание нового объекта // Функция сохраения конфигурационных файлов по маске // №1 - что сохраняем - 0 = только HOSTAPD; 1 - DNSMASQ QString temp; QDateTime TimeNow; QString dateUNIXNow; if(step == 0) { // Сохраняем только HOSTAPD temp = getMaskToConfig(0); QFile::remove("/etc/hostapd/hostapd.conf"); QFile hostapd_config("/etc/hostapd/hostapd.conf"); hostapd_config.open(QIODevice::WriteOnly); QTextStream out(&hostapd_config); out << temp; hostapd_config.close(); dateUNIXNow = QString::number(TimeNow.currentDateTime().toTime_t()); emit toMainLog(QString("%1|%2|%3|%4").arg(tr("Options"), dateUNIXNow, tr("Hostapd config succesfully update."), QString("1"))); // Hostapd if(!nomesseage) { QMessageBox msgBoxHostapd; msgBoxHostapd.setText(tr("Конфигурационный файл обновлён")); msgBoxHostapd.setIcon(QMessageBox::Information); msgBoxHostapd.setInformativeText(tr("Настройки Hostapd успешно сохранены. Для вступления их в силу, пожалуйста, перезапустите точку доступа.")); msgBoxHostapd.setStandardButtons(QMessageBox::Ok); msgBoxHostapd.setDefaultButton(QMessageBox::Ok); msgBoxHostapd.exec(); } temp.clear(); } else { // Сохраняемфайл DNSMASQ // 1 temp = getMaskToConfig(1); QFile::remove("/etc/dnsmasq.conf"); QFile firstDHCPConfig("/etc/dnsmasq.conf"); firstDHCPConfig.open(QIODevice::WriteOnly); QTextStream out1(&firstDHCPConfig); out1 << temp; firstDHCPConfig.close(); temp.clear(); dateUNIXNow = QString::number(TimeNow.currentDateTime().toTime_t()); emit toMainLog(QString("%1|%2|%3|%4").arg(tr("Options"), dateUNIXNow, tr("DNSMASQ config succesfully update."), QString("1"))); // DHCP if(!nomesseage) { QMessageBox msgBoxDHCP; msgBoxDHCP.setText(tr("Конфигурационный файл обновлён")); msgBoxDHCP.setIcon(QMessageBox::Information); msgBoxDHCP.setInformativeText(tr("Настройки DHCP успешно сохранены. Для вступления их в силу, пожалуйста, перезапустите точку доступа.")); msgBoxDHCP.setStandardButtons(QMessageBox::Ok); msgBoxDHCP.setDefaultButton(QMessageBox::Ok); msgBoxDHCP.exec(); } temp.clear(); } delete GlobalSettings; }
int ex3(struct parser* p) { int label_1 = label_count++; whitespace(p); if (lstring(p, ".ID")) { out1("ID"); return 1; } else if (lstring(p, ".NUMBER")) { out1("NUM"); return 1; } else if (lstring(p, ".STRING")) { out1("SR"); return 1; } else if (lstring(p, ".EMPTY")) { out1("SET"); return 1; } else if (lstring(p, "(")) { ex1(p); lstring(p, ")"); return 1; } else if (*(p->buf->begin) == '$') { p->buf->begin++; generate_label(label_1); ex3(p); out3("BT", label_1); out1("SET"); return 1; } else if (identifier(p)) { out2("CLL", p->id); return 1; } else if (string(p)) { out2("TST", p->id); return 1; } return 0; }
// 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); }
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); }
int output(struct parser* p) { if (lstring(p, ".OUT")) { lstring(p, "("); while (output1(p)) {} lstring(p, ")"); out1("OUT"); } else if (lstring(p, ".LABEL")) { out1("LB"); output1(p); out1("OUT"); } else { //out1("OUT"); return 0; } return 1; }
int output1(struct parser* p) { whitespace(p); if (lstring(p, "*1")) { out1("GN1"); return 1; } else if (lstring(p, "*2")) { out1("GN2"); return 1; } else if (lstring(p, "*")) { out1("CI"); return 1; } else if (string(p)) { out2("CL", p->id); return 1; } return 0; }
int main () { BTree<int> t; t.insert (10,""); t.insert (20,"L"); t.insert (8,"R"); t.insert (17,"LL"); t.insert (19,"RL"); assert (t.sum () == 74); assert (t.countLeaves () == 2); BTree<int> t2 (t); assert (t == t2); assert (t.member(10)); assert (!t.member(99)); t.insert (99,"LR"); assert (t.member(99)); assert (!(t == t2)); std::ofstream out1 ("tree1.hsl"); t.printToHs (out1); out1.close (); std::ifstream in1 ("tree1.hsl"); t2.readFromHs (in1); assert (t == t2); assert (!t.isBOT()); BTree<int> bot; bot.insertBOT (10); bot.insertBOT (232); bot.insertBOT (577); bot.insertBOT (232); bot.insertBOT (878); bot.insertBOT (23); bot.insertBOT (68); bot.insertBOT (1); std::ofstream botf ("botf.dot"); bot.printToDotty (botf); assert (bot.isBOT()); return 0; }
void ThreadParse::run() { QTextStream out1(&str); A2lLexer *lexer1 = new A2lLexer(); lexer1->initialize(); QStringList *errorList1 = new QStringList(); A2lGrammar *gram = new A2lGrammar(); nodeA2l1 = new A2LFILE(out1, 0, lexer1, errorList1, gram); nodeA2l1->name = (char*)"fileName"; delete lexer1; }
int program(struct parser* p) { lstring(p, ".SYNTAX"); identifier(p); out2("ADR", p->id); while (st(p)) {} if (lstring(p, ".END")) { out1("END"); return 1; } return 1; }
int main() { using vector_type = hpx::partitioned_vector<double>; const std::size_t height = 16; const std::size_t width = 16; std::size_t local_height = 16; std::size_t local_width = 16; std::size_t local_leading_dimension = local_height; std::size_t raw_size = (height * width) * (local_height * local_width); auto layout = hpx::container_layout(height * width, hpx::find_all_localities()); // Vector instantiations for test 1 vector_type in1(raw_size, layout); vector_type out1(raw_size, layout); std::string in1_name("in1"); std::string out1_name("out1"); in1.register_as(hpx::launch::sync, in1_name); out1.register_as(hpx::launch::sync, out1_name); // Vector instantiations for test 2 vector_type in2(raw_size, layout); vector_type out2(raw_size, layout); std::string in2_name("in2"); std::string out2_name("out2"); in2.register_as(hpx::launch::sync, in2_name); out2.register_as(hpx::launch::sync, out2_name); // Launch tests hpx::future<void> join1 = hpx::lcos::define_spmd_block("block1", 4, bulk_test_action(), height, width, local_height, local_width, local_leading_dimension, in1_name, out1_name); hpx::future<void> join2 = hpx::lcos::define_spmd_block("block2", 4, async_bulk_test_action(), height, width, local_height, local_width, local_leading_dimension, in2_name, out2_name); hpx::wait_all(join1, join2); return 0; }
int st(struct parser* p) { if (!identifier(p)) { return 0; } label(p->id); character(p, '='); ex1(p); lstring(p, ".,"); out1("R"); return 1; }
int main(int, char **) try { DB::ReadBufferFromFileDescriptor in1(STDIN_FILENO); DB::WriteBufferFromFileDescriptor out1(STDOUT_FILENO); DB::AsynchronousWriteBuffer out2(out1); DB::CompressedWriteBuffer out3(out2); DB::copyData(in1, out3); return 0; } catch (const DB::Exception & e) { std::cerr << e.what() << ", " << e.displayText() << std::endl; return 1; }
DEF_TEST(UnflattenWithCustomFactory, r) { // Create and flatten the test flattenable SkBinaryWriteBuffer writeBuffer; sk_sp<SkFlattenable> flattenable1(new IntFlattenable(1, 2, 3, 4)); writeBuffer.writeFlattenable(flattenable1.get()); sk_sp<SkFlattenable> flattenable2(new IntFlattenable(2, 3, 4, 5)); writeBuffer.writeFlattenable(flattenable2.get()); sk_sp<SkFlattenable> flattenable3(new IntFlattenable(3, 4, 5, 6)); writeBuffer.writeFlattenable(flattenable3.get()); // Copy the contents of the write buffer into a read buffer sk_sp<SkData> data = SkData::MakeUninitialized(writeBuffer.bytesWritten()); writeBuffer.writeToMemory(data->writable_data()); SkReadBuffer readBuffer(data->data(), data->size()); // Register a custom factory with the read buffer readBuffer.setCustomFactory(SkString("IntFlattenable"), &custom_create_proc); // Unflatten and verify the flattenables sk_sp<IntFlattenable> out1((IntFlattenable*) readBuffer.readFlattenable( SkFlattenable::kSkUnused_Type)); REPORTER_ASSERT(r, out1); REPORTER_ASSERT(r, 2 == out1->a()); REPORTER_ASSERT(r, 3 == out1->b()); REPORTER_ASSERT(r, 4 == out1->c()); REPORTER_ASSERT(r, 5 == out1->d()); sk_sp<IntFlattenable> out2((IntFlattenable*) readBuffer.readFlattenable( SkFlattenable::kSkUnused_Type)); REPORTER_ASSERT(r, out2); REPORTER_ASSERT(r, 3 == out2->a()); REPORTER_ASSERT(r, 4 == out2->b()); REPORTER_ASSERT(r, 5 == out2->c()); REPORTER_ASSERT(r, 6 == out2->d()); sk_sp<IntFlattenable> out3((IntFlattenable*) readBuffer.readFlattenable( SkFlattenable::kSkUnused_Type)); REPORTER_ASSERT(r, out3); REPORTER_ASSERT(r, 4 == out3->a()); REPORTER_ASSERT(r, 5 == out3->b()); REPORTER_ASSERT(r, 6 == out3->c()); REPORTER_ASSERT(r, 7 == out3->d()); }
void diff_it( std::list<linet> &lines1, std::list<linet> &lines2) { std::string tmp1_name=get_temporary_file("delta_diff1", "txt"); std::string tmp2_name=get_temporary_file("delta_diff2", "txt"); std::string tmp3_name=get_temporary_file("delta_diff3", "txt"); { std::ofstream out1(tmp1_name.c_str()); std::ofstream out2(tmp2_name.c_str()); for(std::list<linet>::const_iterator l_it=lines1.begin(); l_it!=lines1.end(); l_it++) out1 << l_it->line << "\n"; for(std::list<linet>::const_iterator l_it=lines2.begin(); l_it!=lines2.end(); l_it++) out2 << l_it->line << "\n"; } std::string cmdline="diff \""+tmp1_name+"\""+ " \""+tmp2_name+"\""+ "> \""+tmp3_name+"\""; int result=system(cmdline.c_str()); // open output if(result>=0) { std::ifstream in(tmp3_name.c_str()); std::string line; std::list<std::string> diff; while(std::getline(in, line)) diff.push_back(line); process_diff(lines1, lines2, diff); } // clean up unlink(tmp1_name.c_str()); unlink(tmp2_name.c_str()); unlink(tmp3_name.c_str()); }
void out(FILE* fbin2,double average, int d, unsigned long n_tuples,int n, option_t *opt) { double *tscore; double* *keyvalue;//score index->index tscore = (double*)malloc(n_tuples * sizeof(double)); keyvalue = (double**)malloc(n_tuples * sizeof(double*)); int **readin; readin = (int**)malloc(n_tuples * sizeof(int*)); for (int i = 0; i < n_tuples; i++) readin[i] = (int*)malloc((d + 5) * sizeof(int)); for (int i = 0; i < n_tuples; i++) { char *buf; buf = (char*)malloc((d + 5) * sizeof(char)); fgets(buf, d + 5, fbin2); analyse(buf, sizeof(buf), readin[i]); fscanf(fbin2, "%f", &tscore[i]); keyvalue[i] = &tscore[i]; free(buf); } qsort((void*)keyvalue, n_tuples, sizeof(double*), cmp_1); //------------------------------------------------------------------------ FILE* fout1 = fopen("out1.txt", "w"); FILE* fout2 = fopen("out2.txt", "w"); if (n == 0) { fclose(fout1); fclose(fout2); } //1--------------------------------------------------------------------- out1(fout1, n,keyvalue,tscore,d,readin); fclose(fout1); //2-------------------------------------------------------------------------- out2(fout2, n, keyvalue, tscore, d, readin,n_tuples); fclose(fout2); //3-------------------------------------------------------------------------- FILE* fout3 = fopen("out3.txt", "w"); out3(fout2, n, keyvalue, tscore, d, readin, n_tuples,opt); fclose(fout3); //4------------------------------------------------------------------------------ FILE* fout4 = fopen("out4.txt", "w"); out4(fout2, n, keyvalue, tscore, d, readin, n_tuples, opt); fclose(fout4); // free(tscore); free(readin); free(keyvalue); }
bool isUpdated( const InputFile &in, const std::string &outHeaderName, const std::string &outImplName) { bool toret = false; InputFile out1( outHeaderName ); InputFile out2( outImplName ); if ( in.isOpen() && out1.isOpen() && out2.isOpen() ) { toret = ( out1.getTimeStamp() >= in.getTimeStamp() && out2.getTimeStamp() >= in.getTimeStamp() ) ; } return toret; }
int TetrahedronSetTopologyContainer::getTetrahedronIndex(PointID v1, PointID v2, PointID v3, PointID v4) { if(!hasTetrahedraAroundVertex()) createTetrahedraAroundVertexArray(); sofa::helper::vector<unsigned int> set1 = getTetrahedraAroundVertex(v1); sofa::helper::vector<unsigned int> set2 = getTetrahedraAroundVertex(v2); sofa::helper::vector<unsigned int> set3 = getTetrahedraAroundVertex(v3); sofa::helper::vector<unsigned int> set4 = getTetrahedraAroundVertex(v4); sort(set1.begin(), set1.end()); sort(set2.begin(), set2.end()); sort(set3.begin(), set3.end()); sort(set4.begin(), set4.end()); // The destination vector must be large enough to contain the result. sofa::helper::vector<unsigned int> out1(set1.size()+set2.size()); sofa::helper::vector<unsigned int>::iterator result1; result1 = std::set_intersection(set1.begin(),set1.end(),set2.begin(),set2.end(),out1.begin()); out1.erase(result1,out1.end()); sofa::helper::vector<unsigned int> out2(set3.size()+out1.size()); sofa::helper::vector<unsigned int>::iterator result2; result2 = std::set_intersection(set3.begin(),set3.end(),out1.begin(),out1.end(),out2.begin()); out2.erase(result2,out2.end()); sofa::helper::vector<unsigned int> out3(set4.size()+out2.size()); sofa::helper::vector<unsigned int>::iterator result3; result3 = std::set_intersection(set4.begin(),set4.end(),out2.begin(),out2.end(),out3.begin()); out3.erase(result3,out3.end()); assert(out3.size()==0 || out3.size()==1); if (out3.size()==1) return (int) (out3[0]); else return -1; }
server::worker::worker(environment const & env, io_state const & ios, definition_cache & cache, optional<std::string> const & base_dir): m_empty_snapshot(env, ios.get_options()), m_cache(cache), m_base_dir(base_dir), m_todo_line_num(0), m_todo_options(ios.get_options()), m_terminate(false), m_thread([=]() { io_state _ios(ios); while (!m_terminate) { file_ptr todo_file; unsigned todo_line_num = 0; options todo_options; // wait for next task while (!m_terminate) { unique_lock<mutex> lk(m_todo_mutex); if (m_todo_file) { todo_file = m_todo_file; todo_line_num = m_todo_line_num; todo_options = m_todo_options; break; } else { m_todo_cv.wait(lk); } } // extract block of code and snapshot from todo_file reset_interrupt(); bool worker_interrupted = false; if (m_terminate) break; DIAG(std::cerr << "processing '" << todo_file->get_fname() << "'\n";) std::string block; unsigned num_lines; snapshot s; { lean_assert(todo_file); lock_guard<mutex> lk(todo_file->m_lines_mutex); unsigned i = todo_file->find(todo_line_num); todo_file->m_snapshots.resize(i); s = i == 0 ? m_empty_snapshot : todo_file->m_snapshots[i-1]; if (direct_imports_have_changed(s.m_env)) s = m_empty_snapshot; lean_assert(s.m_line > 0); todo_file->m_info.start_from(s.m_line); todo_file->m_info.save_environment_options(s.m_line, 0, s.m_env, s.m_options); num_lines = todo_file->copy_to(block, s.m_line - 1); } if (m_terminate) break; // parse block of code with respect to snapshot try { std::istringstream strm(block); #if defined(LEAN_SERVER_DIAGNOSTIC) std::shared_ptr<output_channel> out1(new stderr_channel()); std::shared_ptr<output_channel> out2(new stderr_channel()); #else std::shared_ptr<output_channel> out1(new string_output_channel()); std::shared_ptr<output_channel> out2(new string_output_channel()); #endif io_state tmp_ios(_ios, out1, out2); tmp_ios.set_options(join(s.m_options, _ios.get_options())); bool use_exceptions = false; unsigned num_threads = 1; parser p(s.m_env, tmp_ios, strm, todo_file->m_fname.c_str(), m_base_dir, use_exceptions, num_threads, &s, &todo_file->m_snapshots, &todo_file->m_info); p.set_cache(&m_cache); p(); } catch (interrupted &) { worker_interrupted = true; } catch (throwable & ex) { DIAG(std::cerr << "worker exception: " << ex.what() << "\n";) } if (!m_terminate && !worker_interrupted) { DIAG(std::cerr << "finished '" << todo_file->get_fname() << "'\n";) unique_lock<mutex> lk(m_todo_mutex); if (m_todo_file == todo_file && m_last_file == todo_file && m_todo_line_num == todo_line_num) { m_todo_line_num = num_lines + 1; m_todo_file = nullptr; m_todo_cv.notify_all(); } }
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"; }
Sivia::Sivia(repere& R, struct sivia_struct *par) : R(R) { par->area = 0; // Create the function we want to apply SIVIA on. Variable x,y; double ei = par->ei; double xb=par->xb1,yb=par->yb1; Interval xbi=Interval(par->xb1-ei,par->xb1+ei),ybi=Interval(par->yb1-ei,par->yb1+ei); double arc = par->sonar_arc; double r = pow(par->sonar_radius,2); double th1 = par->th[0]; double th2=th1+arc; double th21= par->th[1]; double th22=th21 + arc; double th31= par->th[2]; double th32=th31 + arc; double e=1; double epsilon = par->epsilon; double xin,yin; // First SONAR Function f(x,y,sqr(x-xbi)+sqr(y-ybi)); NumConstraint c1(x,y,f(x,y)<=r+e); NumConstraint c2(x,y,f(x,y)>=e); NumConstraint c3(x,y,f(x,y)>r+e); NumConstraint c4(x,y,f(x,y)<e); double sign1,sign2; if(cos(th1)>0) sign1=1; else sign1=-1; if(cos(th2)<0) sign2=1; else sign2=-1; NumConstraint cth11(x,y,sign1*(y-ybi-((sin(th1))/(cos(th1)))*(x-xbi))<0); NumConstraint cth12(x,y,sign1*(y-ybi-((sin(th1))/(cos(th1)))*(x-xbi))>0); NumConstraint cth21(x,y,sign2*(y-ybi-((sin(th2))/(cos(th2)))*(x-xbi))<0); NumConstraint cth22(x,y,sign2*(y-ybi-((sin(th2))/(cos(th2)))*(x-xbi))>0); // Create contractors with respect to each // of the previous constraints. CtcFwdBwd out1(c1); CtcFwdBwd out2(c2); CtcFwdBwd in1(c3); CtcFwdBwd in2(c4); CtcFwdBwd outth1(cth12); CtcFwdBwd inth1(cth11); CtcFwdBwd inth2(cth21); CtcFwdBwd outth2(cth22); // CtcIn inside(f,Interval(-1,1)); // CtcNotIn outside(f,Interval(-1,1)); // Create a contractor that removes all the points // that do not satisfy either f(x,y)<=2 or f(x,y)>=0. // These points are "outside" of the solution set. CtcCompo outside1(out1,out2,outth1,outth2); // Create a contractor that removes all the points // that do not satisfy both f(x,y)>2 or f(x,y)<0. // These points are "inside" the solution set. CtcUnion inside11(in1,in2,inth1); CtcUnion inside1(inside11,inth2); // Second SONAR double xb2=par->xb2,yb2=par->yb2; Interval xb2i=Interval(par->xb2-ei,par->xb2+ei),yb2i=Interval(par->yb2-ei,par->yb2+ei); Function f2(x,y,sqr(x-xb2i)+sqr(y-yb2i)); NumConstraint c21(x,y,f2(x,y)<=r+e); NumConstraint c22(x,y,f2(x,y)>=e); NumConstraint c23(x,y,f2(x,y)>r+e); NumConstraint c24(x,y,f2(x,y)<e); double sign21,sign22; if(cos(th21)>0) sign21=-1; else sign21=1; if(cos(th22)<0) sign22=1; else sign22=-1; NumConstraint cth211(x,y,sign21*(y-yb2i-((sin(th21))/(cos(th21)))*(x-xb2i))<0); NumConstraint cth212(x,y,sign21*(y-yb2i-((sin(th21))/(cos(th21)))*(x-xb2i))>0); NumConstraint cth221(x,y,sign22*(y-yb2i-((sin(th22))/(cos(th22)))*(x-xb2i))<0); NumConstraint cth222(x,y,sign22*(y-yb2i-((sin(th22))/(cos(th22)))*(x-xb2i))>0); // Create contractors with respect to each // of the previous constraints. CtcFwdBwd out21(c21); CtcFwdBwd out22(c22); CtcFwdBwd in21(c23); CtcFwdBwd in22(c24); CtcFwdBwd outth21(cth211); CtcFwdBwd inth21(cth212); CtcFwdBwd inth22(cth221); CtcFwdBwd outth22(cth222); // CtcIn inside(f,Interval(-1,1)); // CtcNotIn outside(f,Interval(-1,1)); // Create a contractor that removes all the points // that do not satisfy either f(x,y)<=2 or f(x,y)>=0. // These points are "outside" of the solution set. CtcCompo outside2(out21,out22,outth21,outth22); // Create a contractor that removes all the points // that do not satisfy both f(x,y)>2 or f(x,y)<0. // These points are "inside" the solution set. CtcUnion inside21(in21,in22,inth21); CtcUnion inside2(inside21,inth22); //Third SONAR double xb3=par->xb3,yb3=par->yb3; Interval xb3i=Interval(par->xb3-ei,par->xb3+ei),yb3i=Interval(par->yb3-ei,par->yb3+ei); Function f3(x,y,sqr(x-xb3i)+sqr(y-yb3i)); NumConstraint c31(x,y,f3(x,y)<=r+e); NumConstraint c32(x,y,f3(x,y)>=e); NumConstraint c33(x,y,f3(x,y)>r+e); NumConstraint c34(x,y,f3(x,y)<e); double sign31,sign32; if(cos(th31)>0) sign31=-1; else sign31=1; if(cos(th32)<0) sign32=1; else sign32=-1; NumConstraint cth311(x,y,sign31*(y-yb3i-((sin(th31))/(cos(th31)))*(x-xb3i))<0); NumConstraint cth312(x,y,sign31*(y-yb3i-((sin(th31))/(cos(th31)))*(x-xb3i))>0); NumConstraint cth321(x,y,sign32*(y-yb3i-((sin(th32))/(cos(th32)))*(x-xb3i))<0); NumConstraint cth322(x,y,sign32*(y-yb3i-((sin(th32))/(cos(th32)))*(x-xb3i))>0); // Create contractors with respect to each // of the previous constraints. CtcFwdBwd out31(c31); CtcFwdBwd out32(c32); CtcFwdBwd in31(c33); CtcFwdBwd in32(c34); CtcFwdBwd outth31(cth311); CtcFwdBwd inth31(cth312); CtcFwdBwd inth32(cth321); CtcFwdBwd outth32(cth322); // CtcIn inside(f,Interval(-1,1)); // CtcNotIn outside(f,Interval(-1,1)); // Create a contractor that removes all the points // that do not satisfy either f(x,y)<=2 or f(x,y)>=0. // These points are "outside" of the solution set. CtcCompo outside3(out31,out32,outth31,outth32); // Create a contractor that removes all the points // that do not satisfy both f(x,y)>2 or f(x,y)<0. // These points are "inside" the solution set. CtcUnion inside31(in31,in32,inth31); CtcUnion inside3(inside31,inth32); //CtcQInter inter(inside,1); //Artifact MODELISATION double xa = par->xa; double ya = par->ya; double ra = par->ra; Function f_a(x,y,sqr(x-xa)+sqr(y-ya)); NumConstraint ca1(x,y,f_a(x,y)<=sqr(ra)); NumConstraint ca2(x,y,f_a(x,y)>=sqr(ra)-par->thick); NumConstraint ca3(x,y,f_a(x,y)>sqr(ra)); NumConstraint ca4(x,y,f_a(x,y)<sqr(ra)-par->thick); CtcFwdBwd aout1(ca1); CtcFwdBwd aout2(ca2); CtcFwdBwd ain1(ca3); CtcFwdBwd ain2(ca4); CtcUnion ain(ain1,ain2); CtcCompo aout(aout1,aout2); //Robot MODELISATION double xr = par->xr; //robot position x double yr = par->yr; //robot position y double wr = par->wr; //robot width double lr = par->lr; //robot length double ep = par->thick; xr = par->xr - wr/2; NumConstraint inrx1(x,y,x>xr+ep); NumConstraint outrx1(x,y,x<xr+ep); NumConstraint inrx2(x,y,x<xr-ep); NumConstraint outrx2(x,y,x>xr-ep); NumConstraint inry1(x,y,y<yr-lr/2); NumConstraint outry1(x,y,y>yr-lr/2); NumConstraint inry2(x,y,y>yr+lr/2); NumConstraint outry2(x,y,y<yr+lr/2); CtcFwdBwd incrx1(inrx1); CtcFwdBwd incrx2(inrx2); CtcFwdBwd incry1(inry1); CtcFwdBwd incry2(inry2); CtcFwdBwd outcrx1(outrx1); CtcFwdBwd outcrx2(outrx2); CtcFwdBwd outcry1(outry1); CtcFwdBwd outcry2(outry2); CtcUnion inrtemp(incrx1,incrx2,incry1); CtcUnion inr1(inrtemp,incry2); CtcCompo outrtemp(outcrx1,outcrx2,outcry1); CtcCompo outr1(outrtemp,outcry2); //2nd rectangle xr = par->xr + wr/2; NumConstraint inrx21(x,y,x>xr+ep); NumConstraint outrx21(x,y,x<xr+ep); NumConstraint inrx22(x,y,x<xr-ep); NumConstraint outrx22(x,y,x>xr-ep); NumConstraint inry21(x,y,y<yr-lr/2); NumConstraint outry21(x,y,y>yr-lr/2); NumConstraint inry22(x,y,y>yr+lr/2); NumConstraint outry22(x,y,y<yr+lr/2); CtcFwdBwd incrx21(inrx21); CtcFwdBwd incrx22(inrx22); CtcFwdBwd incry21(inry21); CtcFwdBwd incry22(inry22); CtcFwdBwd outcrx21(outrx21); CtcFwdBwd outcrx22(outrx22); CtcFwdBwd outcry21(outry21); CtcFwdBwd outcry22(outry22); CtcUnion inrtemp2(incrx21,incrx22,incry21); CtcUnion inr2(inrtemp2,incry22); CtcCompo outrtemp2(outcrx21,outcrx22,outcry21); CtcCompo outr2(outrtemp2,outcry22); //3nd rectangle top rectangle yr=par->yr+par->lr/2; xr=par->xr; NumConstraint inrx31(x,y,x>xr+wr/2+ep); NumConstraint outrx31(x,y,x<xr+wr/2+ep); NumConstraint inrx32(x,y,x<xr-wr/2-ep); NumConstraint outrx32(x,y,x>xr-wr/2-ep); NumConstraint inry31(x,y,y<yr-ep); NumConstraint outry31(x,y,y>yr-ep); NumConstraint inry32(x,y,y>yr+ep); NumConstraint outry32(x,y,y<yr+ep); CtcFwdBwd incrx31(inrx31); CtcFwdBwd incrx32(inrx32); CtcFwdBwd incry31(inry31); CtcFwdBwd incry32(inry32); CtcFwdBwd outcrx31(outrx31); CtcFwdBwd outcrx32(outrx32); CtcFwdBwd outcry31(outry31); CtcFwdBwd outcry32(outry32); CtcUnion inrtemp3(incrx31,incrx32,incry31); CtcUnion inr3(inrtemp3,incry32); CtcCompo outrtemp3(outcrx31,outcrx32,outcry31); CtcCompo outr3(outrtemp3,outcry32); //4 rectangle bot yr=par->yr-par->lr/2; xr=par->xr; NumConstraint inrx41(x,y,x>xr+wr/2+ep); NumConstraint outrx41(x,y,x<xr+wr/2+ep); NumConstraint inrx42(x,y,x<xr-wr/2-ep); NumConstraint outrx42(x,y,x>xr-wr/2-ep); NumConstraint inry41(x,y,y<yr-ep); NumConstraint outry41(x,y,y>yr-ep); NumConstraint inry42(x,y,y>yr+ep); NumConstraint outry42(x,y,y<yr+ep); CtcFwdBwd incrx41(inrx41); CtcFwdBwd incrx42(inrx42); CtcFwdBwd incry41(inry41); CtcFwdBwd incry42(inry42); CtcFwdBwd outcrx41(outrx41); CtcFwdBwd outcrx42(outrx42); CtcFwdBwd outcry41(outry41); CtcFwdBwd outcry42(outry42); CtcUnion inrtemp4(incrx41,incrx42,incry41); CtcUnion inr4(inrtemp4,incry42); CtcCompo outrtemp4(outcrx41,outcrx42,outcry41); CtcCompo outr4(outrtemp4,outcry42); CtcCompo inrtp(inr1,inr2,inr3); CtcUnion outrtp(outr1,outr2,outr3); CtcCompo inr(inrtp,inr4); CtcUnion outr(outrtp,outr4); yr = par->yr; int maxq = 3; //nb of contractors int Qinter = 2; int ctcq = maxq - Qinter + 1; //nb for q-relaxed function of Ibex Array<Ctc> inside1r1(inside1,inr,ain); Array<Ctc> outside1r1(outside1,outr,aout); Array<Ctc> inside2r1(inside2,inr,ain); Array<Ctc> outside2r1(outside2,outr,aout); Array<Ctc> inside3r1(inside3,inr,ain); Array<Ctc> outside3r1(outside3,outr,aout); CtcQInter outside1r(outside1r1,Qinter); CtcQInter inside1r(inside1r1,ctcq); CtcQInter outside2r(outside2r1,Qinter); CtcQInter inside2r(inside2r1,ctcq); CtcQInter outside3r(outside3r1,Qinter); CtcQInter inside3r(inside3r1,ctcq); // Build the initial box. IntervalVector box(2); box[0]=Interval(-10,10); box[1]=Interval(-10,10); par->vin.clear(); // Build the way boxes will be bisected. // "LargestFirst" means that the dimension bisected // is always the largest one. int nbox1=0; LargestFirst lf; IntervalVector viinside1(2); stack<IntervalVector> s; s.push(box); while (!s.empty()) { IntervalVector box=s.top(); s.pop(); contract_and_draw(inside1r,box,viinside1,1,par,nbox1,Qt::magenta,Qt::red); if (box.is_empty()) { continue; } contract_and_draw(outside1r,box,viinside1,0,par,nbox1,Qt::darkBlue,Qt::cyan); if (box.is_empty()) { continue; } if (box.max_diam()<epsilon) { R.DrawBox(box[0].lb(),box[0].ub(),box[1].lb(),box[1].ub(),QPen(Qt::yellow),QBrush(Qt::NoBrush)); } else { pair<IntervalVector,IntervalVector> boxes=lf.bisect(box); s.push(boxes.first); s.push(boxes.second); } } if(par->isinside==1){ robot_position_estimator(nbox1,par); par->isinside1=1; par->isinside=0; //cout<<"area1: "<<par->area<<endl; } IntervalVector box2(2); box2[0]=Interval(-10,10); box2[1]=Interval(-10,10); // Build the way boxes will be bisected. // "LargestFirst" means that the dimension bisected // is always the largest one. int nbox2=0; LargestFirst lf2; IntervalVector viinside2(2); stack<IntervalVector> s2; s2.push(box2); while (!s2.empty()) { IntervalVector box2=s2.top(); s2.pop(); contract_and_draw(inside2r,box2,viinside2,2,par,nbox2,Qt::magenta,Qt::red); if (box2.is_empty()) { continue; } contract_and_draw(outside2r,box2,viinside2,0,par,nbox2,Qt::darkBlue,Qt::cyan); if (box2.is_empty()) { continue; } if (box2.max_diam()<epsilon) { R.DrawBox(box2[0].lb(),box2[0].ub(),box2[1].lb(),box2[1].ub(),QPen(Qt::yellow),QBrush(Qt::NoBrush)); } else { pair<IntervalVector,IntervalVector> boxes2=lf2.bisect(box2); s2.push(boxes2.first); s2.push(boxes2.second); } } if(par->isinside==1){ robot_position_estimator(nbox2,par); par->isinside2=1; par->isinside=0; //cout<<"area2: "<<par->area<<endl; } IntervalVector box3(2); box3[0]=Interval(-10,10); box3[1]=Interval(-10,10); // Build the way boxes will be bisected. // "LargestFirst" means that the dimension bisected // is always the largest one. int nbox3=0; LargestFirst lf3; IntervalVector viinside3(2); stack<IntervalVector> s3; s3.push(box3); while (!s3.empty()) { IntervalVector box3=s3.top(); s3.pop(); contract_and_draw(inside3r,box3,viinside3,3,par,nbox3,Qt::magenta,Qt::red); if (box3.is_empty()) { continue; } contract_and_draw(outside3r,box3,viinside3,0,par,nbox3,Qt::darkBlue,Qt::cyan); if (box3.is_empty()) { continue; } if (box3.max_diam()<epsilon) { R.DrawBox(box3[0].lb(),box3[0].ub(),box3[1].lb(),box3[1].ub(),QPen(Qt::yellow),QBrush(Qt::NoBrush)); } else { pair<IntervalVector,IntervalVector> boxes3=lf3.bisect(box3); s3.push(boxes3.first); s3.push(boxes3.second); } } if(par->isinside==1){ robot_position_estimator(nbox3,par); par->isinside3=1; par->isinside=0; //cout<<"area3: "<<par->area<<endl; } par->state.clear(); if (par->isinside1 ==1 || par->isinside2 ==1 || par->isinside3 ==1){ double *aimth = new double[3]; aimth[0] = get_angle(xb,yb,par->xin,par->yin)+M_PI ; aimth[1] = get_angle(xb2,yb2,par->xin,par->yin)+M_PI; aimth[2] = get_angle(xb3,yb3,par->xin,par->yin)+M_PI; R.DrawLine(xb,yb,xb+r*cos(aimth[0]),yb+r*sin(aimth[0]),QPen(Qt::red)); R.DrawLine(xb2,yb2,xb2+r*cos(aimth[1]),yb2+r*sin(aimth[1]),QPen(Qt::red)); R.DrawLine(xb3,yb3,xb3+r*cos(aimth[2]),yb3+r*sin(aimth[2]),QPen(Qt::red)); par->state = std::string("found"); double kp = par->kp; double u[3]; for (int i=0;i<3;i++){ u[i] = -kp*atan(tan((par->th[i] - (aimth[i] - arc/2.0 ))/2)); if(u[i]>par->sonar_speed) par->th[i] += par->sonar_speed; if(u[i]<-par->sonar_speed) par->th[i] += -par->sonar_speed; else par->th[i] += u[i]; } // for (int i=0;i<3;i++){ // u[i] = atan(tan((par->th[i] - (aimth[i] - arc/2.0 ))/2)); // par->th[i] -=u[i]; // } } r = sqrt(r); //cout<<"th1"<<th1<<endl; R.DrawEllipse(xb,yb,par->ei,QPen(Qt::black),QBrush(Qt::NoBrush)); R.DrawEllipse(xb2,yb2,par->ei,QPen(Qt::black),QBrush(Qt::NoBrush)); R.DrawEllipse(xb3,yb3,par->ei,QPen(Qt::black),QBrush(Qt::NoBrush)); R.DrawLine(xb,yb,xb+r*cos(th2),yb+r*sin(th2),QPen(Qt::green)); R.DrawLine(xb2,yb2,xb2+r*cos(th22),yb2+r*sin(th22),QPen(Qt::green)); R.DrawLine(xb3,yb3,xb3+r*cos(th32),yb3+r*sin(th32),QPen(Qt::green)); R.DrawLine(xb,yb,xb+r*cos(th1),yb+r*sin(th1),QPen(Qt::green)); R.DrawLine(xb2,yb2,xb2+r*cos(th21),yb2+r*sin(th21),QPen(Qt::green)); R.DrawLine(xb3,yb3,xb3+r*cos(th31),yb3+r*sin(th31),QPen(Qt::green)); R.DrawEllipse(par->xa,par->ya,par->ra,QPen(Qt::black),QBrush(Qt::NoBrush)); R.DrawRobot(xr-wr/2,yr+lr/2,-3.14/2,wr,lr); R.Save("paving"); par->vin.clear(); }
int main() { cout << setiosflags(ios::uppercase); ofstream out1("Daten_Gauss.out"); out1 << setiosflags(ios::uppercase); ofstream out("LIP.out"); out << setiosflags(ios::uppercase); ofstream outs("Y2D.out"); outs << setiosflags(ios::uppercase); ofstream rout("REGLIP_Gauss.out"); rout << setiosflags(ios::uppercase); cout << "*** Imaginaerteilgleichung ***" << endl; cout << "*** Filter: Gauss ***" << endl; mp_init(); cout << "*** Precision = " << mpipl << " ***" << endl; int M, N, MD; double xa, xb, x1, x2, xr1, xr2, h, step, step2, b1, dfactor, dpi; mp_real b, mpx1, mpx2, mpstep, mpx; dpi = 4.0 * atan(1.0); mp_real pi = mppic; // pi aus der Bibliothek !!! mp_real pi2 = pi * pi; static mp_real factor; cin >> b1; cin >> xa >> xb >> MD; cin >> x1 >> x2 >> M; cin >> xr1 >> xr2 >> N ; cout << '\v'; /* KERNELARRY ANFANG */ mp_real* const mpregKern = new mp_real [M+1]; b = mp_real(b1); mpx1 = mp_real(x1); mpx2 = mp_real(x2); mpstep = (mpx2 - mpx1)/mp_real(M); /* Vorfaktor */ factor = mp_real(2.0)*b/power(pi,mp_real(1.5)); factor *= exp(mp_real(0.25) * pi2 * b * b); dfactor = 2.0 * (b1/pow(dpi,1.5)) * exp(b1*b1*dpi*dpi*.25); cout << "*** Begin: Init. Kernel *** " << endl; cout << "b1 = " << b1 << endl; cout << "b = " << b ; cout << "x1 = " << x1 << endl; /* Anfangs-/Endpunkt der Regularisierung */ cout << "x2 = " << x2 << endl; cout << "M = " << M << endl; cout << "h = " << mpstep; cout << "factor = " << factor ; cout << "dfactor = " << dfactor << endl; for(int i = 0; i <= M; i++) { mpx = mpx1 + i * mpstep; mpregKern[i] = mpregkerne2(mpx, b); } cout << "*** End: Init. Kernel *** " << endl; /* KERNELARRY ENDE */ double x0, datlinpol, Error_splint, DataError, e2core; /* Index der Vektoren beginnt mit 1 und *nicht* mit 0 */ double* y2d = dvector(1,MD); /* 2.Ableitung der SPL-Funktion */ double* data = dvector(1,MD); /* Datenvektor */ double* x = dvector(1,MD); /* x-Vektor */ /* Datenarrays fuellen */ h = (xb - xa)/(MD - 1); double rho = MD/(xb -xa); cout << '\v'; cout << "*** Begin: Init. Data-Array ***" << endl; cout << "xa = " << xa << endl; /* Anfangs-/Endpunkte der Daten */ cout << "xb = " << xb << endl; cout << "MD = " << MD << endl; /* Zahl der Datenpunkte */ cout << "h = " << h << endl; cout << "rho = " << rho << endl; x[1] = xa; data[1] = e2data(xa); for(int i = 2; i <= MD ; i++) { x[i] = xa + (i-1) * h; data[i] = e2data(x[i]); } x[MD] = xb; data[MD] = e2data(xb); cout << "*** End: Init. Data-Array ***" << endl; cout << '\v' ; /* Kontrollausgabe, Datenausgabe */ for(int i = 1; i <= MD; i++) { DataError = fabs(data[i] - e2(x[i]))/fabs(e2(x[i])); DataError *= 100.0; out1 << i << '\t' << x[i] << '\t' << data[i] << '\t' << e2(x[i]) << '\t' << DataError << endl; } cout << "*** Begin: Interpol. *** " << endl; intlinear(x,data,MD,y2d); for(int i = 1; i <= MD; i++) outs << i << '\t' << y2d[i] << endl; cout << "*** End: Interpol. *** " << endl; cout << '\v'; for(int j = 0; j <= M; j++) { step = dble(mpstep); x0 = x1 + j * step; datlinpol = linint(x,data,y2d,MD,x0); e2core = e2(x0); Error_splint = fabs(datlinpol - e2core)/fabs(e2core); Error_splint *= 100.0; out << x0 << '\t' << datlinpol << '\t' << e2core << '\t' << Error_splint << endl; } /* REGULARISIERUNG */ double xi; mp_real mp_regsum, mpdata, mpError, mpreg; double regsum, Error, Reg; step2 = (xr2 - xr1)/N; cout <<"*** Begin: Regularisation ***" << endl; cout << "b1 = " << b1 << endl; cout << "b = " << b ; cout << "x1 = " << xr1 << endl; cout << "x2 = " << xr2 << endl; cout << "N = " << N << endl; cout << "h = " << step2 << endl; cout << '\v' ; for(int jj = 0; jj <= N; jj++) { mp_regsum = mp_real(0.0); x0 = xr1 + jj * step2; for(int j = 0; j <= M; j++) { xi = x1 + j * step; xi = x0 - xi; datlinpol = linint(x,data,y2d,MD,xi); mpdata = mp_real(datlinpol); mp_regsum += mpregKern[j] * mpdata; } mp_regsum *= mpstep; mp_regsum *= factor; mpreg = mpRegexakt(mp_real(x0),b); mpError = abs(mp_regsum - mpreg)/abs(mpreg); mpError *= mp_real(100.0); regsum = dble(mp_regsum); Error = dble(mpError); Reg = dble(mpreg); cout << x0 << endl; cout << mpreg << mp_regsum << mpError << endl; rout << x0 << '\t' << Reg << '\t' << regsum << '\t' << Error << '\t' << b1 << endl; } cout <<"*** End: Regularisation ***" << endl; free_dvector(y2d,1,MD); free_dvector(data,1,MD); free_dvector(x,1,MD); delete [] mpregKern; return 0; }