bool __cdecl ExecuteSimulatedAnnealing(
			__int32 sessionId,
			IGenericStream* inStream,
			IGenericStream* outStream)
		{
			CS.Enter();
			CSessionDataCache::iterator i = sessionDataCache.find(sessionId);
			_ASSERTE(i != sessionDataCache.end());
			CS.Leave();

			TSessionData& sd = i->second;

			__int8 bDirectAccess = false;
			inStream->Read(&bDirectAccess, sizeof(bDirectAccess));


			//here we are not suppose to more than obne simulation in the same loc
			unsigned __int64 locNo = 0;
			inStream->Read(&locNo, sizeof(locNo));
			ASSERT(locNo < sd.m_modelVector.size());
			unsigned __int64 XSize = 0;
			inStream->Read(&XSize, sizeof(XSize));
			ASSERT(XSize < (long)100);

			vector<double> paramArray(XSize);
			for (size_t i = 0; i < XSize; i++)
				inStream->Read(&paramArray[i], sizeof(paramArray[i]));

			//LeaveCriticalSection(&CS);

			CStatisticXY stat;
			sd.m_modelVector[locNo]->GetFValue(paramArray, stat);

			//write outputStream
			outStream->Write(&sessionId, sizeof(sessionId));
			outStream->Write(&locNo, sizeof(locNo));
			outStream->Write(&stat, sizeof(stat));


			return true;
		}
Exemplo n.º 2
0
    JSFunction * _compileFunction( const char * raw , JSObject * assoc , const char *& gcName ) {
        if ( ! assoc )
            assoc = JS_GetGlobalObject( _context );

        while (isspace(*raw)) {
            raw++;
        }

        stringstream fname;
        fname << "cf_";
        static int fnum = 1;
        fname << "_" << fnum++ << "_";


        if ( ! hasFunctionIdentifier( raw ) ) {
            string s = raw;
            if ( isSimpleStatement( s ) ) {
                s = "return " + s;
            }
            gcName = "cf anon";
            fname << "anon";
            return JS_CompileFunction( _context , assoc , fname.str().c_str() , 0 , 0 , s.c_str() , strlen( s.c_str() ) , "nofile_a" , 0 );
        }

        string code = raw;

        size_t start = code.find( '(' );
        assert( start != string::npos );

        fname << "_f_" << trim( code.substr( 9 , start - 9 ) );

        code = code.substr( start + 1 );
        size_t end = code.find( ')' );
        assert( end != string::npos );

        string paramString = trim( code.substr( 0 , end ) );
        code = code.substr( end + 1 );

        vector<string> params;
        while ( paramString.size() ) {
            size_t c = paramString.find( ',' );
            if ( c == string::npos ) {
                params.push_back( paramString );
                break;
            }
            params.push_back( trim( paramString.substr( 0 , c ) ) );
            paramString = trim( paramString.substr( c + 1 ) );
            paramString = trim( paramString );
        }

        boost::scoped_array<const char *> paramArray (new const char*[params.size()]);
        for ( size_t i=0; i<params.size(); i++ )
            paramArray[i] = params[i].c_str();

        JSFunction * func = JS_CompileFunction( _context , assoc , fname.str().c_str() , params.size() , paramArray.get() , code.c_str() , strlen( code.c_str() ) , "nofile_b" , 0 );

        if ( ! func ) {
            cout << "compile failed for: " << raw << endl;
            return 0;
        }
        gcName = "cf normal";
        return func;
    }