Exemple #1
0
  private void test1PersonStartingOnLane(boolean reduceCap) {
    fixture.create1PersonFromLink1Population();

    if (reduceCap) {
      fixture.sc.getConfig().qsim().setStartTime(3500.0);
      fixture.sc.getConfig().qsim().setEndTime(7200.0);
      LaneDefinitions20 lanes = fixture.sc.getLanes();
      Lane lane1 =
          lanes.getLanesToLinkAssignments().get(fixture.id1).getLanes().get(fixture.laneId1);
      lane1.setCapacityVehiclesPerHour(1800.0);
      Lane lane1ol =
          lanes
              .getLanesToLinkAssignments()
              .get(fixture.id1)
              .getLanes()
              .get(fixture.link1FirstLaneId);
      lane1ol.setCapacityVehiclesPerHour(1800.0);
    }

    EventsManager events = EventsUtils.createEventsManager();
    MixedLanesEventsHandler handler = new MixedLanesEventsHandler(this.fixture);
    events.addHandler(handler);
    QSim qsim = QSimUtils.createDefaultQSim(this.fixture.sc, events);
    qsim.run();
    Assert.assertNotNull(handler.lastAgentDepartureEvent);
    Assert.assertEquals(3600.0, handler.lastAgentDepartureEvent.getTime(), testUtils.EPSILON);

    Assert.assertNull(handler.lastLink1EnterEvent);

    Assert.assertNull(handler.lastLane1olEnterEvent);
    Assert.assertEquals(
        3600.0 + firstLinkOrLaneTT, handler.lastLane1olLeaveEvent.getTime(), testUtils.EPSILON);
    Assert.assertEquals(
        3600.0 + firstLinkOrLaneTT, handler.lastLane1EnterEvent.getTime(), testUtils.EPSILON);
    Assert.assertEquals(
        3600.0 + firstLinkOrLaneTT + laneTTlane1,
        handler.lastLane1LeaveEvent.getTime(),
        testUtils.EPSILON);

    Assert.assertNotNull(handler.lastLink2EnterEvent);
    Assert.assertEquals(
        this.fixture.pid1, handler.vehId2DriverId.get(handler.lastLink2EnterEvent.getVehicleId()));
    Assert.assertEquals(
        3600.0 + firstLinkOrLaneTT + laneTTlane1,
        handler.lastLink2EnterEvent.getTime(),
        testUtils.EPSILON);

    Assert.assertNull(handler.lastLink3EnterEvent);
  }
Exemple #2
0
  /**
   * Tests travel times in the same scenario as above but without lanes. Note, that they are
   * different in this example!
   *
   * @author thunig
   */
  @Test
  public void testLink2PersonsDriving() {
    log.info("starting testLink2PersonsDriving()");

    fixture.sc.getConfig().qsim().setUseLanes(false);

    fixture.create2PersonPopulation();
    EventsManager events = EventsUtils.createEventsManager();

    MixedLanesEventsHandler handler = new MixedLanesEventsHandler(fixture);
    events.addHandler(handler);

    QSim qsim = (QSim) QSimUtils.createDefaultQSim(fixture.sc, events);
    qsim.run();

    Assert.assertNotNull(handler.lastAgentDepartureEvent);
    Assert.assertEquals(3600.0, handler.lastAgentDepartureEvent.getTime(), testUtils.EPSILON);

    Assert.assertNotNull(handler.lastLink1EnterEvent);
    Assert.assertEquals(
        3600.0 + firstLinkOrLaneTT, handler.lastLink1EnterEvent.getTime(), testUtils.EPSILON);

    Assert.assertNotNull(handler.lastLink2EnterEvent);
    Assert.assertEquals(
        fixture.pid1, handler.vehId2DriverId.get(handler.lastLink2EnterEvent.getVehicleId()));
    Assert.assertEquals(
        3600.0 + firstLinkOrLaneTT + linkTTWithoutLanes,
        handler.lastLink2EnterEvent.getTime(),
        testUtils.EPSILON);

    Assert.assertNotNull(handler.lastLink3EnterEvent);
    Assert.assertEquals(
        fixture.pid2, handler.vehId2DriverId.get(handler.lastLink3EnterEvent.getVehicleId()));
    Assert.assertEquals(
        3600.0 + firstLinkOrLaneTT + linkTTWithoutLanes,
        handler.lastLink3EnterEvent.getTime(),
        testUtils.EPSILON);
  }
