int
MSNet::simulate(SUMOTime start, SUMOTime stop) {
    // the simulation loop
    std::string quitMessage = "";
    myStep = start;
    do {
        if (myLogStepNumber) {
            preSimStepOutput();
        }
        simulationStep();
        if (myLogStepNumber) {
            postSimStepOutput();
        }
        MSNet::SimulationState state = simulationState(stop);
#ifndef NO_TRACI
        if (state!=SIMSTATE_RUNNING) {
            if (OptionsCont::getOptions().getInt("remote-port")!=0&&!traci::TraCIServer::wasClosed()) {
                state = SIMSTATE_RUNNING;
            }
        }
#endif
        if (state!=SIMSTATE_RUNNING) {
            quitMessage = "Simulation End: " + getStateMessage(state);
        }
    } while (quitMessage=="");
    WRITE_MESSAGE(quitMessage);
    // exit simulation loop
    closeSimulation(start);
    return 0;
}
Exemple #2
0
int
MSNet::simulate(SUMOTime start, SUMOTime stop) {
    // report the begin when wished
    WRITE_MESSAGE("Simulation started with time: " + time2string(start));
    // the simulation loop
    MSNet::SimulationState state = SIMSTATE_RUNNING;
    myStep = start;
    // preload the routes especially for TraCI
    loadRoutes();
#ifndef NO_TRACI
#ifdef HAVE_PYTHON
    if (OptionsCont::getOptions().isSet("python-script")) {
        traci::TraCIServer::runEmbedded(OptionsCont::getOptions().getString("python-script"));
        closeSimulation(start);
        WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
        WRITE_MESSAGE("Reason: Script ended");
        return 0;
    }
#endif
#endif
    while (state == SIMSTATE_RUNNING) {
        if (myLogStepNumber) {
            preSimStepOutput();
        }
        simulationStep();
        if (myLogStepNumber) {
            postSimStepOutput();
        }
        state = simulationState(stop);
#ifndef NO_TRACI
        if (state != SIMSTATE_RUNNING) {
            if (OptionsCont::getOptions().getInt("remote-port") != 0 && !traci::TraCIServer::wasClosed()) {
                state = SIMSTATE_RUNNING;
            }
        }
#endif
    }
    // report the end when wished
    WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
    WRITE_MESSAGE("Reason: " + getStateMessage(state));
    // exit simulation loop
    closeSimulation(start);
    return 0;
}
Exemple #3
0
int MSNet::simulate(SUMOTime start, SUMOTime stop)
{
  OptionsCont &oc = OptionsCont::getOptions();
  if(oc.getSimulationVerbosity()>1)
    std::cout<<"----> void MSNet::simulate(...)"<<std::endl;  
  //if((oc.getString("net-file").find("munchen"))||
  // (oc.getString("net-file").find("munich")))
  if(oc.getSafeBool("ger"))
    setCity("munchen");
  //else if(oc.getString("net-file").find("cambiano"))
  else if(oc.getSafeBool("ita"))
    setCity("cambiano");
  else
    setCity("unknown");
  // the simulation loop
  MSNet::SimulationState state = SIMSTATE_RUNNING;
  myStep = start;
#ifndef NO_TRACI
#ifdef HAVE_PYTHON
  if(OptionsCont::getOptions().isSet("python-script")) {
    traci::TraCIServer::runEmbedded(OptionsCont::getOptions().getString("python-script"));
    WRITE_MESSAGE("Simulation End: Script ended");
    closeSimulation(start);
    return 0;
  }
#endif
#endif
  // Initialize weather conditions
  if(oc.isSet("fiet"))
    setCurrentEnvTemp(oc.getFloat("fiet"));
  else
    setCurrentEnvTemp(5.3);
  if(oc.isSet("fieh"))
    setCurrentEnvHum(oc.getFloat("fieh"));
  else
    setCurrentEnvHum(67.8);
  while(state == SIMSTATE_RUNNING)
  {
    if(myLogStepNumber)
        preSimStepOutput();
    simulationStep();
    // FIXME Custom wait
    //for(int i=0;i++<0x00003fff;)for(int j=0;j++<0x00000fff;);
    if(oc.getSafeBool("rwc") || oc.getSafeBool("rlwc"))
      updateWeather();
    if(myLogStepNumber)
        postSimStepOutput();
    state = simulationState(stop);
#ifndef NO_TRACI
    if(state != SIMSTATE_RUNNING)
    {
      if(OptionsCont::getOptions().getInt("remote-port") != 0 && !traci::TraCIServer::wasClosed())
        state = SIMSTATE_RUNNING;
    }
#endif
  }
  WRITE_MESSAGE("Simulation End: " + getStateMessage(state));
  // exit simulation loop
  closeSimulation(start);
  return 0;
}