//------------------------------------------------------------------------------- // General dumping methods -- dumping relevant parts of ontology //------------------------------------------------------------------------------- void TBox :: dump ( dumpInterface* dump ) const { dump->prologue(); // dump all (relevant) roles dumpAllRoles(dump); // dump all (relevant) concepts for ( c_const_iterator pc = c_begin(); pc != c_end(); ++pc ) if ( isRelevant(*pc) ) dumpConcept( dump, *pc ); for ( i_const_iterator pi = i_begin(); pi != i_end(); ++pi ) if ( isRelevant(*pi) ) dumpConcept( dump, *pi ); // dump GCIs if ( getTG() != bpTOP ) { dump->startAx (diImpliesC); dump->dumpTop(); dump->contAx (diImpliesC); dumpExpression ( dump, getTG() ); dump->finishAx (diImpliesC); } dump->epilogue(); }
uint8_t BayGPRSInterface::begin(long baud,uint8_t unlock_only){ _baud=baud; i_begin(_baud); skipChars(); printP("AT"); //Will autoconfigure BAUD-Rate - Auto BAUD-Rate did not work with Sleep-Mode! delay(100); println(); printP("AT+IPR="); println(_baud); wait_forOK(200); return init(unlock_only); }
uint8_t BayGPRSInterface::changeIPR(long baud) { _baud = baud; long t_baud[] = { baud, 9600, 38400, 57600 }; for (uint8_t i = 0; i < 4; i++) { i_begin(t_baud[i]); skipChars(); printP("AT"); //Will autoconfigure BAUD-Rate - Auto BAUD-Rate did not work with Sleep-Mode! delay(100); println(); printP("AT+IPR="); println(_baud); if (!wait_forOK(200)) { i_end(); i_begin(_baud); return 0; } i_end(); } return 1; }
void TBox :: answerQuery ( const std::vector<DLTree*>& Cs ) { DLHeap.removeQuery(); std::cout << "Transforming concepts..."; // create BPs for all the concepts concepts.clear(); for ( std::vector<DLTree*>::const_iterator q = Cs.begin(), q_end = Cs.end(); q != q_end; ++q ) concepts.push_back(tree2dag(*q)); std::cout << " done" << std::endl << "Filling all individuals..."; // all individuals to go thru std::vector<TIndividual*> AllInd; for ( i_iterator i = i_begin(), i_e = i_end(); i != i_e; i++ ) AllInd.push_back(*i); std::cout << " done with " << AllInd.size() << " individuals" << std::endl; size_t size = Cs.size(); std::cout << "Creating iterables..."; IV.clear(); for ( size_t j = 0; j < size; j++ ) IV.add(new Iterable<TIndividual*>(AllInd)); std::cout << " done\n"; std::cout << "Run consistency checks..."; size_t n = 0, nAns = 0; TsProcTimer timer; timer.Start(); do { if ( n++ % 100 == 0 ) { float time = timer; std::cout << n << " tries, " << nAns << " answers, " << time << " total time, " << time/n << " avg time" << std::endl; } if ( static_cast<NominalReasoner*>(nomReasoner)->checkExtraCond() ) { for ( size_t k = 0; k < size; k++ ) std::cout << IV.get(k)->getName() << " "; std::cout << "\n"; } } while ( !IV.next() ); timer.Stop(); std::cout << "Total " << n << " tries, " << nAns << " answers, " << timer << " total time, " << timer/n << " avg time" << std::endl; }
ordinal_type Stokhos::Sparse3Tensor<ordinal_type, value_type>:: num_entries() const { #ifdef STOKHOS_DEBUG TEUCHOS_TEST_FOR_EXCEPTION(fill_completed == false, std::logic_error, "You must call fillComplete() before calling num_entries()!"); #endif ordinal_type num = 0; for (k_iterator k = k_begin(); k != k_end(); ++k) for (kj_iterator j = j_begin(k); j != j_end(k); ++j) for (kji_iterator i = i_begin(j); i != i_end(j); ++i) ++num; return num; }
void Stokhos::Sparse3Tensor<ordinal_type, value_type>:: print(std::ostream& os) const { #ifdef STOKHOS_DEBUG TEUCHOS_TEST_FOR_EXCEPTION(fill_completed == false, std::logic_error, "You must call fillComplete() before calling print()!"); #endif for (k_iterator k=k_begin(); k!=k_end(); ++k) for (kj_iterator j=j_begin(k); j!=j_end(k); ++j) for (kji_iterator i=i_begin(j); i!=i_end(j); ++i) os << "k = " << index(k) << ", j = " << index(j) << ", i = " << index(i) << ", Cijk = " << value(i) << std::endl; }
uint8_t BayGPRSInterface::init(uint8_t unlock_only){ uint8_t count=0; init_start: uint8_t i=0; printP("AT"); //Wake up delay(200); println(); wait_forOK(1000); printlnP("AT"); //Check communication if(! wait_forOK(200)){ //communication ok! printlnP("ATE0"); //Command echo off wait_forOK(500); printlnP("AT+CSCLK=2"); //Auto-Sleepmode wait_forOK(500); //Check PIN printlnP("AT+CPIN?"); while(wait_forPGM(PSTR("+CPIN: "),5000,7,_base64buffer)){ printlnP("AT"); wait_forOK(200); printlnP("AT+CFUN=0"); //Disable wait_forOK(10000); printlnP("AT+CFUN=1"); //delay(2000); //Enable wait_forOK(10000); printlnP("AT"); wait_forOK(200); printlnP("AT+CPIN?"); i++; if(i>2) return 6; } if(_base64buffer[5]=='U') return 3; //SIM PUK if(_base64buffer[5]=='I'){ //SIM PIN printlnP("AT"); wait_forOK(200); printP("AT+CPIN=\""); print(_pin); println("\""); if(wait_forOK(30000)) { return 2; //Wrong PIN } wait_for("SMS Ready",(unlock_only?5000:60000)); } //Return here - Moden will try to connect and attach in the background! if(unlock_only) return 0; // Waiting for Modem to Connect for(i=0;i<127;i++){ if(isRegistered()) break; delay(500); } if(i==127) return 4; for(i=0;i<127;i++){ if(isAttached()) break; delay(500); } if(i==127) return 5; return 0; } softReset(); softSwitch(); i_begin(_baud); skipChars(); printP("AT"); //Will autoconfigure BAUD-Rate - Auto BAUD-Rate did not work with Sleep-Mode! delay(100); println(); printP("AT+IPR="); println(_baud); wait_forOK(200); count++; if(count>1) return 1; goto init_start; }
void TBox :: buildDAG ( void ) { nNominalReferences = 0; // init concept indexing nC = 1; // start with 1 to make index 0 an indicator of "not processed" ConceptMap.push_back(NULL); // make fresh concept and datatype concept2dag(pTemp); DLTree* freshDT = DTCenter.getFreshDataType(); addDataExprToHeap ( static_cast<TDataEntry*>(freshDT->Element().getNE()) ); deleteTree(freshDT); for ( c_const_iterator pc = c_begin(); pc != c_end(); ++pc ) concept2dag(*pc); for ( i_const_iterator pi = i_begin(); pi != i_end(); ++pi ) concept2dag(*pi); // init heads of simple rules for ( TSimpleRules::iterator q = SimpleRules.begin(), q_end = SimpleRules.end(); q < q_end; ++q ) (*q)->bpHead = tree2dag((*q)->tHead); // builds Roles range and domain initRangeDomain(ORM); initRangeDomain(DRM); // build all splits for ( TSplitVars::iterator s = getSplits()->begin(), s_end = getSplits()->end(); s != s_end; ++s ) split2dag(*s); RoleMaster::iterator p, p_end; // build all GCIs DLTree* GCI = Axioms.getGCI(); // add special domains to the GCIs if ( likely(useSpecialDomains) ) for ( p = ORM.begin(), p_end = ORM.end(); p < p_end; ++p ) if ( !(*p)->isSynonym() && (*p)->hasSpecialDomain() ) GCI = createSNFAnd ( GCI, clone((*p)->getTSpecialDomain()) ); // take chains that lead to Bot role into account if ( !ORM.getBotRole()->isSimple() ) GCI = createSNFAnd ( GCI, new DLTree ( TLexeme(FORALL), createRole(ORM.getBotRole()), createBottom() ) ); T_G = tree2dag(GCI); deleteTree(GCI); // mark GCI flags GCIs.setGCI(T_G != bpTOP); GCIs.setReflexive(ORM.hasReflexiveRoles()); // builds functional labels for roles for ( p = ORM.begin(), p_end = ORM.end(); p < p_end; ++p ) if ( !(*p)->isSynonym() && (*p)->isTopFunc() ) (*p)->setFunctional ( atmost2dag ( 1, *p, bpTOP ) ); for ( p = DRM.begin(), p_end = DRM.end(); p < p_end; ++p ) if ( !(*p)->isSynonym() && (*p)->isTopFunc() ) (*p)->setFunctional ( atmost2dag ( 1, *p, bpTOP ) ); // check the type of the ontology if ( nNominalReferences > 0 ) { unsigned int nInd = i_end() - i_begin(); if ( nInd > 100 && nNominalReferences > nInd ) isLikeWINE = true; } // here DAG is complete; set its final size DLHeap.setFinalSize(); }
void TBox :: gatherRelevanceInfo ( void ) { nRelevantCCalls = 0; nRelevantBCalls = 0; // gather GCIs features curFeature = &GCIFeatures; markGCIsRelevant(); clearRelevanceInfo(); KBFeatures |= GCIFeatures; // fills in nominal cloud relevance info NCFeatures = GCIFeatures; // set up relevance info for ( i_iterator pi = i_begin(); pi != i_end(); ++pi ) { setConceptRelevant(*pi); NCFeatures |= (*pi)->posFeatures; } // correct NC inverse role information if ( NCFeatures.hasSomeAll() && !RelatedI.empty() ) NCFeatures.setInverseRoles(); for ( c_iterator pc = c_begin(); pc != c_end(); ++pc ) setConceptRelevant(*pc); long cSize = ( c_end() - c_begin() ) + ( i_end() - i_begin() ); size_t bSize = DLHeap.size()-2; curFeature = nullptr; float cRatio, bRatio = 0, logCSize = 1, logBSize = 1, sqCSize = 1, sqBSize = 1; if ( cSize > 10 ) { cRatio = ((float)nRelevantCCalls)/cSize; sqCSize = sqrtf((float)cSize); if ( cSize > 1 ) logCSize = logf((float)cSize); } if ( bSize > 20 ) { bRatio = ((float)nRelevantBCalls)/bSize; sqBSize = sqrtf((float)bSize); if ( bSize > 1 ) logBSize = logf((float)bSize); } if (0) // relevance stat { if ( LLM.isWritable(llAlways) && cSize > 10 ) LL << "There were made " << nRelevantCCalls << " relevance C calls for " << cSize << " concepts\nRC ratio=" << cRatio << ", ratio/logSize=" << cRatio/logCSize << ", ratio/sqSize=" << cRatio/sqCSize << ", ratio/size=" << cRatio/cSize<< "\n"; if ( LLM.isWritable(llAlways) && bSize > 20 ) LL << "There were made " << nRelevantBCalls << " relevance B calls for " << bSize << " nodes\nRB ratio=" << bRatio << ", ratio/logSize=" << bRatio/logBSize << ", ratio/sqSize=" << bRatio/sqBSize << ", ratio/size=" << bRatio/bSize << "\n"; } // set up GALEN-like flag; based on r/n^{3/2}, add r/n^2<1 isLikeGALEN = (bRatio > sqBSize*20) && (bRatio < bSize); // switch off sorted reasoning iff top role appears if ( KBFeatures.hasTopRole() ) useSortedReasoning = false; }