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(); }
//=========================================================================== //=========================================================================== //=========================================================================== //=========================================================================== void AddNewFileToMainMenu(TPopupMenu *PopupMenu, AnsiString FileName, TNotifyEvent NotifyEvent) { TRegistry *Reg = new TRegistry; bool FirstInput = false; bool FileExist = false; int Counter = 0; int posFileNameInMenu = -1; AnsiString appName = ExtractFileName(Application->ExeName); appName.SetLength(appName.Length() - 4); try { Reg->RootKey = HKEY_LOCAL_MACHINE; /// ---- Находитться в Uses Windows Reg->OpenKey("Software\\Digital Systems & Technologies\\" + appName, true); //create a new key >> .ext //------------------- if (FileName == "Load") { for ( int i = 0; i < CountFileName; i++){ FileNameStackArray[i] = ""; FileNameStackArray[i] = Reg->ReadString("FileName"+IntToStr(i+1)); if (FileNameStackArray[i] != "") { Counter = Counter + 1; addMenuItem (Counter, PopupMenu, "&"+IntToStr(Counter) + ". " + GetShortFileName(FileNameStackArray[i]), NotifyEvent); FirstInput = true; } } if (FirstInput) addMenuItem (Counter + 1,PopupMenu,"-", NULL); } else { // --- Проверка на повтор файла ----------- for ( int i = 0; i < CountFileName; i++) if (FileName == FileNameStackArray[i]) { FileExist = true; FileNameStackArray[i] = ""; posFileNameInMenu = i; } // -------- Если файл уже существует то удаляем его из списка, сортируем список if (FileExist) { for ( int i = posFileNameInMenu; i < CountFileName - 1; i++ ) { FileNameStackArray[i] = FileNameStackArray[i+1]; } FileNameStackArray[CountFileName - 1] = ""; } // ----- Добавляем в "Стек" --------- for ( int i = CountFileName - 1; i > 0; i--) if (FileNameStackArray[i-1].data() != NULL) FileNameStackArray[i] = FileNameStackArray[i-1]; FileNameStackArray[0] = FileName; // ---- Удаляю все файлы с менюхи --------- for ( int i = PopupMenu->Items->Count-1; i >= 0; i--) if (PopupMenu->Items->Items[i]->Name[1] == 'F') delete PopupMenu->Items->Items[i]; // ---- Добавляю новые файлы в менюху ------ Counter = 0; for ( int i = 0; i < CountFileName - 1; i++ ) { if (FileNameStackArray[i] != "") { Counter = Counter + 1; addMenuItem (Counter, PopupMenu, "&" + IntToStr(Counter) + ". " + GetShortFileName(FileNameStackArray[i]), NotifyEvent); } } // ---- Добавляю черту ------ addMenuItem (Counter + 1,PopupMenu,"-", NULL); } // ---- Записываю в Реестр ------- for ( int i = 0; i < CountFileName; i++) Reg->WriteString("FileName" + IntToStr(i+1), FileNameStackArray[i]); //------------------- Reg->CloseKey(); } __finally { delete Reg; } }