private StrategySettings getStrategySettings(
      final Id<StrategySettings> index, final boolean createIfMissing) {
    StrategySettings settings = null;

    // should be in a map, but it is difficult to keep consistency with the
    // delegate...
    for (StrategySettings s : getStrategySettings()) {
      if (!s.getId().equals(index)) continue;
      if (settings != null) throw new IllegalStateException("several settings with id " + index);
      settings = s;
    }

    if (settings == null && createIfMissing) {
      settings = new StrategySettings(index);
      addStrategySettings(settings);
    }

    return settings;
  }
예제 #2
0
  public static void main(String[] args) {
    Config config = new Config();
    config.addCoreModules();
    Controler controler = new Controler(config);

    // controler settings
    controler
        .getConfig()
        .controler()
        .setOverwriteFileSetting(
            true
                ? OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles
                : OutputDirectoryHierarchy.OverwriteFileSetting.failIfDirectoryExists);
    controler.getConfig().controler().setCreateGraphs(false);

    // controlerConfigGroup
    ControlerConfigGroup ccg = controler.getConfig().controler();
    ccg.setOutputDirectory(outputPath);
    ccg.setFirstIteration(0);
    ccg.setLastIteration(0);
    ccg.setMobsim("qsim");
    Set set = new HashSet();
    set.add(EventsFileFormat.xml);
    ccg.setEventsFileFormats(set);
    //		ccg.setRunId("321");

    // qsimConfigGroup
    QSimConfigGroup qcg = controler.getConfig().qsim();
    qcg.setStartTime(0 * 3600.);
    qcg.setEndTime(30 * 3600.);
    qcg.setFlowCapFactor(0.1);
    qcg.setStorageCapFactor(0.3);
    //		qcg.setFlowCapFactor(0.01);
    //		qcg.setStorageCapFactor(0.03);
    qcg.setNumberOfThreads(1);
    qcg.setRemoveStuckVehicles(false);
    qcg.setStuckTime(10.0);

    // planCalcScoreConfigGroup
    PlanCalcScoreConfigGroup pcs = controler.getConfig().planCalcScore();
    Set<String> activities = new HashSet<String>();
    activities.add("unknown");
    activities.add("work");
    activities.add("pickup");
    activities.add("with adult");
    activities.add("other");
    activities.add("pvWork");
    activities.add("pvHome");
    activities.add("gvHome");
    activities.add("education");
    activities.add("business");
    activities.add("shopping");
    activities.add("private");
    activities.add("leisure");
    activities.add("sports");
    activities.add("home");
    activities.add("friends");

    for (String activity : activities) {
      ActivityParams params = new ActivityParams(activity);
      params.setTypicalDuration(30 * 3600);
      pcs.addActivityParams(params);
    }

    // strategy
    StrategyConfigGroup scg = controler.getConfig().strategy();
    StrategySettings strategySettings =
        new StrategySettings(Id.create("1", StrategySettings.class));
    strategySettings.setStrategyName("ChangeExpBeta");
    strategySettings.setWeight(1.0);
    scg.addStrategySettings(strategySettings);

    // network
    NetworkConfigGroup ncg = controler.getConfig().network();
    ncg.setInputFile(networkFile);

    // plans
    PlansConfigGroup pcg = controler.getConfig().plans();
    pcg.setInputFile(plansFile);

    // define emission tool input files

    EmissionsConfigGroup ecg = new EmissionsConfigGroup();
    controler.getConfig().addModule(ecg);
    ecg.setEmissionRoadTypeMappingFile(roadTypeMappingFile);
    ecg.setEmissionVehicleFile(emissionVehicleFile);

    ecg.setAverageWarmEmissionFactorsFile(averageFleetWarmEmissionFactorsFile);
    ecg.setAverageColdEmissionFactorsFile(averageFleetColdEmissionFactorsFile);

    ecg.setUsingDetailedEmissionCalculation(isUsingDetailedEmissionCalculation);
    ecg.setDetailedWarmEmissionFactorsFile(detailedWarmEmissionFactorsFile);
    ecg.setDetailedColdEmissionFactorsFile(detailedColdEmissionFactorsFile);

    // TODO: the following does not work yet. Need to force controler to always write events in the
    // last iteration.
    VspExperimentalConfigGroup vcg = controler.getConfig().vspExperimental();
    vcg.setWritingOutputEvents(false);

    controler.addControlerListener(new EmissionControlerListener());
    controler.run();
  }