Example #1
0
	Word BallSearch::findWord()
	{
		for (;;) {
			WordPair largest(pairs.top());
			Word result(largest.currentCombination);
			string oldName = result.name;
			findNames(result);			
			pairs.pop();
			largest.setCurrentIndex(largest.distanceIndex+1);
			pairs.push(largest);
			list<Word>::iterator it;
			for (it = words.begin(); it != words.end(); ++it)
				if (result.nameClass == it->nameClass)
					break;
			if (result.nameClass != "" && it == words.end()) {
				double sizeRatio = norm(result.matrix.c) / norm(words.front().matrix.c);
				//fprintf(stderr, "%s: sizeRatio = %f gPower = %d\n", result.name.c_str(), sizeRatio, gPower(result));
				if (sizeRatio < 1) {
					m_foundBigBall = true;
				}
				return result;
			}
			//fprintf(stderr, "rejecting %s^-1 *(%d,%d) %s = %s -> %s (%s)\n",
				//largest.firstWord->name.c_str(),
				//largest.distances[largest.distanceIndex-1].x,
				//largest.distances[largest.distanceIndex-1].y,
				//largest.secondWord->name.c_str(),
				//oldName.c_str(),
				//result.name.c_str(),
				//result.nameClass.c_str()
			//);
			//printf("duplicate; resorting\n");
		}
	}
Example #2
0
	void BallSearch::pushWord(Word word)
	{
		list<Word>::iterator it;
		// first, check to see if this word has already been pushed
		findNames(word);
		if (word.nameClass == "")
			return;
		for (it = words.begin(); it != words.end(); ++it)
			if (it->nameClass == word.nameClass)
				return;
		//printf("pushWord(%s) class=%s\n", word.name.c_str(), word.nameClass.c_str());
		words.push_back(word);
		Word* wp = &words.back();
		for (it = words.begin(); it != words.end(); ++it) {
			WordPair pair(&*it, wp, &params);
//			printf("pushWordPair(%s,%s)\n", pair.firstWord->name.c_str(), pair.secondWord->name.c_str());
			if (pair.distances.size() > 0)
				pairs.push(pair);
		}
	}
Example #3
0
	void BallSearch::pushWord(string word)
	{
		Word w;
		w.name = word;
		string::size_type pos;
		int x = 0;
		int y = 0;
		for (pos = 0; pos <= word.length(); ++pos) {
			int c = pos < word.length() ? word[pos] : -1;
			switch(c) {
				case 'm': --x; break;
				case 'M': ++x; break;
				case 'n': --y; break;
				case 'N': ++y; break;
				default: {
					if (x != 0 || y != 0) {
						w.matrix = w.matrix*constructT(params, x, y);
						x=y=0;
					}
					if (c == 'g') {
						w.matrix = w.matrix*g;
					} else if (c == 'G') {
						w.matrix = w.matrix*G;
					}
				}
			}
		}
		//printf("pushWord(%s): distance=%f\n", w.name.c_str(), 0.5 / norm(w.matrix.c));
		pushWord(w);
		Word wInv = inverse(w);
		findNames(wInv);
		pushWord(wInv);
		//fprintf(stderr, "pushed words %s(%s) and %s(%s)\n",
			//w.name.c_str(), w.nameClass.c_str(),
			//wInv.name.c_str(), wInv.nameClass.c_str());
	}
Example #4
0
std::vector<Path>
findNames(const Path &root) {
    return findNames(root, isExisting);
}