本文整理汇总了C++中WordList::sumWordsLengthWithRepeats方法的典型用法代码示例。如果您正苦于以下问题:C++ WordList::sumWordsLengthWithRepeats方法的具体用法?C++ WordList::sumWordsLengthWithRepeats怎么用?C++ WordList::sumWordsLengthWithRepeats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WordList
的用法示例。
在下文中一共展示了WordList::sumWordsLengthWithRepeats方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: score
/**
* Calculate score of a given UYiV. The score is based on the formulas written in the inform.
* @param uyv
* @return score
*/
double Dencoder::score(shared_ptr<UYiV> uyv) const
{
if (uyv == NULL) return -1;
WordList* y = uyv->getYList();
//if the yList is NULL return score 0
assert(y != NULL);
if (y == NULL) return 0;
// if (y->getSize() == 0) return -1;
int p, q, k, l, pipes, I, encoding, total;
p = uyv->getWordsPosPairs()->size();
//This is the complete encoding... And I just to count the encoding of the new uyv...
encoding = 0;
q = y->getWordVec().size();
k = uyv->getU()->getSize();
l = uyv->getV()->getSize();
pipes = (q-1) ;
I = 1;
// the terms with the + are our gains, the - our penalties
// total = - getProdElectionSize() + p*k + p*l + y->sumWordsLengthWithoutRepeats() - y->sumWordsLengthWithRepeats() - p - 1 - k - l - 1 - 1 - (q - 1);
total = p*k + p*l + y->sumWordsLengthWithRepeats() -
y->sumWordsLengthWithoutRepeats() -
encoding -
p - 1 - k - l - 1 - I - pipes ;
assert(y->sumWordsLengthWithRepeats()>=y->sumWordsLengthWithoutRepeats());
return total;
}
示例2: replaceNonTerminal
/**
* replace the given shield with a NonTerminal in the Sequence
* @param uyv the yield to be replaced
* @param nonTerminal
*/
void Dencoder::replaceNonTerminal(shared_ptr<UYiV> uyv, int nonTerminal)
{
int I = nonTerminal-1;
vector<int> delimiterPos;
shared_ptr<Word> u = uyv->getU();
shared_ptr<Word> v = uyv->getV();
// int uSize = u->getSize();
int vSize = v->getSize();
int uPos = -1;
int vPos = -1;
int yieldLength = -1;
int diff = 0;
//I'm gonna use this just to know which y i'm adding and its position.
WordList* y = uyv->getYList();
list< shared_ptr<Word> > * wordList = y->getWordList();
list< shared_ptr<Word> >::iterator yIt = wordList->begin();
int p, k, l, total;
p = uyv->getWordsPosPairs()->size();
k = uyv->getU()->getSize();
l = uyv->getV()->getSize();
// if(opt == 0)
// total = getSeq()->getSize() - (p*k + p*l + y->sumWordsLengthWithRepeats() - p);
// else
total = getSeq()->getSize() - (p*k + p*l + y->sumWordsLengthWithRepeats() - p) ;
int * newSeq = new int[total];
shared_ptr<Sequence> oldSequence = getSeq();
int realSize = oldSequence->getSize();
int* oldSeq = oldSequence->getIntSequence();
list<std::pair<int, int> > * wordsPosPairs = uyv->getWordsPosPairs();
list<std::pair<int,int> >::iterator posIt = wordsPosPairs->begin();
int lastEncode = -2;
assert(lastEncode!=-15);
int yWordPos;
//Rewrite
for(int i = 0; i < realSize; i++)
{
assert(i<oldSequence->getSize());
assert(i-diff<total);
if (posIt!=wordsPosPairs->end() && i == (*posIt).first)
{
uPos = (*posIt).first;
vPos = (*posIt).second;
//add which production option I chose here
yWordPos = y->wordPos(*yIt);
prodElectionOrder_[I].push(yWordPos);
totalElectionSize_++;
// Changes for the new encode:
++yIt;
yieldLength = vPos + vSize - uPos;
newSeq[i - diff] = nonTerminal;
diff += yieldLength-1;
i += yieldLength-1;
//increase pos iterator
posIt++;
}
else
{
if(oldSeq[i] == 1)
{
delimiterPos.push_back(i-diff);
}
newSeq[i-diff] = oldSeq[i];
}
}
//Create Productions:
list<shared_ptr<Production> >* lp;
lp = rebuildGrammar(newSeq, delimiterPos, total);
delete[] newSeq;
grammar_ = make_shared<Grammar>(lp);
//.........这里部分代码省略.........