Exemplo n.º 1
0
int Chromosome::parsedValue(){
	if (!_scoreNeedsUpdate){
		return _parsedValue;
	}
	
	bool expectsOperator = false;
	_parsedValue = 0;
	OperationType operation = ADD;
	
	for (size_t i = 0; i < CHROMOSOME_LENGTH; i++){
		if (expectsOperator){
			
			operation = determineOperatorType(_genes[i]);
			
			if (operation != NON_OPERATION){
				expectsOperator = false;
			}
			
		} else {
			int number = _genes[i] - '0';
			
			if (number < 0 || number > 9){
				continue;
			}
			
			applyOperation(operation, number);

			expectsOperator = true;
		}
	}
	
	return _parsedValue;
}
Exemplo n.º 2
0
		void blit(const ImageData &src, ImageData &dest)
		{
			if (src.format == dest.format)
			{
				copy(src, dest);
				return;
			}
			
			op_blit op;
			applyOperation(op, src, dest);
		}
Exemplo n.º 3
0
 	void blitPremultiply(const ImageData &src, ImageData &dest)
     {
         op_premultipliedAlpha op;
         applyOperation(op, src, dest);
     }
Exemplo n.º 4
0
    /* local.$oplog.main is of the form:
         { ts: ..., op: <optype>, ns: ..., o: <obj> , o2: <extraobj>, b: <boolflag> }
         ...
       see logOp() comments.

       @param alreadyLocked caller already put us in write lock if true
    */
    void ReplSource::sync_pullOpLog_applyOperation(BSONObj& op, bool alreadyLocked) {
        if( logLevel >= 6 ) // op.tostring is expensive so doing this check explicitly
            log(6) << "processing op: " << op << endl;

        if( op.getStringField("op")[0] == 'n' )
            return;

        char clientName[MaxDatabaseNameLen];
        const char *ns = op.getStringField("ns");
        nsToDatabase(ns, clientName);

        if ( *ns == '.' ) {
            problem() << "skipping bad op in oplog: " << op.toString() << endl;
            return;
        }
        else if ( *ns == 0 ) {
            /*if( op.getStringField("op")[0] != 'n' )*/ {
                problem() << "halting replication, bad op in oplog:\n  " << op.toString() << endl;
                replAllDead = "bad object in oplog";
                throw SyncException();
            }
            //ns = "local.system.x";
            //nsToDatabase(ns, clientName);
        }

        if ( !only.empty() && only != clientName )
            return;

        if( cmdLine.pretouch && !alreadyLocked/*doesn't make sense if in write lock already*/ ) {
            if( cmdLine.pretouch > 1 ) {
                /* note: this is bad - should be put in ReplSource.  but this is first test... */
                static int countdown;
                assert( countdown >= 0 );
                if( countdown > 0 ) {
                    countdown--; // was pretouched on a prev pass
                }
                else {
                    const int m = 4;
                    if( tp.get() == 0 ) {
                        int nthr = min(8, cmdLine.pretouch);
                        nthr = max(nthr, 1);
                        tp.reset( new ThreadPool(nthr) );
                    }
                    vector<BSONObj> v;
                    oplogReader.peek(v, cmdLine.pretouch);
                    unsigned a = 0;
                    while( 1 ) {
                        if( a >= v.size() ) break;
                        unsigned b = a + m - 1; // v[a..b]
                        if( b >= v.size() ) b = v.size() - 1;
                        tp->schedule(pretouchN, v, a, b);
                        DEV cout << "pretouch task: " << a << ".." << b << endl;
                        a += m;
                    }
                    // we do one too...
                    pretouchOperation(op);
                    tp->join();
                    countdown = v.size();
                }
            }
            else {
                pretouchOperation(op);
            }
        }

        scoped_ptr<writelock> lk( alreadyLocked ? 0 : new writelock() );

        if ( replAllDead ) {
            // hmmm why is this check here and not at top of this function? does it get set between top and here?
            log() << "replAllDead, throwing SyncException: " << replAllDead << endl;
            throw SyncException();
        }

        Client::Context ctx( ns );
        ctx.getClient()->curop()->reset();

        bool empty = ctx.db()->isEmpty();
        bool incompleteClone = incompleteCloneDbs.count( clientName ) != 0;

        if( logLevel >= 6 )
            log(6) << "ns: " << ns << ", justCreated: " << ctx.justCreated() << ", empty: " << empty << ", incompleteClone: " << incompleteClone << endl;

        // always apply admin command command
        // this is a bit hacky -- the semantics of replication/commands aren't well specified
        if ( strcmp( clientName, "admin" ) == 0 && *op.getStringField( "op" ) == 'c' ) {
            applyOperation( op );
            return;
        }

        if ( ctx.justCreated() || empty || incompleteClone ) {
            // we must add to incomplete list now that setClient has been called
            incompleteCloneDbs.insert( clientName );
            if ( nClonedThisPass ) {
                /* we only clone one database per pass, even if a lot need done.  This helps us
                 avoid overflowing the master's transaction log by doing too much work before going
                 back to read more transactions. (Imagine a scenario of slave startup where we try to
                 clone 100 databases in one pass.)
                 */
                addDbNextPass.insert( clientName );
            }
            else {
                if ( incompleteClone ) {
                    log() << "An earlier initial clone of '" << clientName << "' did not complete, now resyncing." << endl;
                }
                save();
                Client::Context ctx(ns);
                nClonedThisPass++;
                resync(ctx.db()->name);
                addDbNextPass.erase(clientName);
                incompleteCloneDbs.erase( clientName );
            }
            save();
        }
        else {
            applyOperation( op );
            addDbNextPass.erase( clientName );
        }
    }
