/** * Set a distance filter, dropping everything out which is not in the distance given in meters * around the given Node Id. * * @param distance * @param nodeId */ public void setDistanceFilter(final Double distance, final String nodeId) { this.distanceFilter = distance; this.distanceFilterNode = this.network.getNodes().get(Id.create(nodeId, Node.class)); }
private Geometry createBounds() { if (bounds != null) return bounds; double[] box = NetworkUtils.getBoundingBox(network.getNodes().values()); return factory.createPolygon(new Coordinate[]{ new Coordinate(box[0], box[1]), new Coordinate(box[2], box[1]), new Coordinate(box[2], box[3]), new Coordinate(box[0], box[3]), new Coordinate(box[0], box[1])}); } }
private Id<Node> getNewNodeId() { Random r = new Random(); Id<Node> id = Id.create(r.nextInt(Integer.MAX_VALUE), Node.class); while (this.network.getNodes().get(id) != null) { id = Id.create(r.nextInt(Integer.MAX_VALUE), Node.class); } return id; }
private Set<Node> circularCut(Network network) { Set<Node> nodesToRemove = new HashSet<>(); for (Node n : network.getNodes().values()) { Coord coord = n.getCoord(); double distance = CoordUtils.calcEuclideanDistance(coord, center); if (distance > radius) { nodesToRemove.add(n); } } return nodesToRemove; } }
private void setLinksMinMax() { log.info("compute network bounding box"); double[] bb = NetworkUtils.getBoundingBox(scenario.getNetwork().getNodes().values()); xCoordMinLinkNode = bb[0]; // yCoordMinLinkNode = bb[1]; // xCoordMaxLinkNode = bb[2]; yCoordMaxLinkNode = bb[3]; }
/** * Resets all nodes in the network as if they have not been visited yet. */ private void resetNetworkVisited() { for (Node node : this.network.getNodes().values()) { DijkstraNodeData data = getData(node); data.resetVisited(); } }
/** * Resets all nodes in the network as if they have not been visited yet. */ private void resetNetworkVisited() { for (Node node : this.network.getNodes().values()) { DijkstraNodeData data = getData(node); data.resetVisited(); } }
public void setCountCoordUsingDistanceFilter(final Double distance, final String nodeId) { final Coord centerCoord = network.getNodes().get(Id.create(nodeId, Node.class)).getCoord(); this.distanceFilter = new CountsComparisonAlgorithm.DistanceFilter() { @Override public boolean isInRange(Count<Link> count) { double dist = CoordUtils.calcEuclideanDistance(count.getCoord(), centerCoord); return dist < distance; } }; }
/** * Resets all nodes in the network as if they have not been visited yet. */ private void resetNetworkVisited() { for (Node node : this.network.getNodes().values()) { DijkstraNodeData data = getData(node); data.resetVisited(); } }
private Set<Node> rectangularCut(Network network) { Set<Node> nodesToRemove = new HashSet<>(); for (Node n : network.getNodes().values()) { Coord coord = n.getCoord(); double x = coord.getX(); double y = coord.getY(); if (!((x < this.maxX) && (this.minX < x) && (y < this.maxY) && (this.minY < y))) { nodesToRemove.add(n); } } return nodesToRemove; }
public static Node createAndAddNode(Network network, final Id<Node> id, final Coord coord) { if (network.getNodes().containsKey(id)) { throw new IllegalArgumentException(network + "[id=" + id + " already exists]"); } Node n = network.getFactory().createNode(id, coord); network.addNode(n) ; return n; }
public void run(final Network network) { Collection<? extends Node> nodes; if (this.travelZone.getHeight() == 0 || this.travelZone.getWidth() == 0) { nodes = network.getNodes().values(); } else { nodes = getNodesInTravelZone(network); } run(nodes); }
private int createInvertedLink(Link inLink, Link outLink, int numberOfLinksGenerated, Set<String> modes){ Link link = NetworkUtils.createAndAddLink(this.invertedNetwork,Id.create(numberOfLinksGenerated + 1, Link.class), this.invertedNetwork.getNodes().get(Id.create(inLink.getId(), Node.class)), this.invertedNetwork.getNodes().get(Id.create(outLink.getId(), Node.class)), outLink.getLength(), outLink.getFreespeed(), outLink.getCapacity(), outLink.getNumberOfLanes() ); link.setAllowedModes(modes); // log.error("created inverted link " + link.getId() + " from " + inLink.getId() + " to " + outLink.getId() + " with modes " + modes); NetworkUtils.setType( ((Link) link), NetworkUtils.getType(((Link) outLink))); return numberOfLinksGenerated + 1; }
@Test public void testGetNodes_mixedDelimiters() { Network network = getTestNetwork(); List<Node> nodes = NetworkUtils.getNodes(network, " 1\t\t2 \n4\t \t5 3 "); assertEquals(5, nodes.size()); assertEquals(network.getNodes().get(Id.create(1, Node.class)), nodes.get(0)); assertEquals(network.getNodes().get(Id.create(2, Node.class)), nodes.get(1)); assertEquals(network.getNodes().get(Id.create(4, Node.class)), nodes.get(2)); assertEquals(network.getNodes().get(Id.create(5, Node.class)), nodes.get(3)); assertEquals(network.getNodes().get(Id.create(3, Node.class)), nodes.get(4)); }
private static Link createLink(final Network network, final Id<Link> id, final Id<Node> fromNodeId, final Id<Node> toNodeId, final Set<String> modes) { Link link = network.getFactory().createLink(id, network.getNodes().get(fromNodeId), network.getNodes().get(toNodeId)); link.setAllowedModes(modes); link.setCapacity(2000.0); link.setFreespeed(10.0); link.setLength(100.0); link.setNumberOfLanes(1); return link; }
@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 testPersonAvailableForDisutility_FastDijkstra() { Fixture f = new Fixture(); LeastCostPathCalculatorFactory routerFactory = new FastDijkstraFactory(); LeastCostPathCalculator router = routerFactory.createPathCalculator(f.network, f.costFunction, new FreeSpeedTravelTime()); router.calcLeastCostPath( f.network.getNodes().get(Id.create("2", Node.class)), f.network.getNodes().get(Id.create("1", Node.class)), 07*3600, f.person, f.vehicle); // hopefully there was no Exception until here... Assert.assertEquals(22, f.costFunction.cnt); // make sure the costFunction was actually used }
@Test public void testPersonAvailableForDisutility_AStarLandmarks() { Fixture f = new Fixture(); LeastCostPathCalculatorFactory routerFactory = new FastAStarEuclideanFactory(); LeastCostPathCalculator router = routerFactory.createPathCalculator(f.network, f.costFunction, new FreeSpeedTravelTime()); router.calcLeastCostPath( f.network.getNodes().get(Id.create("2", Node.class)), f.network.getNodes().get(Id.create("1", Node.class)), 07*3600, f.person, f.vehicle); // hopefully there was no Exception until here... Assert.assertEquals(22, f.costFunction.cnt); // make sure the costFunction was actually used }
@Test public void testFilter_NoModes() { final Fixture f = new Fixture(); TransportModeNetworkFilter filter = new TransportModeNetworkFilter(f.scenario.getNetwork()); Network subNetwork = ScenarioUtils.createScenario(ConfigUtils.createConfig()).getNetwork(); filter.filter(subNetwork, new HashSet<String>()); Assert.assertEquals("wrong number of nodes.", 0, subNetwork.getNodes().size()); Assert.assertEquals("wrong number of links", 0, subNetwork.getLinks().size()); }
public void testNodesShape() { String netFileName = "test/scenarios/equil/network.xml"; String outputFileShp = getOutputDirectory() + "./network.shp"; Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); final Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile(netFileName); new Nodes2ESRIShape(network,outputFileShp, "DHDN_GK4").write(); Collection<SimpleFeature> writtenFeatures = ShapeFileReader.getAllFeatures(outputFileShp); Assert.assertEquals(network.getNodes().size(), writtenFeatures.size()); } }