Exemple #3
0
  private void testMixedLane2PersonsDriving(boolean reduceCap) {
    fixture.create2PersonPopulation();

    // if no capacity is reduced the delay of both agents should be zero
    double delayOfAgent1 = 0;
    double delayOfAgent2 = 0;

    if (reduceCap) {
      // reduce capacity on lane 1
      LaneDefinitions20 lanes = fixture.sc.getLanes();
      Lane lane1 =
          lanes.getLanesToLinkAssignments().get(fixture.id1).getLanes().get(fixture.laneId1);
      lane1.setCapacityVehiclesPerHour(1800.0);

      // the delay of the second agent on lane 1 should be two seconds if
      // capacity is reduced to 1800 veh/h
      delayOfAgent2 = 2;
    }

    EventsManager events = EventsUtils.createEventsManager();

    MixedLanesEventsHandler handler = new MixedLanesEventsHandler(this.fixture);
    events.addHandler(handler);

    QSim qsim = (QSim) QSimUtils.createDefaultQSim(this.fixture.sc, events);
    qsim.run();

    Assert.assertNotNull(handler.lastAgentDepartureEvent);
    Assert.assertEquals(3600.0, handler.lastAgentDepartureEvent.getTime(), testUtils.EPSILON);

    Assert.assertNotNull(handler.lastLink1EnterEvent);
    Assert.assertEquals(
        3600.0 + firstLinkOrLaneTT, handler.lastLink1EnterEvent.getTime(), testUtils.EPSILON);

    Assert.assertEquals(
        3600.0 + firstLinkOrLaneTT, handler.lastLane1olEnterEvent.getTime(), testUtils.EPSILON);
    Assert.assertEquals(
        3600.0 + firstLinkOrLaneTT + laneTTlane1ol,
        handler.lastLane1olLeaveEvent.getTime(),
        testUtils.EPSILON);
    Assert.assertEquals(
        3600.0 + firstLinkOrLaneTT + laneTTlane1ol,
        handler.lastLane1EnterEvent.getTime(),
        testUtils.EPSILON);
    Assert.assertEquals(
        3600.0 + firstLinkOrLaneTT + laneTTlane1ol + laneTTlane1 + delayOfAgent2,
        handler.lastLane1LeaveEvent.getTime(),
        testUtils.EPSILON);

    Assert.assertNotNull(handler.lastLink2EnterEvent);
    Assert.assertEquals(
        this.fixture.pid1, handler.vehId2DriverId.get(handler.lastLink2EnterEvent.getVehicleId()));
    Assert.assertEquals(
        3600.0 + firstLinkOrLaneTT + laneTTlane1ol + laneTTlane1 + delayOfAgent2,
        handler.lastLink2EnterEvent.getTime(),
        testUtils.EPSILON);

    Assert.assertNotNull(handler.lastLink3EnterEvent);
    Assert.assertEquals(
        this.fixture.pid2, handler.vehId2DriverId.get(handler.lastLink3EnterEvent.getVehicleId()));
    Assert.assertEquals(
        3600.0 + firstLinkOrLaneTT + laneTTlane1ol + laneTTlane1 + delayOfAgent1,
        handler.lastLink3EnterEvent.getTime(),
        testUtils.EPSILON);
  }
  private void run(
      final LinkDynamics linkDynamics,
      final TrafficDynamics trafficDynamics,
      final boolean isUsingFastCapacityUpdate) {

    MatsimRandom.reset();
    scenario = ScenarioUtils.loadScenario(ConfigUtils.createConfig());
    createNetwork();

    storeVehicleTypeInfo();

    scenario.getConfig().qsim().setMainModes(Arrays.asList(travelModes));
    scenario.getConfig().qsim().setEndTime(14 * 3600);
    scenario.getConfig().qsim().setLinkDynamics(linkDynamics.name());

    if (linkDynamics.equals(LinkDynamics.SeepageQ)) {
      scenario.getConfig().qsim().setSeepMode("bike");
      scenario.getConfig().qsim().setSeepModeStorageFree(false);
      scenario.getConfig().qsim().setRestrictingSeepage(true);
    }

    scenario
        .getConfig()
        .vspExperimental()
        .setVspDefaultsCheckingLevel(VspDefaultsCheckingLevel.abort);
    scenario.getConfig().qsim().setTrafficDynamics(trafficDynamics);

    scenario.getConfig().qsim().setUsingFastCapacityUpdate(isUsingFastCapacityUpdate);

    // equal modal split run
    Map<String, Integer> minSteps = new HashMap<String, Integer>();

    double pcu1 = modeVehicleTypes.get(travelModes[0]).getPcuEquivalents();
    double pcu2 = modeVehicleTypes.get(travelModes[1]).getPcuEquivalents();

    if (pcu1 == 1 && pcu2 == 0.25) { // car bike
      minSteps.put(travelModes[0], 1);
      minSteps.put(travelModes[1], 4);
    } else { // car truck
      minSteps.put(travelModes[0], 3);
      minSteps.put(travelModes[1], 1);
    }

    int reduceNoOfDataPointsInPlot = 4; // 1--> will generate all possible data points;

    double networkDensity = 3. * (1000. / 7.5);
    double sumOfPCUInEachStep =
        (modeVehicleTypes.get(travelModes[0]).getPcuEquivalents() * minSteps.get(travelModes[0]))
            + (modeVehicleTypes.get(travelModes[1]).getPcuEquivalents()
                * minSteps.get(travelModes[1]));
    int numberOfPoints =
        (int) Math.ceil(networkDensity / (reduceNoOfDataPointsInPlot * sumOfPCUInEachStep)) + 5;

    List<Map<String, Integer>> points2Run = new ArrayList<Map<String, Integer>>();

    for (int m = 1; m < numberOfPoints; m++) {
      Map<String, Integer> pointToRun = new HashMap<>();
      for (String mode : travelModes) {
        pointToRun.put(mode, minSteps.get(mode) * m * reduceNoOfDataPointsInPlot);
      }

      double density = 0;
      for (String mode : pointToRun.keySet()) {
        double pcu = this.modeVehicleTypes.get(mode).getPcuEquivalents();
        density += pcu * pointToRun.get(mode);
      }

      if (density <= networkDensity + 10) {
        System.out.println("Number of Agents - \t" + pointToRun.toString());
        points2Run.add(pointToRun);
      }
    }

    Map<Double, Map<String, Tuple<Double, Double>>> outData =
        new HashMap<Double, Map<String, Tuple<Double, Double>>>();

    for (Map<String, Integer> point2run : points2Run) {

      System.out.println("\n \n \t \t Running points " + point2run.toString() + "\n \n");

      int count = 0;
      person2Mode.clear();

      for (String mode : point2run.keySet()) {
        for (int ii = 0; ii < point2run.get(mode); ii++) {
          person2Mode.put(Id.createPersonId(count++), mode);
        }
        this.mode2FlowData
            .get(modeVehicleTypes.get(mode).getId())
            .setnumberOfAgents(point2run.get(mode));
      }

      EventsManager events = EventsUtils.createEventsManager();
      globalFlowDynamicsUpdator = new GlobalFlowDynamicsUpdator(mode2FlowData);
      events.addHandler(globalFlowDynamicsUpdator);

      final QSim qSim = new QSim(scenario, events);
      ActivityEngine activityEngine = new ActivityEngine(events, qSim.getAgentCounter());
      qSim.addMobsimEngine(activityEngine);
      qSim.addActivityHandler(activityEngine);
      QNetsimEngine netsimEngine = new QNetsimEngine(qSim);
      qSim.addMobsimEngine(netsimEngine);
      qSim.addDepartureHandler(netsimEngine.getDepartureHandler());

      final Map<String, VehicleType> travelModesTypes = new HashMap<String, VehicleType>();

      for (String mode : travelModes) {
        travelModesTypes.put(mode, modeVehicleTypes.get(mode));
      }

      AgentSource agentSource =
          new AgentSource() {
            @Override
            public void insertAgentsIntoMobsim() {
              for (Id<Person> personId : person2Mode.keySet()) {
                String travelMode = person2Mode.get(personId);
                double actEndTime = (MatsimRandom.getRandom().nextDouble()) * 900;

                MobsimAgent agent =
                    new MySimplifiedRoundAndRoundAgent(personId, actEndTime, travelMode);
                qSim.insertAgentIntoMobsim(agent);

                final Vehicle vehicle =
                    VehicleUtils.getFactory()
                        .createVehicle(
                            Id.create(agent.getId(), Vehicle.class),
                            travelModesTypes.get(travelMode));
                final Id<Link> linkId4VehicleInsertion = Id.createLinkId("home");
                qSim.createAndParkVehicleOnLink(vehicle, linkId4VehicleInsertion);
              }
            }
          };

      qSim.addAgentSource(agentSource);

      qSim.run();

      Map<String, Tuple<Double, Double>> mode2FlowSpeed =
          new HashMap<String, Tuple<Double, Double>>();
      for (int i = 0; i < travelModes.length; i++) {

        Tuple<Double, Double> flowSpeed =
            new Tuple<Double, Double>(
                this.mode2FlowData
                    .get(Id.create(travelModes[i], VehicleType.class))
                    .getPermanentFlow(),
                this.mode2FlowData
                    .get(Id.create(travelModes[i], VehicleType.class))
                    .getPermanentAverageVelocity());
        mode2FlowSpeed.put(travelModes[i], flowSpeed);
        outData.put(
            globalFlowDynamicsUpdator.getGlobalData().getPermanentDensity(), mode2FlowSpeed);
      }
    }

    /*
     *	Basically overriding the helper.getOutputDirectory() method, such that,
     *	if file directory does not exists or same file already exists, remove and re-creates the whole dir hierarchy so that
     *	all existing files are re-written
     *	else, just keep adding files in the directory.
     *	This is necessary in order to allow writing different tests results from JUnit parameterization.
     */

    String outDir =
        "test/output/"
            + CreateAutomatedFDTest.class.getCanonicalName().replace('.', '/')
            + "/"
            + helper.getMethodName()
            + "/";
    String fileName = linkDynamics + "_" + trafficDynamics + ".png";
    String outFile;
    // ZZ_TODO : what is there exists some different directory => changing method name will keep
    // collecting the old data.
    if (!new File(outDir).exists() || new File(outDir + fileName).exists()) {
      outFile = helper.getOutputDirectory() + fileName;
    } else {
      outFile = outDir + fileName;
    }

    // plotting data
    scatterPlot(outData, outFile);
  }