Exemplo n.º 1
0
Agents::SimulatorInterface* SimulatorDBEntry::getSimulator(
    size_t& agentCount, float& simTimeStep, size_t subSteps, float simDuration,
    const std::string& behaveFile, const std::string& sceneFile, const std::string& outFile,
    const std::string& scbVersion, bool verbose) {
  _sim = initSimulator(sceneFile, verbose);
  if (!_sim) {
    return 0x0;
  }
  // TODO: Remove time step from the simulator specification!
  float specTimeStep = _sim->getTimeStep();

  _fsm = initFSM(behaveFile, _sim, verbose);
  if (!_fsm) {
    return 0x0;
  }
  if (!finalize(_sim, _fsm)) {
    delete _sim;
    delete _fsm;
    return 0x0;
  }

  if (simTimeStep > 0.f) {
    if (verbose) {
      logger << Logger::INFO_MSG;
      logger << "Simulation time step set by command-line argument: ";
      logger << simTimeStep << ".";
    }
    _sim->setTimeStep(simTimeStep);
  } else {
    simTimeStep = specTimeStep;
    if (verbose) {
      logger << Logger::INFO_MSG << "Simulation time step set by specification file: ";
      logger << specTimeStep << ".";
    }
  }
  _sim->setSubSteps(subSteps);
  float effTimeStep = simTimeStep / (1.f + subSteps);
  logger << Logger::INFO_MSG << "For logical time step: " << simTimeStep << " and ";
  logger << subSteps << " sub step";
  if (subSteps != 1) {
    logger << "s";
  }
  logger << ", effective time step is: " << effTimeStep;

  _sim->setMaxDuration(simDuration);
  if (outFile != "") {
    _sim->setOutput(outFile, scbVersion);
  }
  agentCount = _sim->getNumAgents();
  return _sim;
}
Exemplo n.º 2
0
void MyWindow::runSimulator(){
    if (simulatorIsInitialized == 0){
        if(pipe(pfd) == -1)
            perror("pipe");

        communication_thread = new CommunicationThread(this);
        communication_thread->start();
        initSimulator();
        simulatorIsInitialized = 1;
        exit->setEnabled(false);
        runButton->setEnabled(false);
        isPaused = 0;
        if(!regularDelay)
           pauseButton->setEnabled(true);
        return;
    }
}
Exemplo n.º 3
0
int main(int argc, char** argv) {
  std::cout << std::endl;
  
  char* ref = NULL;

  // Important NOT invert (init requires argument to be parsed)
  parseArguments(argc,argv);
  initSimulator();

  
  size_t N = Options::opts.N;
  size_t m = Options::opts.m;
  size_t M = Options::opts.M;
  size_t Nbar = N - m + 1;
  double pe = Options::opts.pe; 
  std::cout << std::endl;
  
  std::cout << "\t\t+++++  Starting simulation +++++ \n\n";  
  std::cout << "* Reference generation... ";
  ref = new char[N];
  generateIIDGenome(N,ref);
  std::string s(ref);
  std::cout << "[OK]" << std::endl;

  std::cout << "* Read generation... ";
  std::priority_queue<Read> reads;
  generateOfflineReads(s, reads);
  std::cout << "[OK]" << std::endl;

  std::cout << "* Processing reads... ";

  Read r1 = reads.top();
  reads.pop();
  while(!reads.empty()) {
    Read r2 = reads.top();
    reads.pop();
    size_t s = m - (r2.j - r1.j);
    evaluateChainRelation(r1, r2, s);
    int dh = -1;
    if (s <= m) {
      dh = prefixSuffixHammingDistance(r2.r, r1.r, s);
    } else {
      addNonOverlapRecord(r2.j - r1.j - m);
    }
    r1 = r2;
  }

  std::cout << "[OK]" << std::endl;

  
  std::cout << "* Cleaning... ";
  delete[] ref;
  std::cout << "\n\n";
  //  printChainMatrix();
  //printNonOverlapDistribution();
  printFalsePositiveMatrix();
  clearSimulator();
  std::cout << "[OK]" << std::endl;

  
  std::cout << std::endl;
  return 0;
}
int main() {
    
    char *customData = getCustomRecordedGameData();

    initDrawString( w, h );
    
    initFrameDrawer( w, h, 60,
                     customData, false );
    
    delete [] customData;
    

    initSimulator();
    
    int port = 
        SettingsManager::getIntSetting( "simulatorServerPort", 5077 );

    char *password = 
        SettingsManager::getStringSetting( "simulatorServerPassword" );
    
    if( password == NULL ) {
        password = stringDuplicate( "secret" );
        }
    

    
    SocketServer server( port, 256 );

    char quit = false;
    
    while( !quit ) {
        printf( "Waiting for connection on port %d, password = '******'\n", 
                port, password );

        Socket *sock = server.acceptConnection();
        
        if( sock != NULL ) {
            printf( "Got connection\n" );

            char *request = readFullRequest( sock );
            
            if( request != NULL ) {

                char *response = NULL;

                if( strstr( request, "quit" ) == request ) {
                    // starts with quit
                
                    if( strstr( request, password ) != NULL ) {
                        quit = true;
                    
                        response = stringDuplicate( "OK" );
                        }
                    else {
                        response = stringDuplicate( "FAILED" );
                        }
                    }
                else if( strstr( request, "check_alive" ) == request ) {
                    response = stringDuplicate( "OK" );
                    }
                else if( strstr( request, "simulate_robbery" ) == request ) {
                    double startTime = Time::getCurrentTime();
                
                    response = simulateRobbery( request );
                    
                    double netTime = Time::getCurrentTime() - startTime;
                    printf( "Simulation took %f seconds\n", netTime );
                    }
                else {
                    response = stringDuplicate( "FAILED" );
                    }
            

                delete [] request;
            
                sock->send( (unsigned char *)response, strlen( response ), 
                            true, false );
            
                delete [] response;


                sock->send( (unsigned char *)"\n", strlen( "\n" ), 
                            true, false );


                sock->send( (unsigned char *)END_RESPONSE, 
                            strlen( END_RESPONSE ), 
                            true, false );


                sock->sendFlushBeforeClose( 3000 );
                }
            
            delete sock;
            }
        }
    
    delete [] password;
    
    freeSimulator();
    
    freeDrawString();
    freeFrameDrawer();
    }