本文整理汇总了C++中Patron::setTable方法的典型用法代码示例。如果您正苦于以下问题:C++ Patron::setTable方法的具体用法?C++ Patron::setTable怎么用?C++ Patron::setTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Patron
的用法示例。
在下文中一共展示了Patron::setTable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initializeTables
void Restaurant::initializeTables(void) {
if (assumingDpp == true)
{
// Dirichlet process prior model
for (int i=0; i<numPatrons; i++)
{
double probNewTable = concentrationParm / (i + concentrationParm);
double u = ranPtr->uniformRv();
bool successfullyAddedPatron = false;
if (u < probNewTable)
{
Table *tab = new Table(this, ranPtr, observationsPtr, observationsPtr->getNumUniqueAlleles(), lnFactorial);
tables.push_back( tab );
tab->addPatronToTable( patrons[i] );
patrons[i]->setTable(tab);
successfullyAddedPatron = true;
}
else
{
double sum = probNewTable;
for (vector<Table *>::iterator p=tables.begin(); p != tables.end(); p++)
{
sum += (double)(*p)->getNumPatrons() / (i + concentrationParm);
if (u < sum)
{
(*p)->addPatronToTable( patrons[i] );
patrons[i]->setTable( (*p) );
successfullyAddedPatron = true;
break;
}
}
}
if (successfullyAddedPatron == false)
{
Stmessage::error("Failed to add patron to table");
return;
}
}
}
else
{
// fixed number of tables
for (int i=0; i<modelPtr->getNumPopulations(); i++)
tables.push_back( new Table(this, ranPtr, observationsPtr, observationsPtr->getNumUniqueAlleles(), lnFactorial) );
MbVector<int> patronIndices(numPatrons);
for (int i=0; i<numPatrons; i++)
patronIndices[i] = i;
for (int i=0; i<tables.size(); i++)
{
int whichPatron = (int)(ranPtr->uniformRv()*(numPatrons-i));
Patron *p = patrons[ patronIndices[whichPatron] ];
tables[i]->addPatronToTable( p );
p->setTable(tables[i]);
int tempIdx = patronIndices[numPatrons-i-1];
patronIndices[numPatrons-i-1] = patronIndices[whichPatron];
patronIndices[whichPatron] = tempIdx;
}
for (int i=tables.size(); i<numPatrons; i++)
{
int whichPatron = (int)(ranPtr->uniformRv()*(numPatrons-i));
Patron *p = patrons[ patronIndices[whichPatron] ];
int whichTable = (int)(ranPtr->uniformRv()*tables.size());
tables[whichTable]->addPatronToTable( p );
p->setTable(tables[whichTable]);
int tempIdx = patronIndices[numPatrons-i-1];
patronIndices[numPatrons-i-1] = patronIndices[whichPatron];
patronIndices[whichPatron] = tempIdx;
}
}
}