public void initForLink(final Link link) { this.fromNode = link.getFromNode(); this.toNode = link.getToNode(); this.tmpToNodeData = null; }
@SuppressWarnings("static-method") private boolean checkNextLinkSemantics(Link currentLink, Link nextLink, MobsimAgent personAgent){ if (currentLink.getToNode() != nextLink.getFromNode()) { // throw new RuntimeException("Cannot move PersonAgent " + personAgent.getId() + // " from link " + currentLink.getId() + " to link " + nextLink.getId()); return false ; } return true ; }
public static Map<Id<Node>, ? extends Node> getInNodes(Node node) { Map<Id<Node>, Node> nodes = new TreeMap<>(); for (Link link : node.getInLinks().values()) { Node inNode = link.getFromNode(); nodes.put(inNode.getId(), inNode); } return nodes; }
private boolean areLinksMergeable(Link inLink, Link outLink) { List<Node> fromNodes = this.mergedLinksToIntermediateNodes.get(inLink.getId()); if (fromNodes==null) fromNodes = new ArrayList<>(); fromNodes.add(inLink.getFromNode()); List<Node> toNodes = this.mergedLinksToIntermediateNodes.get(outLink.getId()); if(toNodes==null) toNodes = new ArrayList<>(); toNodes.add(outLink.getToNode()); for(Node n :fromNodes) { if (toNodes.contains(n)) return false; } return true; }
private void getLinksTillLink(final List<Id<Link>> links, final Id<Link> nextLinkId, final Id<Link> startLinkId) { Id<Link> linkId = startLinkId; Link nextLink = this.network.getLinks().get(nextLinkId); while (true) { // loop until we hit "return;" Link link = this.network.getLinks().get(linkId); if (link.getToNode() == nextLink.getFromNode()) { return; } linkId = this.subsequentLinks.get(linkId); links.add(linkId); } }
private int getNOfIncidentNodes(final Node node) { HashMap<Id<Node>, Node> nodes = new HashMap<>(); for (Link link : node.getInLinks().values()) { nodes.put(link.getFromNode().getId(), link.getFromNode()); } for (Link link : node.getOutLinks().values()) { nodes.put(link.getToNode().getId(), link.getToNode()); } return nodes.size(); } }
private static Map<Id<Node>, Node> getIncidentNodes(Node node) { Map<Id<Node>, Node> nodes = new TreeMap<>(); for (Link link : node.getInLinks().values()) { nodes.put(link.getFromNode().getId(), link.getFromNode()); } for (Link link : node.getOutLinks().values()) { nodes.put(link.getToNode().getId(), link.getToNode()); } return nodes; }
public static Link findLinkInOppositeDirection(Link link) { for ( Link candidateLink : link.getToNode().getOutLinks().values() ) { if ( candidateLink.getToNode().equals( link.getFromNode() ) ) { return candidateLink ; } } return null ; } public static void readNetwork( Network network, String string ) {
/** * ASSUMPTION: A vehicle enters and exits links at their ends (link.getToNode()) */ public static VrpPathWithTravelData calcAndCreatePath(Link fromLink, Link toLink, double departureTime, LeastCostPathCalculator router, TravelTime travelTime) { Path path = null; if (fromLink != toLink) { // calc path for departureTime+1 (we need 1 second to move over the node) path = router.calcLeastCostPath(fromLink.getToNode(), toLink.getFromNode(), departureTime + 1, null, null); } return VrpPaths.createPath(fromLink, toLink, departureTime, path, travelTime); }
@Override public boolean isAcceptingFromUpstream() { return e.hasSpace(getLink().getFromNode().getId()); }
private boolean checkLinkLengths(final Network network) { for (Link link : network.getLinks().values()) { double linkLength = link.getLength(); double eucDist = CoordUtils.calcEuclideanDistance(link.getFromNode().getCoord(), link.getToNode().getCoord()); if (linkLength < eucDist) { if (log.isDebugEnabled()) { log.debug("link " + link.getId() + " has length " + linkLength + " which is smaller than the euclidean distance " + eucDist); } return false; } } return true; }
/** * Helper method for type conversion. * * @param link * @return */ public static LineString createGeotoolsLineString(Link link) { Coordinate fromCoord = MGC.coord2Coordinate( link.getFromNode().getCoord() ) ; Coordinate toCoord = MGC.coord2Coordinate( link.getToNode().getCoord() ) ; LineString theSegment = new GeometryFactory().createLineString(new Coordinate[]{ fromCoord, toCoord }); return theSegment; }
private void moveToAbort(final MobsimAgent mobsimAgent, final double now, Link currentLink, Link nextLink) { log.error("Agent has no or wrong route! agentId=" + mobsimAgent.getId() + " currentLink=" + currentLink.getId().toString() + " nextLink=" + (nextLink!=null?nextLink.getId():"null") + " currentLinkToNode=" + currentLink.getToNode().getId() + " nextLinkFromNode=" + (nextLink!=null?nextLink.getFromNode().getId():"null") + ". The agent is removed from the simulation."); mobsimAgent.setStateToAbort(now); this.simEngine.internalInterface.arrangeNextAgentState(mobsimAgent); } }
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)); }
@Override public Link removeLink(final Id<Link> linkId) { Link l = this.links.remove(linkId); if (l == null) { return null; } l.getFromNode().removeOutLink(l.getId()) ; l.getToNode().removeInLink(l.getId()) ; if (this.linkQuadTree != null) { this.linkQuadTree.remove(l); } return l; }
private static Coord getVector(Link link){ double x = link.getToNode().getCoord().getX() - link.getFromNode().getCoord().getX(); double y = link.getToNode().getCoord().getY() - link.getFromNode().getCoord().getY(); return new Coord(x, y); }
private void processLink(Link link, EmissionsByPollutant emissions, Grid<Map<Pollutant, Double>> grid) { // create a clipping area to speed up calculation time // use 5*smoothing radius as longer distances result in a weighting of effectively 0 Geometry clip = factory.createPoint(new Coordinate(link.getCoord().getX(), link.getCoord().getY())).buffer(smoothingRadius * 5); grid.getCells(clip).forEach(cell -> { double normalizationFactor = grid.getCellArea() / (Math.PI * smoothingRadius * smoothingRadius); double weight = SpatialInterpolation.calculateWeightFromLine( transformToCoordinate(link.getFromNode()), transformToCoordinate(link.getToNode()), cell.getCoordinate(), smoothingRadius); processCell(cell, emissions, weight * normalizationFactor); }); }
public static double getGradientFactor(Link link) { double gradient = 0.; Double fromNodeZ = link.getFromNode().getCoord().getZ(); Double toNodeZ = link.getToNode().getCoord().getZ(); if ((fromNodeZ != null) && (toNodeZ != null)) { if (toNodeZ > fromNodeZ) { // No positive utility for downhill, only negative for uphill gradient = (toNodeZ - fromNodeZ) / link.getLength(); } } return gradient; }
private static Link findLinkBetween(final Network network, final Id<Link> fromLinkId, final Id<Link> toLinkId) { Link fromLink = network.getLinks().get(fromLinkId); Link toLink = network.getLinks().get(toLinkId); Node from = fromLink.getToNode(); Node to = toLink.getFromNode(); for (Link link : from.getOutLinks().values()) { if (link.getToNode() == to) { return link; } } return null; }
@Override public String toString() { return "[" + ((TransitRouterNetworkNode) link.getFromNode()).getStop().getStopFacility().getId() + ">" + ((TransitRouterNetworkNode) link.getToNode()).getStop().getStopFacility().getId() + " @ " + time + "]"; } }