@Test public void testRepeatingLegs() { final MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); PopulationReaderMatsimV5 reader = new PopulationReaderMatsimV5(scenario); final Population population = scenario.getPopulation(); String str = "<?xml version=\"1.0\" ?>"+ "<!DOCTYPE population SYSTEM \"http://www.matsim.org/files/dtd/population_v5.dtd\">"+ "<population>"+ "<person id=\"1\">"+ " <plan>"+ " <act type=\"h\" x=\"-25000\" y=\"0\" end_time=\"06:00\" />"+ " <leg mode=\"walk\" />"+ " <leg mode=\"pt\" />"+ " <leg mode=\"walk\" />"+ " <act type=\"w\" x=\"10000\" y=\"0\" />"+ " </plan>"+ "</person>"+ "</population>"; reader.parse(new ByteArrayInputStream(str.getBytes())); Plan plan = population.getPersons().get(Id.create(1, Person.class)).getSelectedPlan(); Assert.assertEquals(5, plan.getPlanElements().size()); Assert.assertTrue(plan.getPlanElements().get(0) instanceof Activity); Assert.assertTrue(plan.getPlanElements().get(1) instanceof Leg); Assert.assertTrue(plan.getPlanElements().get(2) instanceof Leg); Assert.assertTrue(plan.getPlanElements().get(3) instanceof Leg); Assert.assertTrue(plan.getPlanElements().get(4) instanceof Activity); }
@Test public void testRepeatingActs() { final MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); PopulationReaderMatsimV5 reader = new PopulationReaderMatsimV5(scenario); final Population population = scenario.getPopulation(); String str = "<?xml version=\"1.0\" ?>"+ "<!DOCTYPE population SYSTEM \"http://www.matsim.org/files/dtd/population_v5.dtd\">"+ "<population>"+ "<person id=\"1\">"+ " <plan>"+ " <act type=\"h\" x=\"-25000\" y=\"0\" end_time=\"06:00\" />"+ " <leg mode=\"walk\" />"+ " <act type=\"w\" x=\"10000\" y=\"0\" end_time=\"12:00\" />"+ " <act type=\"l\" x=\"10000\" y=\"0\" />"+ " </plan>"+ "</person>"+ "</population>"; reader.parse(new ByteArrayInputStream(str.getBytes())); Plan plan = population.getPersons().get(Id.create(1, Person.class)).getSelectedPlan(); Assert.assertEquals(4, plan.getPlanElements().size()); Assert.assertTrue(plan.getPlanElements().get(0) instanceof Activity); Assert.assertTrue(plan.getPlanElements().get(1) instanceof Leg); Assert.assertTrue(plan.getPlanElements().get(2) instanceof Activity); Assert.assertTrue(plan.getPlanElements().get(3) instanceof Activity); }
@Test public void testVehicleIdInRoute() { final MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); PopulationReaderMatsimV5 reader = new PopulationReaderMatsimV5(scenario); final Population population = scenario.getPopulation(); String str = "<?xml version=\"1.0\" ?>"+ "<!DOCTYPE population SYSTEM \"http://www.matsim.org/files/dtd/population_v5.dtd\">"+ "<population>"+ "<person id=\"1\">"+ " <plan>"+ " <act type=\"h\" x=\"-25000\" y=\"0\" end_time=\"06:00\" />"+ " <leg mode=\"car\" >"+ " <route type=\"links\" vehicleRefId=\"123\"/>" + " </leg>" + " <act type=\"w\" x=\"10000\" y=\"0\" end_time=\"12:00\" />"+ " </plan>"+ "</person>"+ "</population>"; reader.parse(new ByteArrayInputStream(str.getBytes())); Plan plan = population.getPersons().get(Id.create(1, Person.class)).getSelectedPlan(); Assert.assertEquals(3, plan.getPlanElements().size()); Assert.assertTrue(plan.getPlanElements().get(0) instanceof Activity); Assert.assertTrue(plan.getPlanElements().get(1) instanceof Leg); Leg leg = (Leg) plan.getPlanElements().get(1) ; NetworkRoute route = (NetworkRoute) leg.getRoute() ; Assert.assertEquals(Id.create("123", Vehicle.class), route.getVehicleId() ) ; Assert.assertTrue(plan.getPlanElements().get(2) instanceof Activity); }
"</person>"+ "</population>"; reader.parse(new ByteArrayInputStream(str.getBytes()));