void FranchiseHq::resetTableImages(std::vector<TableImage*>& tableImages) { for (std::vector<TableImage*>::iterator t=tableImages.begin(); t != tableImages.end(); t++) { MenuItem* m = findMenuItemIndexed( (*t)->getIndexOfAssignedMenuItem() ); if ( m == NULL ) Msg::error("Problem in resetTableImages"); m->addTableImage(*t); } }
void FranchiseHq::initializeFranchiseHq(std::vector<MenuItemInfo*>& mi, std::vector<TableInfo*>& ti, std::vector<double>& si) { // add the menu items to the franchise hq image int i = 0; for (std::vector<MenuItemInfo*>::iterator it=mi.begin(); it != mi.end(); it++) { // set the menu items int idx = (*it)->getIndex(); double stickSize = si[i++]; long int parmSeed = (*it)->getInitialParameterSeed(); MenuItem* m = new MenuItem(ranPtr, modelPtr, settingsPtr, parmType, taxonNames, parmSeed); m->setIndex(idx); m->setStickLength(stickSize); availableMenuItemIndices.erase(idx); menuItems.insert( m ); } // set the tables std::set<int> restIds; TableImageFactory& tif = TableImageFactory::tableImageFactoryInstance(); for (std::vector<TableInfo*>::iterator it=ti.begin(); it != ti.end(); it++) { int rIdx = (*it)->getRestaurantIndex(); int tIdx = (*it)->getTableIndex(); int mIdx = (*it)->getMenuItemIndex(); restIds.insert(rIdx); TableImage* ti = tif.getTableImage(); ti->setRestaurantIndex( rIdx ); ti->setTableIndex( tIdx ); MenuItem* m = findMenuItemIndexed( mIdx ); if (m == NULL) Msg::error("Cannot find menu item in Franchise Headquarters Image"); m->addTableImage(ti); } numRestaurants = restIds.size(); // make certain that the tables in the restaurants reflect the seating of their images in the head quarters setTableMenuAssignments(); }
void FranchiseHq::initializeFranchiseHq(std::vector<TableImage*>& tableImages) { // count the number of restaurants std::set<int> restIds; for (int i=0; i<tableImages.size(); i++) { TableImage* t = tableImages[i]; restIds.insert( t->getRestaurantIndex() ); } numRestaurants = restIds.size(); if (parmTreatment == PARM_RV) { // initialize franchise headquarters using DPP // i. initialze the menu items that have restaurant tables assigned for (int i=0; i<tableImages.size(); i++) { //std::cout << "receiveBuf[" << i << "] = " << receiveBuf[i] << std::endl; TableImage* t = tableImages[i]; double probNew = menuAlpha / (i + menuAlpha); if (ranPtr->uniformRv() < probNew) { // assign table to a new menu item MenuItem* m = addMenuItem(); m->addTableImage(t); } else { // assign table to a pre-existing menu item MenuItem* m = pickMenuItemAtRandom(ranPtr); if (m == NULL) Msg::error("Problem initializing program"); m->addTableImage(t); } } // ii. instantiate the auxiliary menu items for (int i=0; i<numAuxiliaryMenuItems; i++) MenuItem* m = addMenuItem(); // iii. determine the stick breaking weight for each menu item setStickLengths(); } else if (parmTreatment == PARM_SAME) { // all of the restaurants share a single parameter MenuItem* m = addMenuItem(); for (int i=0; i<tableImages.size(); i++) { TableImage* t = tableImages[i]; if ( m->isTableAssignedToMenuItem( t->getRestaurantIndex(), t->getTableIndex() ) == true ) std::cout << "already found table " << t << " on MenuItem" << std::endl; m->addTableImage(t); if (m->getParmType() == PARM_TREE) { ParmTree* treePtr = dynamic_cast<ParmTree *>(m->getParameterPtr()); if ( treePtr == 0 ) Msg::error("Cannot find ParmTree"); } } } else { // each restaurant has a different parameter. Note that we assume that each // restaurant has a single table in it. for (int i=0; i<tableImages.size(); i++) { TableImage* t = tableImages[i]; MenuItem* m = addMenuItem(); m->addTableImage(t); if (m->getParmType() == PARM_TREE) { ParmTree* treePtr = dynamic_cast<ParmTree *>(m->getParameterPtr()); if ( treePtr == 0 ) Msg::error("Cannot find ParmTree"); } } } // make certain that the tables in the restaurants reflect the seating of their images in the head quarters setTableMenuAssignments(); }