void MOGA::mutation( individual & ind ) const { int c, f; int p = std::rand() % num_bits_; index_to_cust_fac( p, c, f ); // Retrieve corresponding customer and facility for index p. // Partial evaluation if ( ind.chr[p] ) unassign( ind, c, f ); // Subtract costs else assign( ind, c, f ); // Add costs }
static void backtrack (void) { int lit; assert (decision); while (top_of_trail > decision) { lit = *--top_of_trail; unassign (lit); if (top_of_trail < next_to_propagate) inc (-lit); } decision = 0; next_to_propagate = top_of_trail; }
/****************************************************************************** * * szFName: c_break * Synopsis: void cbreak(void); * * Description: Control Break interrupt handler * *****************************************************************************/ void c_break(int c) { unsigned int iTemp; #ifndef _WINDOWS if (fSwitches & LOG) unassign(); #endif chdir(curdir); _dos_setdrive(usFirstDisk, &iTemp); if (chdir(szOriginalPath)) DisplayMessage(IDS_CANTCHANGEDIRECTORY, szOriginalPath); exit(3); }
/** * The /bs assign command. * @param u The user who issued the command * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. **/ int do_assign(User * u) { char *chan = strtok(NULL, " "); char *nick = strtok(NULL, " "); BotInfo *bi; ChannelInfo *ci; if (readonly) notice_lang(s_BotServ, u, BOT_ASSIGN_READONLY); else if (!chan || !nick) syntax_error(s_BotServ, u, "ASSIGN", BOT_ASSIGN_SYNTAX); else if (!(bi = findbot(nick))) notice_lang(s_BotServ, u, BOT_DOES_NOT_EXIST, nick); else if (bi->flags & BI_PRIVATE && !is_oper(u)) notice_lang(s_BotServ, u, PERMISSION_DENIED); else if (!(ci = cs_findchan(chan))) notice_lang(s_BotServ, u, CHAN_X_NOT_REGISTERED, chan); else if (ci->flags & CI_VERBOTEN) notice_lang(s_BotServ, u, CHAN_X_FORBIDDEN, chan); else if ((ci->bi) && (stricmp(ci->bi->nick, nick) == 0)) notice_lang(s_BotServ, u, BOT_ASSIGN_ALREADY, ci->bi->nick, chan); else if ((ci->botflags & BS_NOBOT) || (!check_access(u, ci, CA_ASSIGN) && !is_services_admin(u))) notice_lang(s_BotServ, u, PERMISSION_DENIED); else { if (ci->bi) unassign(u, ci); ci->bi = bi; bi->chancount++; if (ci->c && ci->c->usercount >= BSMinUsers) { bot_join(ci); } notice_lang(s_BotServ, u, BOT_ASSIGN_ASSIGNED, bi->nick, ci->name); send_event(EVENT_BOT_ASSIGN, 2, ci->name, bi->nick); } return MOD_CONT; }
//***************************************************************************** // // Main Program // //***************************************************************************** int main(int argc, const char **argv) { int iDrive = 0; unsigned int iNumDrives; PSTR pchTemp = NULL; #ifdef _DOS setvbuf(stdout, NULL, _IONBF, 0); #endif usFirstDisk = fSwitches = 0; DisplayMessage(IDS_EGOLINE, VERSION); ParseEnvironmentOptions("QF_OPT"); if (!(parms(&argc, (const PPSTR) argv + 1) - 1)) usage(TRUE); else argv++; #ifndef _WINDOWS signal(SIGINT, c_break); // set ctrl-break handler #endif #if !defined(_WINDOWS) && !defined(__OS2__) && !defined(WIN32) _harderr(handler); // set hardware error handler #endif // get original drive and directory ... _dos_getdrive(&usFirstDisk); getcwd(szOriginalPath, sizeof(szOriginalPath)); _dos_setdrive(usFirstDisk, (unsigned int *) &iNumDrives); splitfilespec((char *) strupr((char *) *argv), szFileName, (unsigned int *) &iDrive); if (!isvalid(iDrive) || bError) // invalid drive specified. { BELL(); DisplayMessage(IDS_INVALIDDRIVE); exit(1); } if ((fSwitches & DELETEFILE) && (fSwitches & NOPROMPT)) if (!ShowNoPromptMessage(iDrive, szFileName)) c_break(0); if (fSwitches & ALLDRIVES) { for (iDrive = 1; iDrive <= floppies(); iDrive++) { if (isvalid(iDrive) && !bError) { _dos_setdrive(iDrive, &iNumDrives); walkdirs("\\", 0, filefind); } if (bError) bError = FALSE; } for (floppies() + 1; iDrive <= iNumDrives; iDrive++) { if (isvalid(iDrive) && !bError) { _dos_setdrive(iDrive, &iNumDrives); getcwd(curdir, sizeof(curdir)); // save current directory on walkdirs("\\", 0, filefind); // alternate drives chdir(curdir); } if (bError) bError = FALSE; } } else { _dos_setdrive(iDrive, &iNumDrives); getcwd(curdir, sizeof(curdir)); // save current directory on alternate drives if (fSwitches & FROM_CURDIR) // Only search current directory and subdirs walkdirs(szOriginalPath, 1, filefind); else walkdirs("\\", 0, filefind); chdir(curdir); } _dos_setdrive(usFirstDisk, &iNumDrives); chdir(szOriginalPath); // print totals if (!(fSwitches & NOFILEINFO)) { if (fSwitches & SUBDIRTOT) { if (ulDirs || ulTotal) { PSTR pchNumFiles = NULL; printf("\n ================ ===========\n"); pchTemp = LongToString(ulTotalFileSize, pchTemp, 11, LTS_PADLEFT); pchNumFiles = LongToString(ulTotal + ulDirs, NULL, 16, LTS_PADLEFT); printf (" %s %s total files/bytes in all directories\n", pchNumFiles, pchTemp); if (pchNumFiles) free(pchNumFiles); usLineCount += 3; } } if (ulDirs || ulTotal) { printf("\n"); if (ulDirs) { pchTemp = LongToString(ulDirs, pchTemp, 11, LTS_PADLEFT); printf(" %s directory(s) found.\n", pchTemp); } pchTemp = LongToString(ulTotal, pchTemp, 11, LTS_PADLEFT); printf(" %s file(s) found.\n", pchTemp); } else printf("\nNo files found.\n"); if ((fSwitches & DELETEFILE) && ulTotal) { pchTemp = LongToString((LONG) nDeleted, pchTemp, 11, LTS_PADLEFT); printf(" %s file(s) deleted.\n", pchTemp); } if (fSwitches & LOG) { unassign(); printf(" done."); } } // free the memory that MIGHT have been allocated by LongToString. if (pchTemp) free(pchTemp); return (0); }
InputSettingsWindow::InputSettingsWindow() { activeInput = 0; layout = new QVBoxLayout; layout->setMargin(Style::WindowMargin); layout->setSpacing(Style::WidgetSpacing); setLayout(layout); list = new QTreeWidget; list->setColumnCount(2); list->setAllColumnsShowFocus(true); list->setSortingEnabled(false); list->header()->hide(); list->header()->setResizeMode(QHeaderView::ResizeToContents); layout->addWidget(list); controlLayout = new QHBoxLayout; layout->addLayout(controlLayout); message = new QLabel; message->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); controlLayout->addWidget(message); optionButton = new QPushButton("Options"); controlLayout->addWidget(optionButton); optionMenu = new QMenu; optionButton->setMenu(optionMenu); optionAssignModifiers = new QbCheckAction("Assign Modifiers as Keys", 0); optionMenu->addAction(optionAssignModifiers); assignButton = new QPushButton("Assign"); controlLayout->addWidget(assignButton); unassignButton = new QPushButton("Unassign"); controlLayout->addWidget(unassignButton); connect(list, SIGNAL(itemSelectionChanged()), this, SLOT(synchronize())); connect(list, SIGNAL(itemActivated(QTreeWidgetItem*, int)), this, SLOT(assign())); connect(assignButton, SIGNAL(released()), this, SLOT(assign())); connect(unassignButton, SIGNAL(released()), this, SLOT(unassign())); connect(optionAssignModifiers, SIGNAL(triggered()), this, SLOT(toggleAssignModifiers())); //initialize list port1 = new QTreeWidgetItem(list); port1->setData(0, Qt::UserRole, QVariant(-1)); port1->setText(0, "Controller Port 1"); port2 = new QTreeWidgetItem(list); port2->setData(0, Qt::UserRole, QVariant(-1)); port2->setText(0, "Controller Port 2"); userInterface = new QTreeWidgetItem(list); userInterface->setData(0, Qt::UserRole, QVariant(-1)); userInterface->setText(0, "User Interface"); for(unsigned i = 0; i < mapper().size(); i++) { InputGroup &group = *(mapper()[i]); QTreeWidgetItem *grandparent = 0; if(group.category == InputCategory::Port1) { grandparent = port1; } if(group.category == InputCategory::Port2) { grandparent = port2; } if(group.category == InputCategory::UserInterface) { grandparent = userInterface; } if(!grandparent) continue; QTreeWidgetItem *parent = new QTreeWidgetItem(grandparent); parent->setData(0, Qt::UserRole, QVariant(-1)); parent->setText(0, group.label); for(unsigned i = 0; i < group.size(); i++) { QTreeWidgetItem *child = new QTreeWidgetItem(parent); child->setData(0, Qt::UserRole, QVariant(inputTable.size())); inputTable.add(group[i]); } } updateList(); synchronize(); }
void MOGA::repair( individual & ind ) const { // Save assignments into an integer (indices) vector std::vector<unsigned int> assignment( cust_.size() ); // For each customer, test if there is one assignement alone or not. for ( unsigned int c = 0; c < cust_.size(); ++c ) { std::vector<int> list_assigned; // Retrieve assignments for customer c for ( unsigned int f = 0; f < fac_.size(); ++f ) { if ( ind.chr[ index_of(c, f) ] ) { list_assigned.push_back(f); } } // If there are more assignments, select one if ( list_assigned.size() > 1 ) { unsigned int r = std::rand() % list_assigned.size(); for ( unsigned int i = 0; i < list_assigned.size(); ++i ) { if ( i != r ) { int f = list_assigned[i]; unassign( ind, c, f ); // Subtract costs } } assignment[c] = list_assigned[r]; } // If no assignment, select one else if ( list_assigned.size() < 1 ) { int f = std::rand() % fac_.size(); assign( ind, c, f ); // Add costs assignment[c] = f; } // One assignment: OK but save it else { assignment[c] = list_assigned[0]; } } // Search for violated capacities if ( Argument::capacitated ) { // Find facilities for which capacity is violated for ( unsigned int f = 0; f < fac_.size(); ++f ) { for ( unsigned int c = 0; ind.q[f] < 0 && c < assignment.size(); ++c ) { // Find customers that cause capacity to be violated for ( unsigned int g = 0; assignment[c] == f && ind.q[f] < 0 && g < fac_.size(); ++g ) { // Try to assign the customer to an other facility if ( ind.q[g] >= data_.getCustomer(cust_[c]).getDemand() ) { unassign(ind, c, f); assign(ind, c, g); assignment[c] = g; } } } } } }
InputSettingsWindow::InputSettingsWindow() { activeInput = 0; activeGroup = 0; groupIndex = 0; activeMouse = 0; layout = new QVBoxLayout; layout->setMargin(Style::WindowMargin); layout->setSpacing(Style::WidgetSpacing); setLayout(layout); list = new QTreeWidget; list->setColumnCount(2); list->setAllColumnsShowFocus(true); list->setSortingEnabled(false); list->header()->hide(); list->header()->setSectionResizeMode(QHeaderView::ResizeToContents); layout->addWidget(list); controlLayout = new QHBoxLayout; layout->addLayout(controlLayout); message = new QLabel; message->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); controlLayout->addWidget(message); assignButton = new QPushButton("Assign"); controlLayout->addWidget(assignButton); unassignButton = new QPushButton("Unassign"); controlLayout->addWidget(unassignButton); buttonBox = new QLabel("Mouse Button"); buttonBox->setFrameStyle(QFrame::Panel | QFrame::Raised); buttonBox->hide(); controlLayout->addWidget(buttonBox); xAxisButton = new QPushButton("Mouse X-axis"); xAxisButton->hide(); controlLayout->addWidget(xAxisButton); yAxisButton = new QPushButton("Mouse Y-axis"); yAxisButton->hide(); controlLayout->addWidget(yAxisButton); stopButton = new QPushButton("Stop"); stopButton->hide(); controlLayout->addWidget(stopButton); connect(list, SIGNAL(itemSelectionChanged()), this, SLOT(synchronize())); connect(list, SIGNAL(itemActivated(QTreeWidgetItem*, int)), this, SLOT(activateAssign())); connect(assignButton, SIGNAL(released()), this, SLOT(assign())); connect(unassignButton, SIGNAL(released()), this, SLOT(unassign())); connect(xAxisButton, SIGNAL(released()), this, SLOT(xAxisAssign())); connect(yAxisButton, SIGNAL(released()), this, SLOT(yAxisAssign())); connect(stopButton, SIGNAL(released()), this, SLOT(stop())); //initialize list port1 = new QTreeWidgetItem(list); port1->setData(0, Qt::UserRole, QVariant(-1)); port1->setText(0, "Controller Port 1"); port2 = new QTreeWidgetItem(list); port2->setData(0, Qt::UserRole, QVariant(-1)); port2->setText(0, "Controller Port 2"); userInterface = new QTreeWidgetItem(list); userInterface->setData(0, Qt::UserRole, QVariant(-1)); userInterface->setText(0, "User Interface"); for(unsigned i = 0; i < mapper().size(); i++) { InputGroup &group = *(mapper()[i]); QTreeWidgetItem *grandparent = 0; if(group.category == InputCategory::Port1) { grandparent = port1; } if(group.category == InputCategory::Port2) { grandparent = port2; } if(group.category == InputCategory::UserInterface) { grandparent = userInterface; } if(!grandparent) continue; QTreeWidgetItem *parent = new QTreeWidgetItem(grandparent); parent->setData(0, Qt::UserRole, QVariant(-1)); parent->setText(0, group.label); for(unsigned i = 0; i < group.size(); i++) { QTreeWidgetItem *child = new QTreeWidgetItem(parent); child->setData(0, Qt::UserRole, QVariant(inputTable.size())); inputTable.append(group[i]); } } updateList(); synchronize(); }