static void find_trans_colors() { struct OverlayProp { long visual; long type; long value; long layer; }; trans_colors_init = TRUE; Display* appDisplay = QPaintDevice::x11AppDisplay(); QWidget* rootWin = QApplication::desktop(); if ( !rootWin ) return; // Should not happen Atom overlayVisualsAtom = XInternAtom( appDisplay, "SERVER_OVERLAY_VISUALS", True ); if ( overlayVisualsAtom == None ) return; // Server has no overlays Atom actualType; int actualFormat; ulong nItems; ulong bytesAfter; OverlayProp* overlayProps = 0; int res = XGetWindowProperty( appDisplay, rootWin->winId(), overlayVisualsAtom, 0, 10000, False, overlayVisualsAtom, &actualType, &actualFormat, &nItems, &bytesAfter, (uchar**)&overlayProps ); if ( res != Success || actualType != overlayVisualsAtom || actualFormat != 32 || nItems < 4 || !overlayProps ) return; // Error reading property int numProps = nItems / 4; trans_colors.resize( numProps ); int j = 0; for ( int i = 0; i < numProps; i++ ) { if ( overlayProps[i].type == 1 ) { trans_colors[j].vis = (VisualID)overlayProps[i].visual; trans_colors[j].color = (int)overlayProps[i].value; j++; } } XFree( overlayProps ); trans_colors.truncate( j ); }
/*! Returns all ids associated with the application CategoryGroup \a app and the passed in \a labels in that group. */ QArray<int> Categories::ids( const QString &app, const QStringList &labels) const { QArray<int> results; QStringList::ConstIterator it; int i; for ( i=0, it=labels.begin(); it!=labels.end(); i++, ++it ) { int value = id( app, *it ); if ( value != 0 ) { int tmp = results.size(); results.resize( tmp + 1 ); results[ tmp ] = value; } } return results; }
/** Get a vector of Rfcomm channels of the services having "uuid" in the class ID List*/ QArray<int> OTPeer::rfcommList( const OTUUID & uuid) { QArray<int> rfcommList; unsigned int channel; for( unsigned int i = 0; i < serviceList.count(); i ++ ) { if( serviceList[i]->hasClassID(uuid)) { if( serviceList[i]->rfcommChannel(channel) ) { rfcommList.resize( rfcommList.size()+1 ); rfcommList[rfcommList.size()-1] = channel; } } } return rfcommList; }
void ensureCatArray() { if ( mCat.count() > 0 || mCatList.count()==0 ) return; Categories cat( 0 ); cat.load( categoryFileName() ); mCat.resize( mCatList.count() ); int i; QStringList::ConstIterator it; for ( i = 0, it = mCatList.begin(); it != mCatList.end(); ++it, i++ ) { bool number; int id = (*it).toInt( &number ); if ( !number ) { id = cat.id( "Document View", *it ); if ( id == 0 ) id = cat.addCategory( "Document View", *it ); } mCat[i] = id; } }
void SimpleGA::evolve(Team *T) { Team *oldTeam, *newTeam, *delTeam; QArray<floatbot> botFitness; unsigned int teamSize, breed; int i; Bot *curbot; Bot *newbot1, *newbot2; oldTeam = T; newTeam = new Team; delTeam = new Team; teamSize = oldTeam->size(); botFitness.resize(teamSize); for (i=0; i< (int)teamSize; i++) { curbot = oldTeam->bot(i); botFitness[i].fit = curbot->fitnessFunction(); botFitness[i].bot = i; } botFitness.sort(); // reverse fitness array for (i=0; i<(int)(teamSize/2); i++) { floatbot temp; temp.fit = botFitness[i].fit; temp.bot = botFitness[i].bot; botFitness.at(i).fit = botFitness.at(teamSize-i-1).fit; botFitness.at(i).bot = botFitness.at(teamSize-i-1).bot; botFitness.at(teamSize-i-1).fit = temp.fit; botFitness.at(teamSize-i-1).bot = temp.bot; } // add the good bots to the new team breed = teamSize / 2; // number of bots to breed if ( (breed/2)*2 != breed ) breed--; // make sure its even for (i=0; i<(int)(teamSize - breed); i++) { // number of bots to throw out is the number bred, so keep the number not thrown out curbot = oldTeam->bot(botFitness[i].bot); newTeam->insertBot(curbot); } for (i=(teamSize - breed); i<(int)teamSize; i++) { // put bots to be deleted on a separate team curbot = oldTeam->bot(botFitness[i].bot); delTeam->insertBot(curbot); } while (oldTeam->size() > 0) { // remove bots from oldTeam curbot = oldTeam->removeBot(0); } while (delTeam->size() > 0) { // actually delete bots curbot = delTeam->removeBot(0); delete curbot; } // do the crossover of the best bots for (i=0; i<(int)breed; i+=2) { newbot1 = new Bot(oldTeam); newbot2 = new Bot(oldTeam); crossover(newTeam->bot(i), newTeam->bot(i+1), newbot1, newbot2); newTeam->insertBot(newbot1); newTeam->insertBot(newbot2); } // mutate a bot given the mutation rate for (i=0; i<(int)teamSize; i++) { double rnd = Random::randd(0,1); if (rnd < MutationRate) { curbot = newTeam->bot(i); curbot->mutateBot(); } } // copy bots back into old team while (newTeam->size() > 0) { curbot = newTeam->removeBot(0); oldTeam->insertBot(curbot); } oldTeam->generations(oldTeam->generations() + 1); delete delTeam; delete newTeam; }
void setCatArrayDirty() { mCat.resize(0); }