Esempio n. 1
0
 private com.relteq.sirius.jaxb.Scenario restoreScenario(Scenarios db_scenario)
     throws SiriusException {
   if (null == db_scenario) return null;
   com.relteq.sirius.jaxb.Scenario scenario = factory.createScenario();
   scenario.setId(id2str(db_scenario.getId()));
   scenario.setName(db_scenario.getName());
   scenario.setDescription(db_scenario.getDescription());
   try {
     scenario.setSettings(restoreSettings(db_scenario));
     scenario.setNetworkList(restoreNetworkList(db_scenario));
     scenario.setSignalList(restoreSignalList(db_scenario.getSignalSets()));
     scenario.setSensorList(restoreSensorList(db_scenario.getSensorSets()));
     scenario.setInitialDensitySet(restoreInitialDensitySet(db_scenario.getInitialDensitySets()));
     scenario.setWeavingFactorSet(restoreWeavingFactorSet(db_scenario.getWeavingFactorSets()));
     scenario.setSplitRatioProfileSet(
         restoreSplitRatioProfileSet(db_scenario.getSplitRatioProfileSets()));
     scenario.setDownstreamBoundaryCapacityProfileSet(
         restoreDownstreamBoundaryCapacity(
             db_scenario.getDownstreamBoundaryCapacityProfileSets()));
     scenario.setEventSet(restoreEventSet(db_scenario.getEventSets()));
     scenario.setDemandProfileSet(restoreDemandProfileSet(db_scenario.getDemandProfileSets()));
     scenario.setControllerSet(restoreControllerSet(db_scenario.getControllerSets()));
     scenario.setFundamentalDiagramProfileSet(
         restoreFundamentalDiagramProfileSet(db_scenario.getFundamentalDiagramProfileSets()));
     scenario.setNetworkConnections(
         restoreNetworkConnections(db_scenario.getNetworkConnectionSets()));
     scenario.setDestinationNetworks(restoreDestinationNetworks(db_scenario));
     scenario.setRoutes(restoreRoutes(db_scenario));
   } catch (TorqueException exc) {
     throw new SiriusException(exc);
   }
   return scenario;
 }
Esempio n. 2
0
  @Override
  public void open(int run_id) throws SiriusException {
    success = false;
    if (1 != scenario.numEnsemble) logger.warn("scenario.numEnsembles != 1");
    if (null == db_scenario) throw new SiriusException("Scenario was not loaded from the database");

    logger.info("Initializing simulation run");
    Connection conn = null;
    try {
      conn = Transaction.begin();

      DataSources db_ds = new DataSources();
      db_ds.setId(DataSourcesPeer.nextId(DataSourcesPeer.ID, conn));
      db_ds.save(conn);

      Criteria crit = new Criteria();
      crit.add(ScenariosPeer.ID, db_scenario.getId());
      com.workingdogs.village.Value max_runnum =
          SimulationRunsPeer.maxColumnValue(SimulationRunsPeer.RUN_NUMBER, crit, conn);
      final long run_number = null == max_runnum ? 1 : max_runnum.asLong() + 1;
      logger.info("Run number: " + run_number);

      db_simulation_run = new com.relteq.sirius.om.SimulationRuns();
      db_simulation_run.setDataSources(db_ds);
      db_simulation_run.setScenarios(db_scenario);
      db_simulation_run.setRunNumber(run_number);
      db_simulation_run.setVersion(com.relteq.sirius.Version.get().getEngineVersion());
      db_simulation_run.setBuild("");
      db_simulation_run.setSimulationStartTime(BigDecimal.valueOf(scenario.getTimeStart()));
      db_simulation_run.setSimulationDuration(
          BigDecimal.valueOf(scenario.getTimeEnd() - scenario.getTimeStart()));
      db_simulation_run.setSimulationDt(BigDecimal.valueOf(scenario.getSimDtInSeconds()));
      db_simulation_run.setOutputDt(BigDecimal.valueOf(scenario.getOutputDt()));
      db_simulation_run.setExecutionStartTime(Calendar.getInstance().getTime());
      db_simulation_run.setStatus(-1);
      db_simulation_run.save(conn);

      Transaction.commit(conn);
      conn = null;
      success = true;
    } catch (TorqueException exc) {
      throw new SiriusException(exc);
    } catch (DataSetException exc) {
      throw new SiriusException(exc);
    } finally {
      if (null != conn) {
        Transaction.safeRollback(conn);
        db_simulation_run = null;
      }
    }
    ts = Calendar.getInstance();
    ts.set(Calendar.MILLISECOND, 0);
  }