@Override public void setLinkIds( final Id<Link> startLinkId, final List<Id<Link>> linkIds, final Id<Link> endLinkId) { netRoute.setLinkIds(startLinkId, linkIds, endLinkId); }
public static NetworkRoute createNetworkRoute(List<Id<Link>> routeLinkIds, final Network network) { Id<Link> startLinkId = routeLinkIds.get(0); List<Id<Link>> linksBetween = (routeLinkIds.size() > 2) ? routeLinkIds.subList(1, routeLinkIds.size() - 1) : new ArrayList<>(0); Id<Link> endLinkId = routeLinkIds.get(routeLinkIds.size() - 1); NetworkRoute route = createLinkNetworkRouteImpl(startLinkId, endLinkId); route.setLinkIds(startLinkId, linksBetween, endLinkId); return route; }
private NetworkRoute createRoute(Id<Link> fromLink, Path path, Id<Link> toLink) { NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(fromLink, toLink); route.setLinkIds(fromLink, getLinkIds(path.links), toLink); return route; }
private void finishLeg(Id<Link> toLocation) { NetworkRoute route = null; if (previousRouteContent != null) { List<Id<Link>> linkIds = NetworkUtils.getLinkIds(previousRouteContent); route = RouteUtils.createLinkNetworkRouteImpl(previousActLoc, toLocation); if (!linkIds.isEmpty()) { route.setLinkIds(previousActLoc, linkIds, toLocation); } } currentTourBuilder.addLeg(currentTourBuilder.createLeg(route, currentLegDepTime,currentLegTransTime)); previousRouteContent = null; }
private void finishLeg(Id<Link> toLocation) { NetworkRoute route = null; if (previousRouteContent != null) { List<Id<Link>> linkIds = NetworkUtils.getLinkIds(previousRouteContent); route = RouteUtils.createLinkNetworkRouteImpl(previousActLoc, toLocation); if (!linkIds.isEmpty()) { route.setLinkIds(previousActLoc, linkIds, toLocation); } } currentTourBuilder.addLeg(currentTourBuilder.createLeg(route, currentLegDepTime, currentLegTransTime)); previousRouteContent = null; }
private void insertWenden(Id<Link> fromLinkId, Id<Link> toLinkId, Umlauf umlauf) { Node startNode = this.network.getLinks().get(fromLinkId).getToNode(); Node endNode = this.network.getLinks().get(toLinkId).getFromNode(); double depTime = 0.0; Path wendenPath = routingAlgo.calcLeastCostPath(startNode, endNode, depTime, null, null); if (wendenPath == null) { throw new RuntimeException("No route found from node " + startNode.getId() + " to node " + endNode.getId() + "."); } NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(fromLinkId, toLinkId); route.setLinkIds(fromLinkId, NetworkUtils.getLinkIds(wendenPath.links), toLinkId); umlauf.getUmlaufStuecke().add(new Wenden(route)); }
@Test public void testGetNodes_NoLinksBetween() { Fixture f = new Fixture(); Id<Link> startLinkId = f.linkIds[3]; Id<Link> endLinkId = f.linkIds[4]; List<Id<Link>> linkIds = new ArrayList<Id<Link>>(0); NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(startLinkId, endLinkId); route.setLinkIds(startLinkId, linkIds, endLinkId); List<Node> nodes = RouteUtils.getNodes(route, f.network); Assert.assertEquals(1, nodes.size()); Assert.assertEquals(f.nodeIds[4], nodes.get(0).getId()); }
@Test public void testStartAndEndOnSameLinks_setLinks() { Network network = createTestNetwork(); Id<Link> link = Id.create("3", Link.class); NetworkRoute route = getNetworkRouteInstance(link, link, network); route.setLinkIds(link, new ArrayList<Id<Link>>(0), link); Assert.assertEquals(0, route.getLinkIds().size()); }
@Test public void testGetSubRoute_sameStartEnd() { Fixture f = new Fixture(); NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(f.linkIds[0], f.linkIds[5]); List<Id<Link>> linkIds = new ArrayList<Id<Link>>(); Collections.addAll(linkIds, f.linkIds[1], f.linkIds[2], f.linkIds[3], f.linkIds[4]); route.setLinkIds(f.linkIds[0], linkIds, f.linkIds[5]); NetworkRoute subRoute = RouteUtils.getSubRoute(route, f.network.getNodes().get(f.nodeIds[5]), f.network.getNodes().get(f.nodeIds[4]), f.network); Assert.assertEquals(0, subRoute.getLinkIds().size()); Assert.assertEquals(f.linkIds[4], subRoute.getStartLinkId()); Assert.assertEquals(f.linkIds[4], subRoute.getEndLinkId()); }
@Test public void testGetSubRoute_emptySubRoute() { Fixture f = new Fixture(); NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(f.linkIds[0], f.linkIds[5]); List<Id<Link>> linkIds = new ArrayList<Id<Link>>(); Collections.addAll(linkIds, f.linkIds[1], f.linkIds[2], f.linkIds[3], f.linkIds[4]); route.setLinkIds(f.linkIds[0], linkIds, f.linkIds[5]); NetworkRoute subRoute = RouteUtils.getSubRoute(route, f.network.getNodes().get(f.nodeIds[4]), f.network.getNodes().get(f.nodeIds[4]), f.network); Assert.assertEquals(0, subRoute.getLinkIds().size()); Assert.assertEquals(f.linkIds[3], subRoute.getStartLinkId()); Assert.assertEquals(f.linkIds[4], subRoute.getEndLinkId()); }
@Test public void testStartAndEndOnSubsequentLinks_setLinks() { Network network = createTestNetwork(); final Id<Link> link13 = Id.create("13", Link.class); final Id<Link> link14 = Id.create("14", Link.class); NetworkRoute route = getNetworkRouteInstance(link13, link14, network); route.setLinkIds(link13, new ArrayList<Id<Link>>(0), link14); Assert.assertEquals(0, route.getLinkIds().size()); }
@Test public void testGetNodes_SameStartEndLink() { Fixture f = new Fixture(); Link startLink = f.network.getLinks().get(f.linkIds[2]); Link endLink = f.network.getLinks().get(f.linkIds[2]); List<Id<Link>> links = new ArrayList<Id<Link>>(0); NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(startLink.getId(), endLink.getId()); route.setLinkIds(startLink.getId(), links, endLink.getId()); List<Node> nodes = RouteUtils.getNodes(route, f.network); Assert.assertEquals(0, nodes.size()); }
@Test public void testGetLinkIds() { Network network = createTestNetwork(); Id<Link> link1 = Id.create("1", Link.class); Id<Link> link4 = Id.create("4", Link.class); NetworkRoute route = getNetworkRouteInstance(link1, link4, network); route.setLinkIds(link1, NetworkUtils.getLinkIds("22 12 -23 3"), link4); List<Id<Link>> ids = route.getLinkIds(); Assert.assertEquals("number of links in route.", 4, ids.size()); Assert.assertEquals(Id.create("22", Link.class), ids.get(0)); Assert.assertEquals(Id.create("12", Link.class), ids.get(1)); Assert.assertEquals(Id.create("-23", Link.class), ids.get(2)); Assert.assertEquals(Id.create("3", Link.class), ids.get(3)); }
@Test public void testPtTutorialWithError() { Scenario scenario = ScenarioUtils.loadScenario(ConfigUtils.loadConfig("test/scenarios/pt-tutorial/0.config.xml")); TransitLine transitLine = scenario.getTransitSchedule().getTransitLines().get(Id.create("Blue Line", TransitLine.class)); transitLine.getRoutes().get(Id.create("3to1", TransitRoute.class)).getRoute().setLinkIds(Id.createLinkId("33"), Collections.<Id<Link>>emptyList(), Id.createLinkId("11")); TransitScheduleValidator.ValidationResult validationResult = TransitScheduleValidator.validateAll(scenario.getTransitSchedule(), scenario.getNetwork()); Assert.assertThat(validationResult.getIssues(), containsInAnyOrder(Matchers.allOf( hasProperty("severity", Matchers.equalTo(TransitScheduleValidator.ValidationResult.Severity.ERROR)), hasProperty("entities", containsInAnyOrder(Matchers.equalTo(Id.create("2b", TransitStopFacility.class))))))); }
@Test public void testGetSubRoute_sameLinks_emptyRoute1() { Network network = createTestNetwork(); Id<Link> id1 = Id.create("1", Link.class); NetworkRoute route = getNetworkRouteInstance(id1, id1, network); route.setLinkIds(id1, null, id1); NetworkRoute subRoute = route.getSubRoute(id1, id1); List<Id<Link>> linkIds = subRoute.getLinkIds(); Assert.assertEquals("number of links in subRoute.", 0, linkIds.size()); Assert.assertEquals("wrong start link.", id1, subRoute.getStartLinkId()); Assert.assertEquals("wrong end link.", id1, subRoute.getEndLinkId()); }
@Test public void testGetDistance() { Network network = createTestNetwork(); Id<Link> link1 = Id.create("1", Link.class); Id<Link> link4 = Id.create("4", Link.class); NetworkRoute route = getNetworkRouteInstance(link1, link4, network); route.setLinkIds(link1, NetworkUtils.getLinkIds("22 12 -23 3"), link4); route.setDistance(1234.5); Assert.assertEquals("wrong difference.", 1234.5, route.getDistance(), MatsimTestCase.EPSILON); }
@Test public void testGetSubRoute_endOnly() { Network network = createTestNetwork(); Id<Link> id0 = Id.create("0", Link.class); Id<Link> id15 = Id.create("15", Link.class); NetworkRoute route = getNetworkRouteInstance(id0, id15, network); route.setLinkIds(id0, NetworkUtils.getLinkIds("1 22 12 -23 3 24 14"), id15); NetworkRoute subRoute = route.getSubRoute(id15, id15); List<Id<Link>> linkIds = subRoute.getLinkIds(); Assert.assertEquals("number of links in subRoute.", 0, linkIds.size()); Assert.assertEquals("wrong start link.", id15, subRoute.getStartLinkId()); Assert.assertEquals("wrong end link.", id15, subRoute.getEndLinkId()); }
@Test public void testGetSubRoute_startOnly() { Network network = createTestNetwork(); Id<Link> id0 = Id.create("0", Link.class); Id<Link> id15 = Id.create("15", Link.class); NetworkRoute route = getNetworkRouteInstance(id0, id15, network); route.setLinkIds(id0, NetworkUtils.getLinkIds("1 22 12 -23 3 24 14"), id15); NetworkRoute subRoute = route.getSubRoute(id0, id0); List<Id<Link>> linkIds = subRoute.getLinkIds(); Assert.assertEquals("number of links in subRoute.", 0, linkIds.size()); Assert.assertEquals("wrong start link.", id0, subRoute.getStartLinkId()); Assert.assertEquals("wrong end link.", id0, subRoute.getEndLinkId()); }
@Test public void testGetSubRoute_sameLinks() { Network network = createTestNetwork(); Id<Link> id1 = Id.create("1", Link.class); Id<Link> id12 = Id.create("12", Link.class); Id<Link> id14 = Id.create("14", Link.class); NetworkRoute route = getNetworkRouteInstance(id1, id14, network); route.setLinkIds(id1, NetworkUtils.getLinkIds("22 12 -23 3 24"), id14); NetworkRoute subRoute = route.getSubRoute(id12, id12); List<Id<Link>> linkIds = subRoute.getLinkIds(); Assert.assertEquals("number of links in subRoute.", 0, linkIds.size()); Assert.assertEquals("wrong start link.", id12, subRoute.getStartLinkId()); Assert.assertEquals("wrong end link.", id12, subRoute.getEndLinkId()); }
private static Person createPerson(Id<Person> personId, MutableScenario scenario, Link link1, Link link2) { final Id<Person> id = personId; Person p = PopulationUtils.getFactory().createPerson(id); Plan plan = PersonUtils.createAndAddPlan(p, true); PopulationUtils.createAndAddActivityFromLinkId(plan, "h", link1.getId()); Leg leg = PopulationUtils.createAndAddLeg( plan, TransportMode.car ); NetworkRoute route = ((PopulationFactory) scenario.getPopulation().getFactory()).getRouteFactories().createRoute(NetworkRoute.class, link1.getId(), link2.getId()); leg.setRoute(route); route.setLinkIds(link1.getId(), null, link2.getId()); leg.setRoute(route); PopulationUtils.createAndAddActivityFromLinkId(plan, "w", link2.getId()); return p; }