コード例 #1
0
  @Test
  public void testOutsideTollTime() {
    Config config = matsimTestUtils.loadConfig(null);
    MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config);
    Fixture.createNetwork2(scenario);

    // a basic toll where only the morning hours are tolled
    RoadPricingSchemeImpl toll = new RoadPricingSchemeImpl();
    toll.setType("area");
    toll.addLink(Id.createLinkId("5"));
    toll.addLink(Id.createLinkId("11"));
    toll.addCost(8 * 3600, 10 * 3600, 1.0); // high costs!

    Fixture.createPopulation2(scenario);
    Population population = scenario.getPopulation();

    runOnAll(testee(scenario, toll), population);
    Id id1 = Id.createPersonId("1");
    LegImpl leg1 = getLeg1(population, id1);
    LegImpl leg2 = getLeg3(population, id1);

    Fixture.compareRoutes(
        "2 5 6",
        (NetworkRoute)
            leg1
                .getRoute()); // agent should take shortest route, as tolls are not active at that
                              // time
    Fixture.compareRoutes("8 11 12", (NetworkRoute) leg2.getRoute());
  }
コード例 #2
0
  /** Tests a few cases where the router can decide if it is better to pay the toll or not. */
  @Test
  public void testBestAlternatives() {
    Config config = matsimTestUtils.loadConfig(null);
    MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config);
    Fixture.createNetwork2(scenario);

    // a basic toll where only the morning hours are tolled
    RoadPricingSchemeImpl toll = new RoadPricingSchemeImpl();
    toll.setType("area");
    toll.addLink(Id.createLinkId("5"));
    toll.addLink(Id.createLinkId("11"));
    Cost morningCost = toll.addCost(6 * 3600, 10 * 3600, 0.12);
    /* Start with a rather low toll. The toll is also so low, because we only
     * have small network with short links: the cost to travel across one link
     * is: 20s * (-6 EUR / h) = 20 * (-6) / 3600 = 0.03333
     */

    Fixture.createPopulation2(scenario);
    Population population = scenario.getPopulation();

    Id id1 = Id.createPersonId("1");

    // case 1: toll only in morning, it is cheaper to drive around
    runOnAll(testee(scenario, toll), population);
    Fixture.compareRoutes("2 3 4 6", (NetworkRoute) getLeg1(population, id1).getRoute());
    Fixture.compareRoutes("8 11 12", (NetworkRoute) getLeg3(population, id1).getRoute());

    // case 2: now add a toll in the afternoon too, so it is cheaper to pay the toll
    Cost afternoonCost = toll.addCost(14 * 3600, 18 * 3600, 0.12);
    runOnAll(testee(scenario, toll), population);
    Fixture.compareRoutes("2 5 6", (NetworkRoute) getLeg1(population, id1).getRoute());
    Fixture.compareRoutes("8 11 12", (NetworkRoute) getLeg3(population, id1).getRoute());

    // case 3: change the second leg to a non-car mode, than it should be the same as case 1
    String oldMode = getLeg3(population, id1).getMode();
    getLeg3(population, id1).setMode(TransportMode.pt);
    runOnAll(testee(scenario, toll), population);
    Fixture.compareRoutes("2 3 4 6", (NetworkRoute) getLeg1(population, id1).getRoute());
    // and change the mode back
    getLeg3(population, id1).setMode(oldMode);

    // case 4: now remove the costs and add them again, but with a higher amount
    toll.removeCost(morningCost);
    toll.removeCost(afternoonCost);
    toll.addCost(6 * 3600, 10 * 3600, 0.7);
    toll.addCost(14 * 3600, 18 * 3600, 0.7);
    // the agent should now decide to drive around
    runOnAll(testee(scenario, toll), population);
    Fixture.compareRoutes("2 3 4 6", (NetworkRoute) getLeg1(population, id1).getRoute());
  }
コード例 #3
0
  /**
   * Tests cases where the agent must pay the toll because one of its activities is on a tolled link
   */
  @Test
  public void testTolledActLink() {
    Config config = matsimTestUtils.loadConfig(null);
    MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config);
    Fixture.createNetwork2(scenario);

    // a basic toll where only the morning hours are tolled
    RoadPricingSchemeImpl toll = new RoadPricingSchemeImpl();
    toll.setType("area");
    Id.createLinkId("7");
    toll.addCost(6 * 3600, 10 * 3600, 0.06);

    Fixture.createPopulation2(scenario);
    Population population = scenario.getPopulation();

    runOnAll(testee(scenario, toll), population);
    Id id1 = Id.createPersonId("1");

    Fixture.compareRoutes(
        "2 5 6",
        (NetworkRoute) getLeg1(population, id1).getRoute()); // agent should take shortest route
    Fixture.compareRoutes("8 11 12", (NetworkRoute) getLeg3(population, id1).getRoute());
  }