public String allStopsWithCorrectLink() { for (StopTime stopTime : trip.getStopTimes().values()) { Stop stop = stops.get(stopTime.getStopId()); Link link = network.getLinks().get(Id.create(stop.getLinkId(), Link.class)); Point2D fromPoint = new Point2D(link.getFromNode().getCoord().getX(), link.getFromNode().getCoord().getY()); Point2D toPoint = new Point2D(link.getToNode().getCoord().getX(), link.getToNode().getCoord().getY()); Line2D linkLine = new Line2D(fromPoint, toPoint); Point2D point = new Point2D(stop.getPoint().getX(), stop.getPoint().getY()); if (!linkLine.isNearestInside(point)) { int pos = getLinkPosition(link.getId().toString()); if (pos == -1) return stopTime.getStopId(); if (pos == links.size() - 1 || pos == 0) return ""; Link link2 = links.get(pos + 1); fromPoint = new Point2D( link2.getFromNode().getCoord().getX(), link2.getFromNode().getCoord().getY()); toPoint = new Point2D(link2.getToNode().getCoord().getX(), link2.getToNode().getCoord().getY()); Line2D linkLine2 = new Line2D(fromPoint, toPoint); if (!(linkLine.getPointPosition(point).equals(Line2D.PointPosition.AFTER) && linkLine2.getPointPosition(point).equals(Line2D.PointPosition.BEFORE))) return stopTime.getStopId(); } } return ""; }
public String allStopsWithInRouteLink() { for (StopTime stopTime : trip.getStopTimes().values()) { Stop stop = stops.get(stopTime.getStopId()); Link link = network.getLinks().get(Id.createLinkId(stop.getLinkId())); // Link link = network.getLinks().get(stop.getLinkId()); if (!links.contains(link)) return stopTime.getStopId(); } return ""; }
public void calculatePath() { links.clear(); Iterator<StopTime> prev = trip.getStopTimes().values().iterator(), next = trip.getStopTimes().values().iterator(); List<Link> prevLL, nextLL; Link prevL = null, nextL = null; next.next(); Stop prevStop = null, nextStop = null; if (next.hasNext()) { Path bestPath = null; prevStop = stops.get(prev.next().getStopId()); nextStop = stops.get(next.next().getStopId()); if (prevStop.getLinkId() != null) { prevLL = new ArrayList<Link>(); prevLL.add(network.getLinks().get(Id.create(prevStop.getLinkId(), Link.class))); } else prevLL = getBestLinksMode(network, prevStop.getPoint(), trip.getShape()); if (nextStop.getLinkId() != null) { nextLL = new ArrayList<Link>(); nextLL.add(network.getLinks().get(Id.create(nextStop.getLinkId(), Link.class))); } else nextLL = getBestLinksMode(network, nextStop.getPoint(), trip.getShape()); List<Tuple<Path, Link[]>> paths = new ArrayList<Tuple<Path, Link[]>>(); for (int i = 0; i < prevLL.size(); i++) for (int j = 0; j < nextLL.size(); j++) { prevL = prevLL.get(i); nextL = nextLL.get(j); Path path; if (prevL == nextL) path = new Path(new ArrayList<Node>(), new ArrayList<Link>(), 0.0, 0.0); else { path = leastCostPathCalculator.calcLeastCostPath( prevL.getToNode(), nextL.getFromNode(), 0, null, null); if (path == null) path = new Path(new ArrayList<Node>(), new ArrayList<Link>(), 0.0, 0.0); path.links.add(0, prevL); } path.links.add(nextL); paths.add(new Tuple<Path, Link[]>(path, new Link[] {prevL, nextLL.get(j)})); } double shortestDistance = Double.POSITIVE_INFINITY; for (Tuple<Path, Link[]> tuple : paths) { if (tuple.getFirst().links.size() > 0) { double distance = calculateDistance(tuple.getFirst(), prevStop.getPoint(), nextStop.getPoint()); if (bestPath == null || distance <= shortestDistance) { shortestDistance = distance; bestPath = tuple.getFirst(); prevStop.setLinkId(tuple.getSecond()[0].getId().toString()); nextStop.setLinkId(tuple.getSecond()[1].getId().toString()); } } } prevL = bestPath.links.get(bestPath.links.size() - 1); links.addAll(bestPath.links); prevStop = nextStop; } for (; next.hasNext(); ) { Path bestPath = null; nextStop = stops.get(next.next().getStopId()); if (nextStop.getLinkId() != null) { nextL = network.getLinks().get(Id.create(nextStop.getLinkId(), Link.class)); if (prevL.equals(nextL)) bestPath = new Path(new ArrayList<Node>(), new ArrayList<Link>(), 0.0, 0.0); else { bestPath = leastCostPathCalculator.calcLeastCostPath( prevL.getToNode(), nextL.getFromNode(), 0, null, null); if (bestPath == null) bestPath = new Path(new ArrayList<Node>(), new ArrayList<Link>(), 0.0, 0.0); else bestPath.links.add(0, prevL); } bestPath.links.add(nextL); } else { nextLL = getBestLinksMode(network, nextStop.getPoint(), trip.getShape()); List<Tuple<Path, Link>> paths = new ArrayList<Tuple<Path, Link>>(); for (int i = 0; i < nextLL.size(); i++) { nextL = nextLL.get(i); Path path; if (prevL.equals(nextL)) path = new Path(new ArrayList<Node>(), new ArrayList<Link>(), 0.0, 0.0); else { path = leastCostPathCalculator.calcLeastCostPath( prevL.getToNode(), nextL.getFromNode(), 0, null, null); if (path == null) path = new Path(new ArrayList<Node>(), new ArrayList<Link>(), 0.0, 0.0); else path.links.add(0, prevL); } path.links.add(nextL); paths.add(new Tuple<Path, Link>(path, nextL)); } double shortestDistance = Double.POSITIVE_INFINITY; for (Tuple<Path, Link> tuple : paths) { double distance = calculateDistance(tuple.getFirst(), prevStop.getPoint(), nextStop.getPoint()); if (bestPath == null || distance <= shortestDistance) { shortestDistance = distance; bestPath = tuple.getFirst(); nextStop.setLinkId(tuple.getSecond().getId().toString()); } } } prevL = bestPath.links.get(bestPath.links.size() - 1); bestPath.links.remove(0); links.addAll(bestPath.links); prevStop = nextStop; } }