case POPULATION_V5: this.delegate = new PopulationReaderMatsimV5( transformation, this.scenario);
@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 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 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); }
@Test public void testReadingOldRoutesWithoutType() { final MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); PopulationReaderMatsimV5 reader = new PopulationReaderMatsimV5(scenario); final Population population = scenario.getPopulation();
RouteInterceptingPopulationReader popReader = new RouteInterceptingPopulationReader(new PopulationReaderMatsimV5(scenario)); popReader.readFile(filename); Person person2 = pop2.getPersons().get(Id.create(1, Person.class));
@Test public void testReadRoute_sameLinkRoute() throws SAXException, ParserConfigurationException, IOException { final MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); final Population population = scenario.getPopulation(); MatsimXmlParser parser = new PopulationReaderMatsimV5(scenario); XmlParserTestHelper tester = new XmlParserTestHelper(parser); tester.startTag("population"); tester.startTag("person", new String[][]{{"id", "1"}}); tester.startTag("plan", new String[][]{{"selected", "no"}}); tester.startTag("act", new String[][]{{"type", "h"}, {"x", "-25000"}, {"y", "0"}, {"link", "1"}, {"end_time", "06:00"}}); tester.endTag(); tester.startTag("leg", new String[][]{{"mode", "car"}}); tester.startTag("route", new String[][]{{"type", "links"}}); tester.endTag("1"); tester.endTag(); tester.startTag("act", new String[][]{{"type", "w"}, {"x", "10000"}, {"y", "0"}, {"link", "1"}, {"dur", "00:10"}}); tester.endTag(); tester.endTag(); tester.endTag(); tester.endTag(); Person person1 = population.getPersons().get(Id.create("1", Person.class)); Plan plan1 = person1.getPlans().get(0); Leg leg1a = (Leg) plan1.getPlanElements().get(1); Route route1a = leg1a.getRoute(); Assert.assertEquals("different startLink for first leg.", "1", route1a.getStartLinkId().toString()); Assert.assertEquals("different endLink for first leg.", "1", route1a.getEndLinkId().toString()); Assert.assertTrue(route1a instanceof NetworkRoute); NetworkRoute nr = (NetworkRoute) route1a; Assert.assertEquals(0, nr.getLinkIds().size()); }
@Test public void testReadRoute_consequentLinks() throws SAXException, ParserConfigurationException, IOException { final MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); final Population population = scenario.getPopulation(); MatsimXmlParser parser = new PopulationReaderMatsimV5(scenario); XmlParserTestHelper tester = new XmlParserTestHelper(parser); tester.startTag("population"); tester.startTag("person", new String[][]{{"id", "1"}}); tester.startTag("plan", new String[][]{{"selected", "no"}}); tester.startTag("act", new String[][]{{"type", "h"}, {"x", "-25000"}, {"y", "0"}, {"link", "1"}, {"end_time", "06:00"}}); tester.endTag(); tester.startTag("leg", new String[][]{{"mode", "car"}}); tester.startTag("route", new String[][]{{"type", "links"}}); tester.endTag("1 2"); tester.endTag(); tester.startTag("act", new String[][]{{"type", "w"}, {"x", "10000"}, {"y", "0"}, {"link", "2"}, {"dur", "00:10"}}); tester.endTag(); tester.endTag(); tester.endTag(); tester.endTag(); Person person1 = population.getPersons().get(Id.create("1", Person.class)); Plan plan1 = person1.getPlans().get(0); Leg leg1a = (Leg) plan1.getPlanElements().get(1); Route route1a = leg1a.getRoute(); Assert.assertEquals("different startLink for first leg.", "1", route1a.getStartLinkId().toString()); Assert.assertEquals("different endLink for first leg.", "2", route1a.getEndLinkId().toString()); Assert.assertTrue(route1a instanceof NetworkRoute); NetworkRoute nr = (NetworkRoute) route1a; Assert.assertEquals(0, nr.getLinkIds().size()); }
/** * @author mrieser */ @Test public void testReadActivity() { final MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); final Population population = scenario.getPopulation(); PopulationReaderMatsimV5 reader = new PopulationReaderMatsimV5(scenario); Stack<String> context = new Stack<String>(); // not sure the context is ever used in the reader... reader.startTag("population", AttributesBuilder.getEmpty(), context); reader.startTag("person", new AttributesBuilder().add("id", "2").get(), context); reader.startTag("plan", new AttributesBuilder().add("selected", "no").get(), context); reader.startTag("act", new AttributesBuilder().add("type", "h").add("link", "3").get(), context); reader.endTag("act", "", context); reader.startTag("leg", new AttributesBuilder().add("mode", "car").get(), context); reader.endTag("leg", "", context); reader.startTag("act", new AttributesBuilder().add("type", "h").add("link", "2").get(), context); reader.endTag("plan", "", context); reader.endTag("person", "", context); reader.endTag("population", "", context); Assert.assertEquals(1, population.getPersons().size()); Person person = population.getPersons().get(Id.create("2", Person.class)); Plan plan = person.getPlans().get(0); Assert.assertEquals("3", ((Activity) plan.getPlanElements().get(0)).getLinkId().toString()); Assert.assertEquals("2", ((Activity) plan.getPlanElements().get(2)).getLinkId().toString()); }
final Population population = scenario.getPopulation(); MatsimXmlParser parser = new PopulationReaderMatsimV5(scenario); XmlParserTestHelper tester = new XmlParserTestHelper(parser);
PopulationReaderMatsimV5 popReader = new PopulationReaderMatsimV5(scenario); popReader.readFile(filename); Person person2 = pop2.getPersons().get(Id.create(1, Person.class));
final Population population = scenario.getPopulation(); PopulationReaderMatsimV5 parser = new PopulationReaderMatsimV5(scenario);