Exemplo n.º 5
0
/*
This function initializes the IFSOperationViewer and gets the inherited main window ready.
*/
IFSOperationViewer::IFSOperationViewer()
{
loadedIFSImage = NULL;
setupUi(this);

//Setup IFSImageLabels
leftImageLabel = new IFSImageLabel(imageFrame);
leftImageLabel->setObjectName(QString::fromUtf8("leftImageLabel"));
leftImageLabel->setScaledContents(false);
leftImageLabel->setAlignment(Qt::AlignCenter);

horizontalLayout_2->addWidget(leftImageLabel);

rightImageLabel = new IFSImageLabel(imageFrame);
rightImageLabel->setObjectName(QString::fromUtf8("rightImageLabel"));
rightImageLabel->setAlignment(Qt::AlignCenter);

horizontalLayout_2->addWidget(rightImageLabel);

//Set the slider for 3D images invisible until it is needed
threeDFramePositionLabel->setHidden(true);
threeDFramePositionSlider->setHidden(true);





//Initialize the file open action
action_Open->setShortcut(QKeySequence::Open);
action_Open->setStatusTip(tr("Load a IFS image for processing and viewing"));

//Initialize the save action
action_Save->setShortcut(QKeySequence::Save);
action_Save->setStatusTip(tr("Save the result of processing"));

//Connect the image labels to the values for the position
connect(leftImageLabel, SIGNAL(imageCursorRow(int)), rowPositionLabel, SLOT(setNum(int)));
connect(rightImageLabel, SIGNAL(imageCursorRow(int)), rowPositionLabel, SLOT(setNum(int)));

connect(leftImageLabel, SIGNAL(imageCursorColumn(int)), columnPositionLabel, SLOT(setNum(int)));
connect(rightImageLabel, SIGNAL(imageCursorColumn(int)), columnPositionLabel, SLOT(setNum(int)));

connect(leftImageLabel, SIGNAL(imageCursorValue(double)), imageValueLabel, SLOT(setNum(double)));
connect(rightImageLabel, SIGNAL(imageCursorValue(double)), imageValueLabel, SLOT(setNum(double)));

//Add action signals
connect(action_Open, SIGNAL(triggered()), this, SLOT(openFile()));
connect(action_Save, SIGNAL(triggered()), this, SLOT(saveFile()));

//Connect buttons
connect(applyButton, SIGNAL(clicked()), this, SLOT(applyOperation()));
connect(swapButton, SIGNAL(clicked()), this, SLOT(swap()));

//Connect slider
connect(threeDFramePositionSlider, SIGNAL(valueChanged(int)), this, SLOT(setFrame(int)));
connect(threeDFramePositionSlider, SIGNAL(valueChanged(int)), threeDFramePositionLabel, SLOT(setNum(int)));

//Set up function details and the function list
populateFunctionDetailsAndList();

//Connect list to parameters
connect(operationListBox, SIGNAL(currentTextChanged(const QString &)), this, SLOT(setupParameterWidgets(const QString&)));

//Set the function list to the first item
if(operationListBox->count() > 0)
{
operationListBox->setCurrentRow(0);
}

}