void test_unfold( ) { typedef IntLabeledGraph Graph; typedef Graph::edge_type edge_type; typedef Graph::vertex_type vertex_type; Graph F; int o = F.newVertex( ); Word x1( 1 ); Word x2( 2 ); for( int i=0 ; i<5; ++i ) { Word w = Word::randomWord( 2 , 3 ); addLoop( F , o , w.begin( ) , w.end( ) ); } set< int > candidates; candidates.insert( o ); list< FoldDetails< vertex_type , edge_type > > details; fold( F , candidates , &details ); if( F.getVertices( ).size( )>1 ) return; pair< bool , list< edge_type > > path = trace_path( F , o , x2.begin( ) , x2.end( ) ); liftup( F , o , path.second , details.begin( ) , details.end( ) ); }
int main( ) { FPGroup G; cout << "Enter nilpotentcy class first then group "; int NilpotentcyClass; cin >> NilpotentcyClass; Chars errMsg = cin >> G; if (errMsg.length()>0) return 1; NilpotentGroup ng(G.namesOfGenerators(), NilpotentcyClass,makeVectorOf(G.getRelators())); ng.initialize(); VectorOf<Word> vw; Word w; for (int i=1;true;i++){ cout << endl << "Enter the "<<i<<" generator of subgroup"<< endl; cout << "Empty word to finish: "; w = G.readWord(cin,errMsg); if (w.length()==0) break; if (errMsg.length()>0) return 1; vw.append(w); } SGOfNilpotentGroup sg(ng,vw); sg.initBasis(); sg.printBasis(cout); cout << "The Hirsch number :" << sg.theHirschNumber() << endl; cout << "Index in parent group :" << sg.index() << endl; cout << "Is Trivial :" << sg.isTrivial() << endl; cout << "Is Central :" << sg.isCentral() << endl; cout << "Is normal :" << sg.isNormal() << endl; cout << "Is abelian :" << sg.isAbelian() << endl; cout << "Subgroup class :" << sg.subgroupClass() << endl; cout << "Generators of normal closure :" << endl; vw = sg.normalClosureGens(); for (int i=0;i<vw.length();i++){ G.printWord(cout,vw[i]); cout << endl; } PresentationForSNG sgp = sg.makePresentation(); cout << "Presentation of subgroup :" << endl; sgp.print(cout); cout << endl << "Enter the word :"; errMsg = ""; w = G.readWord(cin,errMsg); if (errMsg.length()>0){ cout << errMsg; return 1; } cout << endl << "Does subgroup contain the word :" << sg.contains(w) << endl; PolyWord result; if (sg.decompose(ng.decompose(w),result)) cout << "Decomposition in sg basis :" << sg.asDecomposition(result); else cout << "Subgroup does not contain this word"; }
// get wordID_t index for word represented as string wordID_t Vocab::GetWordID(const std::string& word_str, const FactorDirection& direction, const FactorList& factors, bool isNonTerminal) { // get id for factored string Word word; word.CreateFromString( direction, factors, word_str, isNonTerminal); return GetWordID( word); }
int Group::right (int v, const Word& word) { int g = v; for (unsigned t=0; t<word.size(); ++t) { g = right(g, word[word.size() -t -1]); } return g; }
//测试word的相关操作 int main6() { Word *word = new Word("wordfdsafds"); RedisProxy redisProxy("localhost", 6379); redisProxy.addWord(word); word = redisProxy.getWord(word->getId()); std::cout << word->getId() << " " << word->getName(); return 0; }
Word GAConjProblemForORGroupSolver::greedyReduce( const OneRelatorGroup& group , const Word& word ) { Word w = word; w = w.cyclicallyReduce( ); while( oneGreedyReduce( group , w ) ); return w; }
static Word MakeWord(string text) { FactorCollection &factorCollection = FactorCollection::Instance(); const Factor* f = factorCollection.AddFactor(Input,0,text); Word w; w.SetFactor(0,f); return w; }
wordID_t Vocab::GetWordID(const std::string& word_str) { FactorList factors; factors.push_back(0); Word word; word.CreateFromString(Input, factors, word_str, false); return GetWordID(word); }
bool operator > (Word w1, Word w2) { string w1word = w1.getWord(); string w2word = w2.getWord(); transform(w1word.begin(), w1word.end(), w1word.begin(), ::toupper); transform(w2word.begin(), w2word.end(), w2word.begin(), ::toupper); return (w1word > w2word); }
Word TheGrigorchukGroupAlgorithms::reduce( const Word& w ) { Word result; for( Word::const_iterator w_it=w.begin( ) ; w_it!=w.end( ) ; ++w_it ) push_back( result , *w_it ); return result; }
Word int2word(int g) { Word result; while (g) { result.push_back((g % 10) - 1); g /= 10; } return result; }
void GlobalLexicalModel::Load() { FactorCollection &factorCollection = FactorCollection::Instance(); const std::string& factorDelimiter = StaticData::Instance().GetFactorDelimiter(); VERBOSE(2, "Loading global lexical model from file " << m_filePath << endl); m_inputFactors = FactorMask(m_inputFactorsVec); m_outputFactors = FactorMask(m_outputFactorsVec); InputFileStream inFile(m_filePath); // reading in data one line at a time size_t lineNum = 0; string line; while(getline(inFile, line)) { ++lineNum; vector<string> token = Tokenize<string>(line, " "); if (token.size() != 3) { // format checking UTIL_THROW2("Syntax error at " << m_filePath << ":" << lineNum << ":" << line); } // create the output word Word *outWord = new Word(); vector<string> factorString = Tokenize( token[0], factorDelimiter ); for (size_t i=0 ; i < m_outputFactorsVec.size() ; i++) { const FactorDirection& direction = Output; const FactorType& factorType = m_outputFactorsVec[i]; const Factor* factor = factorCollection.AddFactor( direction, factorType, factorString[i] ); outWord->SetFactor( factorType, factor ); } // create the input word Word *inWord = new Word(); factorString = Tokenize( token[1], factorDelimiter ); for (size_t i=0 ; i < m_inputFactorsVec.size() ; i++) { const FactorDirection& direction = Input; const FactorType& factorType = m_inputFactorsVec[i]; const Factor* factor = factorCollection.AddFactor( direction, factorType, factorString[i] ); inWord->SetFactor( factorType, factor ); } // maximum entropy feature score float score = Scan<float>(token[2]); // std::cerr << "storing word " << *outWord << " " << *inWord << " " << score << endl; // store feature in hash DoubleHash::iterator keyOutWord = m_hash.find( outWord ); if( keyOutWord == m_hash.end() ) { m_hash[outWord][inWord] = score; } else { // already have hash for outword, delete the word to avoid leaks (keyOutWord->second)[inWord] = score; delete outWord; } } }
void WQueue::print() { Word* cur = front; while (cur != NULL) { cout << cur->getData() << " "; cur = cur->getNext(); } }
void TTSQueue::DisplayS() { Word * word = header; while(word != NULL) { word->DisplayS(); word = word->next; } }
Word Word::operator+(const Word& rhs) { char* temp = new char[this->string_length_ + rhs.len() - 1]; strcpy(temp, this->string_); strcat(temp, rhs.getString()); Word sum(temp); delete [] temp; return sum; }
//word TEST_F(Gtest, test_Word) { std::string name = "wordfdsafds"; Word *word = new Word("wordfdsafds"); RedisProxy redisProxy("localhost", 6379); redisProxy.addWord(word); word = redisProxy.getWord(word->getId()); std::cout << word->getId() << " " << word->getName() << std::endl; EXPECT_EQ(name, word->getName()); }
int main10() { RedisProxy redisProxy("localhost", 6379); User *user = new User("yinliang"); Word * word = new Word("ABCD"); redisProxy.addUser(user); redisProxy.addWord(word); redisProxy.userBuyWord(user->getId(), word->getId()); }
Elt SubgroupRep::eval( const Word& w ) const { #if SAFETY > 0 if ( w.maxOccurringGenerator() > theNumberOfGenerators ) error("SubgroupRep::eval: attempt to evaluate word with no " "interpretation in parent group"); #endif return w.replaceGenerators(theGenerators); }
void Probe::operator()(const SmartPointer<Block> &block) { interp(block); if (!block->isDeleted()) { if (!didOutputProbe && block->findWord('M', 3)) { outputProbe(); didOutputProbe = true; } if (didOutputProbe && block->findWord('G', 1) && getAxisPosition('Z') < clearHeight) { double x = getAxisPosition('X'); double y = getAxisPosition('Y'); double z = getAxisPosition('Z'); vector<ProbePoint *> pt = grid->find(Vector2D(x, y)); double x1 = pt[0]->x(); double x2 = pt[1]->x(); double y1 = pt[0]->y(); double y2 = pt[2]->y(); double denom = (x2 - x1) * (y2 - y1); double v[4] = { ((x2 - x) * (y2 - y)) / denom, ((x - x1) * (y2 - y)) / denom, ((x2 - x) * (y - y1)) / denom, ((x - x1) * (y - y1)) / denom, }; SmartPointer<Entity> expr; Word *zWord = block->findWord('Z'); if (useLastZExpression) expr = getVarExpr('Z'); else if (zWord) expr = zWord->getExpression(); else expr = new Number(z); for (int i = 0; i < 4; i++) { if (!pt[i]->address) THROWS("Point " << pt[i] << " does not have address"); SmartPointer<Entity> ref = new Reference(new Number(pt[i]->address)); SmartPointer<Entity> num = new Number(v[i]); expr = new BinaryOp(Operator::ADD_OP, expr, new BinaryOp(Operator::MUL_OP, ref, num)); } expr = new QuotedExpr(expr); if (!zWord) { zWord = new Word('Z', expr); block->push_back(zWord); } else zWord->setExpression(expr); } } Printer::operator()(block); }
void Wordreciting::start() { isStart = true; wordlist = (strategy->selectRandom ? random : ordered); for (int i = 0; i < wordlist->size(); i++) { Word *word = wordlist->getWord(i); word->setLevel(); } }
bool QuadEquationTranformationGraph::isTrivialSolution( const Word& e ) const { Word r; for( Word::const_iterator e_it=e.begin() ; e_it!=e.end( ) ; ++e_it ) { int g = *e_it; if( theEquation.isGenerator( g ) ) r.push_back( g ); } return r.length( )==0; }
vector< int > getTail( int N , const Word& w ) { vector< int > V( N , 0 ); for( Word::const_iterator w_it=w.begin( ) ; w_it!=w.end( ) ; ++w_it ) { int x = *w_it; int ax = abs(x); V[ax-1] += x>0 ? 1:-1; } return V; }
bool Equation::trivialSolution( ) const { Word image; Word::const_iterator w_it = theEquation.begin( ); for( ; w_it!=theEquation.end( ) ; ++w_it ) if( isGenerator(*w_it) ) image.push_back( *w_it ); return image.length()==0; }
WQueue::WQueue(WQueue& q) { Word* cur = q.getFront(); while ( cur!= NULL) { insert(cur->getData()); cur = cur->getNext(); } }
Word Group::parse (int v) { Word result; v = inv[v]; //to parse forwards for (int j=whence[v]; j!= IDENTITY; j = whence[v]) { result.push_back(j); v = left(v,j); } return result; }
Elt Map::evalImage( const Word& w ) const { if (w.length() == 0) return range().eval(w); // don't bother to compute the image of the trivial word Elt res = range().eval( imageOf(w[0]) ); for (int i = 1; i < w.length(); i++) res = range().multiply( res, range().eval( imageOf(w[i]) ) ); return res; }
/*virtual*/ void Distributor::Manipulate( Data& data ) { Word* word = dynamic_cast< Word* >( data.oldResult ); if( word ) { if( word->type == Word::SUM && word->scalar ) { for( ResultList::Node* node = word->resultList.Head(); node; node = node->Next() ) { Word* nestedWord = dynamic_cast< Word* >( node->data ); if( nestedWord ) nestedWord->ScaleBy( word->scalar ); else { Word* product = new Word( Word::GEOMETRIC_PRODUCT ); product->resultList.InsertAfter()->data = word->scalar->Clone(); product->resultList.InsertAfter()->data = node->data; node->data = product; } } delete word->scalar; word->scalar = nullptr; data.treeModified = true; return; } for( ResultList::Node* node = word->resultList.Head(); node; node = node->Next() ) { Word* nestedWord = dynamic_cast< Word* >( node->data ); if( nestedWord && word->DistributesOver( nestedWord ) ) { Word* newWord = new Word( nestedWord->type ); for( ResultList::Node* nestedNode = nestedWord->resultList.Head(); nestedNode; nestedNode = nestedNode->Next() ) { Word* newNestedWord = new Word( word->type ); for( ResultList::Node* leftNode = word->resultList.Head(); leftNode != node; leftNode = leftNode->Next() ) newNestedWord->resultList.InsertAfter()->data = leftNode->data->Clone(); newNestedWord->resultList.InsertAfter()->data = nestedNode->data->Clone(); for( ResultList::Node* rightNode = word->resultList.Tail(); rightNode != node; rightNode = rightNode->Prev() ) newNestedWord->resultList.InsertBefore()->data = rightNode->data->Clone(); } data.newResult = newWord; data.treeModified = true; return; } } } }
Word str2word(const char* g) { Word result; char num[2] = { 0, 0 }; int I = (int)strlen(g); for (int i = 0; i < I; ++i) { num[0] = g[i]; result.push_back(atoi(num)); } return result; }
void Instance::randomize(int num_words, int superstring_length, float avg_common_part_percentage){ clear(); Word superstring; superstring_length_ = superstring_length; superstring.resize(superstring_length); for(int i = 0; i < superstring_length; i++){ superstring[i] = random_nucleotide(); } std::vector< std::pair<Word, int> > temp_words; temp_words.resize(num_words); for(int i = 0; i < num_words; i++){ temp_words[i].second = i; } int basic_word_length = superstring_length/num_words; int random_scope = int(0.25 * float(basic_word_length) * avg_common_part_percentage); int sideword_length = int(float(basic_word_length) * (1.0 + (avg_common_part_percentage)/2.0)); int midword_length = int(float(basic_word_length) * (1.0 + avg_common_part_percentage)); temp_words[0].first.resize(sideword_length + randint(-random_scope, random_scope+1)); for(unsigned i = 0; i < temp_words[0].first.size(); i++) { temp_words[0].first[i] = superstring[i]; } temp_words[num_words-1].first.resize(sideword_length + randint(-random_scope, random_scope+1)); for(int n = temp_words[num_words-1].first.size(), i = 0; i < n; i++) { temp_words[num_words-1].first[i] = superstring[superstring_length - n + i]; } for(int j = 1; j < num_words-1; j++){ int n = midword_length + randint(-random_scope, random_scope+1); temp_words[j].first.resize(n); int I = (n - basic_word_length)/2 + basic_word_length*j; if(I < 0){ n += I; temp_words[j].first.resize(n); I = 0; } if(I + n >= superstring_length){ I = superstring_length-n; } for(int i = 0; i < n; i++, I++){ temp_words[j].first[i] = superstring[I]; } } std::random_shuffle(temp_words.begin(), temp_words.end()); solution_.resize(num_words); for(int i = 0; i < num_words; i++){ add_word(temp_words[i].first); solution_[i] = temp_words[i].second; } }
Result Candidate::QueryMatchResult( const Word &query ) const { // Check if the query is a subsequence of the candidate and return a result // accordingly. This is done by simultaneously going through the characters of // the query and the candidate. If both characters match, we move to the next // character in the query and the candidate. Otherwise, we only move to the // next character in the candidate. The matching is a combination of smart // base matching and smart case matching. If there is no character left in the // query, the query is not a subsequence and we return an empty result. If // there is no character left in the candidate, the query is a subsequence and // we return a result with the query, the candidate, the sum of indexes of the // candidate where characters matched, and a boolean that is true if the query // is a prefix of the candidate. if ( query.IsEmpty() ) { return Result( this, &query, 0, false ); } if ( Length() < query.Length() ) { return Result(); } size_t query_index = 0; size_t candidate_index = 0; size_t index_sum = 0; const CharacterSequence &query_characters = query.Characters(); const CharacterSequence &candidate_characters = Characters(); auto query_character_pos = query_characters.begin(); auto candidate_character_pos = candidate_characters.begin(); for ( ; candidate_character_pos != candidate_characters.end(); ++candidate_character_pos, ++candidate_index ) { const auto &candidate_character = *candidate_character_pos; const auto &query_character = *query_character_pos; if ( query_character->MatchesSmart( *candidate_character ) ) { index_sum += candidate_index; ++query_character_pos; if ( query_character_pos == query_characters.end() ) { return Result( this, &query, index_sum, candidate_index == query_index ); } ++query_index; } } return Result(); }