@Override
 protected void checkParameterSet(final ConfigGroup set) {
   switch (set.getName()) {
     case StrategySettings.SET_NAME:
       if (!(set instanceof StrategySettings)) {
         throw new RuntimeException(set + " is not an instance of StrategySettings");
       }
       break;
     default:
       throw new IllegalArgumentException("unknown set type " + set.getName());
   }
 }
  @Override
  public void addParam(String param_name, String value) {
    // emulate previous behavior of reader (ignore null values at reading). td Apr'15
    if ("null".equalsIgnoreCase(value)) return;

    boolean validParameterName = false;

    for (KtiConfigParameter param : KtiConfigParameter.values()) {

      if (param.getParameterName().equals(param_name)) {
        param.setActualValue(value);
        super.addParam(param_name, value);
        validParameterName = true;
        continue;
      }
    }
    if (!validParameterName) {
      logger.warn(
          "Unknown parameter name in module "
              + HerbieConfigGroup.GROUP_NAME
              + ": \""
              + param_name
              + "\". It is ignored.");
    }
  }
 public HerbieConfigGroup() {
   super(GROUP_NAME);
   for (KtiConfigParameter param : KtiConfigParameter.values()) {
     param.setActualValue(param.getDefaultValue());
     super.addParam(param.getParameterName(), param.getDefaultValue());
   }
 }
 @Override
 protected void checkConsistency() {
   // to make available to tests
   super.checkConsistency();
 }
  /**
   * Tests that the travel times are correctly calculated during the simulation.
   *
   * @author mrieser
   */
  @Test
  public void testTravelTimeCalculation() {
    Config config = this.utils.loadConfig(null);
    Fixture f = new Fixture(config);

    /* Create 2 persons driving from link 1 to link 3, both starting at the
     * same time at 7am.  */
    Population population = f.scenario.getPopulation();
    PopulationFactory factory = population.getFactory();
    Person person1 = null;

    person1 = factory.createPerson(Id.create("1", Person.class));
    Plan plan1 = factory.createPlan();
    person1.addPlan(plan1);
    Activity a1 = factory.createActivityFromLinkId("h", f.link1.getId());
    a1.setEndTime(7.0 * 3600);
    plan1.addActivity(a1);
    Leg leg1 = factory.createLeg(TransportMode.car);
    plan1.addLeg(leg1);
    NetworkRoute route1 =
        ((PopulationFactoryImpl) f.scenario.getPopulation().getFactory())
            .createRoute(NetworkRoute.class, f.link1.getId(), f.link3.getId());
    leg1.setRoute(route1);
    ArrayList<Id<Link>> linkIds = new ArrayList<Id<Link>>();
    linkIds.add(f.link2.getId());
    route1.setLinkIds(f.link1.getId(), linkIds, f.link3.getId());
    plan1.addActivity(factory.createActivityFromLinkId("h", f.link3.getId()));
    population.addPerson(person1);

    Person person2 = factory.createPerson(Id.create("2", Person.class));
    Plan plan2 = factory.createPlan();
    person2.addPlan(plan2);
    Activity a2 = factory.createActivityFromLinkId("h", f.link1.getId());
    a2.setEndTime(7.0 * 3600);
    plan2.addActivity(a2);
    Leg leg2 = factory.createLeg(TransportMode.car);
    plan2.addLeg(leg2);
    NetworkRoute route2 =
        ((PopulationFactoryImpl) f.scenario.getPopulation().getFactory())
            .createRoute(NetworkRoute.class, f.link1.getId(), f.link3.getId());
    leg2.setRoute(route2);
    route2.setLinkIds(f.link1.getId(), linkIds, f.link3.getId());
    plan2.addActivity(factory.createActivityFromLinkId("h", f.link3.getId()));
    population.addPerson(person2);

    // Complete the configuration for our test case
    // - set scoring parameters
    ActivityParams actParams = new ActivityParams("h");
    actParams.setTypicalDuration(8 * 3600);
    actParams.setPriority(1.0);
    config.planCalcScore().addActivityParams(actParams);
    // - define iterations
    config.controler().setLastIteration(0);
    // - make sure we don't use threads, as they are not deterministic
    config.global().setNumberOfThreads(0);

    // Now run the simulation
    Controler controler = new Controler(f.scenario);
    controler.getConfig().controler().setCreateGraphs(false);
    controler.getConfig().controler().setWriteEventsInterval(0);
    controler.setDumpDataAtEnd(false);
    controler.run();

    // test if we got the right result
    // the actual result is 151sec, not 150, as each vehicle "loses" 1sec in the buffer
    assertEquals(
        "TravelTimeCalculator has wrong result",
        151.0,
        controler.getLinkTravelTimes().getLinkTravelTime(f.link2, 7 * 3600, null, null),
        0.0);

    // now test that the ReRoute-Strategy also knows about these travel times...
    config.controler().setLastIteration(1);
    ConfigGroup strategyParams = config.getModule("strategy");
    strategyParams.addParam("maxAgentPlanMemorySize", "4");
    strategyParams.addParam("ModuleProbability_1", "1.0");
    strategyParams.addParam("Module_1", "ReRoute");
    // Run the simulation again
    controler = new Controler(f.scenario);
    controler.getConfig().controler().setCreateGraphs(false);
    controler
        .getConfig()
        .controler()
        .setOverwriteFileSetting(
            OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles);
    controler.getConfig().controler().setWriteEventsInterval(0);
    controler.run();

    // test that the plans have the correct times
    assertEquals(
        "ReRoute seems to have wrong travel times.",
        151.0,
        ((Leg) (person1.getPlans().get(1).getPlanElements().get(1))).getTravelTime(),
        0.0);
  }
 public URL getInputFileURL(URL context) {
   return ConfigGroup.getInputFileURL(context, this.inputFile);
 }