/* build the retention index */ map<string, double> RetentionModel::BuildRetentionIndex(const set<string> &aa_alphabet, const bool normalized_rts, vector<PSMDescription> &psms) { if (VERB >= 4) { cerr << "Training retention index..." << endl; } if (!normalized_rts) { PSMDescription::setPSMSet(psms); sub_ = PSMDescription::normSub; div_ = PSMDescription::normDiv; PSMDescription::normalizeRetentionTimes(psms); } // set the amino acids alphabet vector<string> alphabet(aa_alphabet.begin(), aa_alphabet.end()); retention_features_.set_amino_acids_alphabet(alphabet); // set the aa as the active features bitset<RetentionFeatures::NUM_FEATURE_GROUPS> tmp; retention_features_.set_active_feature_groups(tmp.set(RetentionFeatures::AA_GROUP)); // compute the amino acid features retention_features_.ComputeRetentionFeatures(psms); // normalize the features NormalizeFeatures(true, psms); // initialize a linear svr InitSVR(true); // calibrate the model int number_features = retention_features_.GetTotalNumberFeatures(); svr_model_->CalibrateModel(psms, number_features); // train the model svr_model_->TrainModel(psms, number_features); // get the index (weights of the linear SVR) if (VERB >= 4) { cerr << "Done." << endl << endl; } return GetRetentionIndex(); }
int main() { int key = 8; std::string alphabet("abcdefghijklmnopqrstuvwxyz .;_"); Receiver bob( key , alphabet ); Transmitter alice( key , alphabet ); std::string message ="mi nombre es victor miguel sequeiros arapa"; alice.rail_cipher(message); std::cout << message << std::endl; bob.rail_decipher(message); std::cout << message << std::endl; /* alice.route_cipher(message); std::cout << message << std::endl; bob.route_decipher(message); std::cout << message << std::endl; */ return 0; };
void Processor::encode_text(int padding) { static const zchar again[] = { 'a', 'g', 'a', 'i', 'n', 0, 0, 0, 0 }; static const zchar examine[] = { 'e', 'x', 'a', 'm', 'i', 'n', 'e', 0, 0 }; static const zchar wait[] = { 'w', 'a', 'i', 't', 0, 0, 0, 0, 0 }; zbyte *zchars; const zchar *ptr; zchar c; int i = 0; if (_resolution == 0) find_resolution(); zchars = new byte[3 * (_resolution + 1)]; ptr = _decoded; // Expand abbreviations that some old Infocom games lack if (_expand_abbreviations && (h_version <= V8)) { if (padding == 0x05 && _decoded[1] == 0) { switch (_decoded[0]) { case 'g': ptr = again; break; case 'x': ptr = examine; break; case 'z': ptr = wait; break; default: break; } } } // Translate string to a sequence of Z-characters while (i < 3 * _resolution) { if ((c = *ptr++) != 0) { int index, set; zbyte c2; if (c == ' ') { zchars[i++] = 0; continue; } // Search character in the alphabet for (set = 0; set < 3; set++) for (index = 0; index < 26; index++) if (c == alphabet (set, index)) goto letter_found; // Character not found, store its ZSCII value c2 = translate_to_zscii(c); zchars[i++] = 5; zchars[i++] = 6; zchars[i++] = c2 >> 5; zchars[i++] = c2 & 0x1f; continue; letter_found: // Character found, store its index if (set != 0) zchars[i++] = ((h_version <= V2) ? 1 : 3) + set; zchars[i++] = index + 6; } else {
static int decode_char(char c) { cad_hash_t *map = alphabet(); void *res = map->get(map, &c); if (res == NULL) { return -1; } return *((int*)res); }
QString generateRandomString(){ QString sAlphabet = alphabet(); int len = qrand() % 55 + 2; QString str = ""; for (int i = 0; i < len; i++) { str += sAlphabet[qrand() % sAlphabet.length()]; } return str; }
int main() { Printer::initializePrinter(); Printer::drawCanvas(255,255,255,255); std::ifstream fileAlphabet("../assets/fonts/Alphabet.txt"); AlphabetCurve alphabet(fileAlphabet); alphabet.drawTextCentered("A B C DEF",100,0.1,Texture::createSingleColorTexture(0,0,255,255)); Printer::printToScreen(); Printer::finishPrinter(); return 0; }
// Finds all occurrences of a circular pattern. std::set<int> Multv::cmatch(std::string &pattern) { assert(st_ != NULL); std::set<char> pattern_alpha = alphabet(pattern); assert(pattern_alpha.find('$') == pattern_alpha.end() && pattern_alpha.find('#') == pattern_alpha.end()); pattern += pattern; // form PP pattern.push_back('#'); // add termination character st_->insertPattern(pattern, false); std::set<int> matches(st_->getMatches()); st_->removePattern(); return matches; }
TEST(Automata, TransitionFunction_Alphabet){ unsigned int expectedNumberOfSymbols = 5; unsigned int numberOfStates = 3; Alphabet alphabet(expectedNumberOfSymbols ); TransitionFunction tf(&alphabet, numberOfStates); unsigned int actualNumberOfSymbols = tf.getSymbolCount(); EXPECT_EQ(expectedNumberOfSymbols, actualNumberOfSymbols); }
/* train a retention model; the svr_index is given as a parameter */ int RetentionModel::TrainRetentionModel(const set<string> &aa_alphabet, const map<string, double> &index, const bool normalized_rts, vector<PSMDescription> &psms) { if (VERB >= 4) { cerr << "Training retention model..." << endl; } // normalize if (!normalized_rts) { PSMDescription::setPSMSet(psms); sub_ = PSMDescription::normSub; div_ = PSMDescription::normDiv; PSMDescription::normalizeRetentionTimes(psms); } // set the amino acids alphabet and the index vector<string> alphabet(aa_alphabet.begin(), aa_alphabet.end()); retention_features_.set_amino_acids_alphabet(alphabet); retention_features_.set_svr_index(index); // set the active features; this should be modified as we add more feature groups bitset<RetentionFeatures::NUM_FEATURE_GROUPS> tmp; if (index.size() <= 20) { retention_features_.set_active_feature_groups( tmp.set(RetentionFeatures::INDEX_NO_PTMS_GROUP)); } else { retention_features_.set_active_feature_groups( tmp.set(RetentionFeatures::INDEX_PHOS_GROUP)); } // compute the amino acid features retention_features_.ComputeRetentionFeatures(psms); // normalize the features NormalizeFeatures(true, psms); // save the sub and the div vsub_ = the_normalizer_->GetVSub(); vdiv_ = the_normalizer_->GetVDiv(); // initialize a RBF SVR if (svr_model_) { delete svr_model_; } InitSVR(false); // calibrate the model int number_features = retention_features_.GetTotalNumberFeatures(); //cout << number_features << endl; //cout << psms[0] << endl; svr_model_->CalibrateModel(psms, number_features); // train the model svr_model_->TrainModel(psms, number_features); // unnormalize the retention time PSMDescription::unnormalizeRetentionTimes(psms); if (VERB >= 4) { cerr << "Done." << endl << endl; } return 0; }
int main() { int t,i,j; int c='a'; for(t=1; t<9; t++) { for(i=0; i<2+t; ++i) { printf("%c",alphabet(c+i)); if(i==0||i==t+1) for(j=0; j<t; ++j) printf(" "); else { for(j=0; j<t-i; ++j) printf(" "); printf("%c",alphabet(c+2*t+2-i)); for(j=0; j<i-1; ++j) printf(" "); } printf("%c\n",alphabet(c+2*t+2+i)); } c=alphabet(c+3*t+4); } return 0; }
void PeopleGroupedView::setupModel() { MWidgetView::setupModel(); if (m_mainLayout){ qDebug() << "MODEL CLEARED"; clearLayout(m_mainLayout); } m_itemModel = m_controller->itemModel(); m_mainLayout = new QGraphicsGridLayout(m_controller); m_mainLayout->setContentsMargins(0, 0, 0, 0); m_mainLayout->setSpacing(0); connect(m_itemModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(rowsInserted(QModelIndex,int,int)), Qt::UniqueConnection); connect(m_itemModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(rowsRemoved(QModelIndex,int,int)), Qt::UniqueConnection); connect(m_itemModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChanged(QModelIndex,QModelIndex)), Qt::UniqueConnection); connect(m_itemModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(rowsMoved(QModelIndex,int,int,QModelIndex,int)), Qt::UniqueConnection); connect(m_itemModel, SIGNAL(layoutChanged()), this, SLOT(layoutChanged()), Qt::UniqueConnection); connect(m_itemModel, SIGNAL(modelReset()), this, SLOT(modelReset()), Qt::UniqueConnection); QString alphabet(QObject::tr("a b c d e f g h i j k l m n o p q r s t u v w x y z", "Alphabet for contact index")); m_headings = alphabet.split(" ", QString::SkipEmptyParts); QString capitals(QObject::tr("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z","Alphabet for contact index")); m_displayHeadings = capitals.split(" ", QString::SkipEmptyParts); m_numSections = m_headings.count(); qDebug() << "m_numSections : " << m_numSections; // initialize vector elements to zero m_sectionCounts.clear(); m_sectionCounts.resize(m_numSections + 2); int rows = m_itemModel->rowCount(); for (int i=0; i<rows; ++i){ qDebug() << "PeopleGroupedView::setupModel() insertCard at" << i; insertCard(m_itemModel->index(i, 0)); } }
/* * Benchmark the find functions family * @param func tells which find-function to bench */ float StropBencher::find(int numRuns, int strType, int func) { float startTime = currTime(); std::string alphabet("abcdefghiljkmnopqrstuvwxyz"); const char * c_str = "a\0b\0c\0d\0e\0f\0g\0h\0i\0j\0k\0l\0m\0n\0o\0p\0q\0r\0s\0t\0u\0v\0w\0x\0y\0z\0"; std::string largeAlphabet("abcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyz"); int res; //result of find (position where char was found or -1 on no match) switch(strType) { case MAUTIL_STRING: for(int i = 0; i < numRuns; ++i){ for(int j = 0; j < ALOT; ++j){ for(char k = 0; k < alphabet.length(); ++k){ if(func == 0){ res = alphabet.find(c_str+2*k, 0); if(res == -1) printf("Error in find(), no match but it should be!"); }else if(func == 1){ res = largeAlphabet.find_last_of((char) k+97); //ascii val of 'a' is 97 if(res == -1) printf("Error in find_last_of(), no match but it should be!"); }else if(func == 2){ res = largeAlphabet.find_first_of((char) k+97, rand()%(largeAlphabet.length()-1)); //randomize starting position }else{ res = largeAlphabet.find_first_not_of((char) k+97, rand()%(largeAlphabet.length()-1)); //randomize starting position if(res == -1) printf("Error in find_first_not_of(), no match but it should be!"); } } } } /*case STD_STRING: TODO Will have to wait until STL is implemented*/ } return currTime() - startTime; }
/* write ind file */ void indwrite(char *filename, struct index *ind, int pagenum) { int i,j,hpoint=0; char datama[2048],lbuff[BUFFERLEN]; FILE *fp; int conv_euc_to_euc; if (filename && kpse_out_name_ok(filename)) fp=fopen(filename,"wb"); else { fp=stdout; #ifdef WIN32 setmode(fileno(fp), _O_BINARY); #endif } conv_euc_to_euc = is_internalUPTEX() ? 1 : 0; if (conv_euc_to_euc) set_enc_string(NULL, "euc"); convert(atama,datama); if (conv_euc_to_euc) set_enc_string(NULL, "uptex"); fputs(preamble,fp); if (fpage>0) { fprintf(fp,"%s%d%s",setpage_prefix,pagenum,setpage_suffix); } for (i=line_length=0;i<lines;i++) { if (i==0) { if (!((alphabet(ind[i].dic[0][0]))||(japanese(ind[i].dic[0])))) { if (lethead_flag) { if (symbol_flag && strlen(symbol)) { fprintf(fp,"%s%s%s",lethead_prefix,symbol,lethead_suffix); } else if (lethead_flag>0) { fprintf(fp,"%s%s%s",lethead_prefix,symhead_positive,lethead_suffix); } else if (lethead_flag<0) { fprintf(fp,"%s%s%s",lethead_prefix,symhead_negative,lethead_suffix); } } SPRINTF(lbuff,"%s%s",item_0,ind[i].idx[0]); } else if (alphabet(ind[i].dic[0][0])) { if (lethead_flag>0) { fprintf(fp,"%s%c%s",lethead_prefix,ind[i].dic[0][0],lethead_suffix); } else if (lethead_flag<0) { fprintf(fp,"%s%c%s",lethead_prefix,ind[i].dic[0][0]+32,lethead_suffix); } SPRINTF(lbuff,"%s%s",item_0,ind[i].idx[0]); } else if (japanese(ind[i].dic[0])) { if (lethead_flag) { fputs(lethead_prefix,fp); for (j=hpoint;j<(strlen(datama)/2);j++) { if ((unsigned char)ind[i].dic[0][1]<(unsigned char)datama[j*2+1]) { fprint_euc_char(fp,atama[(j-1)*2],atama[(j-1)*2+1]); hpoint=j; break; } } if (j==(strlen(datama)/2)) { fprint_euc_char(fp,atama[(j-1)*2],atama[(j-1)*2+1]); } fputs(lethead_suffix,fp); } SPRINTF(lbuff,"%s%s",item_0,ind[i].idx[0]); for (hpoint=0;hpoint<(strlen(datama)/2);hpoint++) { if ((unsigned char)ind[i].dic[0][1]<(unsigned char)datama[hpoint*2+1]) { break; } } } switch (ind[i].words) { case 1: SAPPENDF(lbuff,"%s",delim_0); break; case 2: SAPPENDF(lbuff,"%s%s",item_x1,ind[i].idx[1]); SAPPENDF(lbuff,"%s",delim_1); break; case 3: SAPPENDF(lbuff,"%s%s",item_x1,ind[i].idx[1]); SAPPENDF(lbuff,"%s%s",item_x2,ind[i].idx[2]); SAPPENDF(lbuff,"%s",delim_2); break; default: break; } printpage(ind,fp,i,lbuff); } else { if (!((alphabet(ind[i].dic[0][0]))||(japanese(ind[i].dic[0])))) { if ((alphabet(ind[i-1].dic[0][0]))||(japanese(ind[i-1].dic[0]))){ fputs(group_skip,fp); if (lethead_flag && symbol_flag) { fprintf(fp,"%s%s%s",lethead_prefix,symbol,lethead_suffix); } } } else if (alphabet(ind[i].dic[0][0])) { if (ind[i].dic[0][0]!=ind[i-1].dic[0][0]) { fputs(group_skip,fp); if (lethead_flag>0) { fprintf(fp,"%s%c%s",lethead_prefix,ind[i].dic[0][0],lethead_suffix); } else if (lethead_flag<0) { fprintf(fp,"%s%c%s",lethead_prefix,ind[i].dic[0][0]+32,lethead_suffix); } } } else if (japanese(ind[i].dic[0])) { for (j=hpoint;j<(strlen(datama)/2);j++) { if ((unsigned char)(ind[i].dic[0][0]<=(unsigned char)datama[j*2])&&((unsigned char)ind[i].dic[0][1]<(unsigned char)datama[j*2+1])) { break; } } if ((j!=hpoint)||(j==0)) { hpoint=j; fputs(group_skip,fp); if (lethead_flag!=0) { fputs(lethead_prefix,fp); fprint_euc_char(fp,atama[(j-1)*2],atama[(j-1)*2+1]); fputs(lethead_suffix,fp); } } } switch (ind[i].words) { case 1: SAPPENDF(lbuff,"%s%s%s",item_0,ind[i].idx[0],delim_0); break; case 2: if (strcmp(ind[i-1].idx[0],ind[i].idx[0])!=0 || strcmp(ind[i-1].dic[0],ind[i].dic[0])!=0) { SAPPENDF(lbuff,"%s%s%s",item_0,ind[i].idx[0],item_x1); } else { if (ind[i-1].words==1) { SAPPENDF(lbuff,"%s",item_01); } else { SAPPENDF(lbuff,"%s",item_1); } } SAPPENDF(lbuff,"%s",ind[i].idx[1]); SAPPENDF(lbuff,"%s",delim_1); break; case 3: if (strcmp(ind[i-1].idx[0],ind[i].idx[0])!=0 || strcmp(ind[i-1].dic[0],ind[i].dic[0])!=0) { SAPPENDF(lbuff,"%s%s",item_0,ind[i].idx[0]); SAPPENDF(lbuff,"%s%s%s",item_x1,ind[i].idx[1],item_x2); } else if (ind[i-1].words==1) { SAPPENDF(lbuff,"%s%s%s",item_01,ind[i].idx[1],item_x2); } else if (strcmp(ind[i-1].idx[1],ind[i].idx[1])!=0 || strcmp(ind[i-1].dic[1],ind[i].dic[1])!=0) { if (ind[i-1].words==2) SAPPENDF(lbuff,"%s%s%s",item_1,ind[i].idx[1],item_12); else SAPPENDF(lbuff,"%s%s%s",item_1,ind[i].idx[1],item_x2); } else { SAPPENDF(lbuff,"%s",item_2); } SAPPENDF(lbuff,"%s%s",ind[i].idx[2],delim_2); break; default: break; } printpage(ind,fp,i,lbuff); } } fputs(postamble,fp); if (filename) fclose(fp); }
void add(const std::string &lang, const std::string &a) { m_alphabets.emplace(std::pair<std::string, alphabet>(lang, alphabet(a))); }
int main(int argc, char *argv[]) { char buf[MAX_BUF_SIZE]; char temp[MAX_BUF_SIZE]; char* ftransition; string test_strings[32]; char* token; SetType* fstates; SetType* falphabet; char fstart_state; SetType* faccept_states; FSAType* f; int test_strings_counter = -1; int section_num = 0; FILE* fp; FILE* fout; /* Primary Testing Procedures */ SetType states("xyz"); SetType alphabet("01"); char trans[50] = "x-0,y,1,x;y-0,z,1,z;z-0,y,1,x"; SetType accept("y"); FSAType a(&states,&alphabet,trans,'x',&accept); a.write(); char state = a.nextState('y', '0'); cout << "Where to go from y on a 0: " << state << endl; a.is_accepted("10") ? cout << "10 accepted\n" : cout << "10 not accepted\n"; a.is_accepted("100") ? cout << "100 accepted\n" : cout << "100 not accepted\n"; /* Thorough Testing Procedures */ fp = fopen("fsadata.dat", "rt"); if(fp == NULL) { cout << "\n*error opening file*\n"; system("PAUSE"); return 0; } fout = fopen("results.dat", "wt"); if(fp == NULL) { cout << "\n*error opening file*\n"; system("PAUSE"); return 0; } while(!feof(fp)) { fgets(buf, sizeof(buf), fp); /* strip \n */ buf[strlen(buf)-1] = '\0'; if(buf[0] == '[') { /* section delimiter */ section_num++; } else { if(section_num == 1) { test_strings_counter++; test_strings[test_strings_counter] = (string)buf; /*cout << test_strings[test_strings_counter] << "<" << buf << ">" << test_strings[test_strings_counter].length() << " " << strlen(buf);*/ } if(section_num == 2) { token = strtok(buf, "|"); fstates = new SetType(token); token = strtok(NULL, "|"); falphabet = new SetType(token); ftransition = strtok(NULL, "|"); token = strtok(NULL, "|"); fstart_state = token[0]; token = strtok(NULL, "|"); /* eliminate non-printing characters that may be at the end of the line */ if(!((token[strlen(token)-1] > 'a' && token[strlen(token)-1] < 'z') || (token[strlen(token)-1] > 'A' && token[strlen(token)-1] < 'A') || (token[strlen(token)-1] > '0' && token[strlen(token)-1] < '9'))) { token[strlen(token)-1] = '\0'; } faccept_states = new SetType(token); /* now put it all together */ f = new FSAType(fstates,falphabet,ftransition,fstart_state, faccept_states); for(int i = 0; i < test_strings_counter; i++) { token = (char*)test_strings[i].c_str(); if(!f->is_accepted(test_strings[i].c_str())) { token = strcat(token, " "); token = strcat(token, "is accepted\n"); fputs(token, fout); } else { token = strcat(token, " "); token = strcat(token, "is not accepted\n"); fputs(token, fout); } } fputs("\n", fout); } } } system("PAUSE"); return 0; }
Multv::Multv(std::string &text) { std::set<char> text_alpha = alphabet(text); assert(text_alpha.find('$') == text_alpha.end() && text_alpha.find('#') == text_alpha.end()); text.push_back('$'); // add termination character st_ = new WeinerST(text); // deleted in Multv destructor }
std::map<Key, sem_elem_t> WFA::readOutCombineOverAllPathsValues() { return readOutCombineOverAllPathsValues(alphabet()); }
QList<Cell*> Grid::solve(bool guess) { // get the safest cell HistoryFrame* startFrame = nullptr; if( !history.isEmpty() ) history.top(); Cell* target = getSafestCell(); while( target != nullptr ) { // the safest cell has no valid numbers, we made a mistake somewhere if( target->domain().size() == 0 ) { // backtrack until some options present themselves HistoryFrame* lastOption = undo(); while( lastOption!=nullptr && lastOption->optionPriorities.size() == 0 ){ delete lastOption; lastOption = undo(); } // if there are no frames with options, error and break if( lastOption == nullptr ){ Logger::log("No solutions!"); break; } // backtrack and continue setCellAndUpdate(lastOption); Logger::log(QString("Cell at (%1,%2) has no solution, backtracking").arg( QString::number(target->rowIndex()), QString::number(target->columnIndex()) )); Logger::log( QString("Guessing %1 at cell (%2,%3)") .arg(alphabet().at(lastOption->target->value()), QString::number(lastOption->target->rowIndex()), QString::number(lastOption->target->columnIndex())) ); } // the safest cell has just one possibility, choose it else if( target->domain().size() == 1 ) { // set cell right away, no need to optimize setCellAndUpdate(target, target->domain().values()[0]); } // the safest cell has multiple options, guess and continue else if( guess ){ // do make a guess and continue auto options = getSafestValues(target); char bestValue = options.dequeue(); setCellAndUpdate(target, bestValue, options); Logger::log( QString("Guessing %1 at cell (%2,%3)") .arg(alphabet().at(bestValue), QString::number(target->rowIndex()), QString::number(target->columnIndex())) ); } // multiple options, and guessing not allowed, break else { break; } // get the next cell target = getSafestCell(); } if( startFrame != nullptr ){ return unwindHistorySince(startFrame).toList(); } else { return unwindHistorySince(history.at(0)).toList(); } }