@Test public final void testLowestFrcRouting() { try { TestData td = TestData.getInstance(); MapDatabase mdb = td.getMapDatabase(); RouteSearch rs = new RouteSearch(Arrays.asList(mdb.getLine(1), mdb.getLine(3), mdb.getLine(5), mdb.getLine(8))); RouteSearchResult result = rs.calculateRoute(); assertEquals(1, result.getIntermediatePos()); } catch (Exception e) { fail("Wrong error detected: " + e.getMessage()); } }
public final RouteSearchResult calculateRoute() throws OpenLREncoderProcessingException { if (LOG.isDebugEnabled()) { LOG.debug("route search between start (" + startLine.getID() + ") and dest (" + destLine.getID() + ")"); } RouteSearchResult result = null; if (startLine.getID() == destLine.getID() && location.size() > 1) { List<Line> route = new ArrayList<Line>(1); route.add(startLine); result = new RouteSearchResult( RouteSearchReturnCode.INTERMEDIATE_FOUND, route, location .get(1), 1); } else if (startLoopIndex == 0) { List<Line> route = new ArrayList<Line>(); route.add(startLine); result = new RouteSearchResult(RouteSearchReturnCode.INTERMEDIATE_FOUND, route, location.get(1), 1); } else { IntermediateHandler iHandler = new IntermediateHandler(location); RouteSearchData data = new RouteSearchData(); Node e = destLine.getEndNode(); destX = e.getLongitudeDeg(); destY = e.getLatitudeDeg(); int startLength = startLine.getLineLength(); PQElem startElem = new PQElem(startLine, 0, startLength, null); data.addToOpen(startElem); OpenLongHashSet locationIDs = new OpenLongHashSet(location.size()); for (Line l : location) { locationIDs.put(l.getID()); } while (!data.isOpenEmpty()) { PQElem actualElement = data.pollElement(); if (locationIDs.containsKey(actualElement.getLine().getID())) { result = iHandler.checkIntermediate(actualElement, data); if (result != null) { break; } } if (actualElement.getLine().getID() == destLine.getID()) { if (endLoopIndex >= 0) { List<Line> route = PathUtils .constructPath(actualElement.getPrevious()); result = new RouteSearchResult( RouteSearchReturnCode.INTERMEDIATE_FOUND, route, destLine, endLoopIndex); break; } else { List<Line> route = PathUtils .constructPath(actualElement); if (route.isEmpty()) { throw new OpenLREncoderProcessingException( EncoderProcessingError.ROUTE_CONSTRUCTION_ERROR); } else { result = new RouteSearchResult( RouteSearchResult.RouteSearchReturnCode.ROUTE_FOUND, route); break; } } } if (startLoopIndex > 0 && iHandler.getLastElemOnRoutePos() == startLoopIndex) { if (LOG.isDebugEnabled()) { LOG.debug("loop is traversed, intermediate found"); } List<Line> route = PathUtils.constructPath(actualElement.getPrevious()); result = new RouteSearchResult( RouteSearchReturnCode.INTERMEDIATE_FOUND, route, startLine, startLoopIndex); break; } extractNextLines(actualElement, data); } if (result == null) { result = new RouteSearchResult(RouteSearchReturnCode.NO_ROUTE_FOUND); } } return result; }
RouteSearch { public final RouteSearchResult calculateRoute() throws OpenLREncoderProcessingException { if (LOG.isDebugEnabled()) { LOG.debug("route search between start (" + startLine.getID() + ") and dest (" + destLine.getID() + ")"); } RouteSearchResult result = null; if (startLine.getID() == destLine.getID() && location.size() > 1) { List<Line> route = new ArrayList<Line>(1); route.add(startLine); result = new RouteSearchResult( RouteSearchReturnCode.INTERMEDIATE_FOUND, route, location .get(1), 1); } else if (startLoopIndex == 0) { List<Line> route = new ArrayList<Line>(); route.add(startLine); result = new RouteSearchResult(RouteSearchReturnCode.INTERMEDIATE_FOUND, route, location.get(1), 1); } else { IntermediateHandler iHandler = new IntermediateHandler(location); RouteSearchData data = new RouteSearchData(); Node e = destLine.getEndNode(); destX = e.getLongitudeDeg(); destY = e.getLatitudeDeg(); int startLength = startLine.getLineLength(); PQElem startElem = new PQElem(startLine, 0, startLength, null); data.addToOpen(startElem); OpenLongHashSet locationIDs = new OpenLongHashSet(location.size()); for (Line l : location) { locationIDs.put(l.getID()); } while (!data.isOpenEmpty()) { PQElem actualElement = data.pollElement(); if (locationIDs.containsKey(actualElement.getLine().getID())) { result = iHandler.checkIntermediate(actualElement, data); if (result != null) { break; } } if (actualElement.getLine().getID() == destLine.getID()) { if (endLoopIndex >= 0) { List<Line> route = PathUtils .constructPath(actualElement.getPrevious()); result = new RouteSearchResult( RouteSearchReturnCode.INTERMEDIATE_FOUND, route, destLine, endLoopIndex); break; } else { List<Line> route = PathUtils .constructPath(actualElement); if (route.isEmpty()) { throw new OpenLREncoderProcessingException( EncoderProcessingError.ROUTE_CONSTRUCTION_ERROR); } else { result = new RouteSearchResult( RouteSearchResult.RouteSearchReturnCode.ROUTE_FOUND, route); break; } } } if (startLoopIndex > 0 && iHandler.getLastElemOnRoutePos() == startLoopIndex) { if (LOG.isDebugEnabled()) { LOG.debug("loop is traversed, intermediate found"); } List<Line> route = PathUtils.constructPath(actualElement.getPrevious()); result = new RouteSearchResult( RouteSearchReturnCode.INTERMEDIATE_FOUND, route, startLine, startLoopIndex); break; } extractNextLines(actualElement, data); } if (result == null) { result = new RouteSearchResult(RouteSearchReturnCode.NO_ROUTE_FOUND); } } return result; } }
RouteSearch { public final RouteSearchResult calculateRoute() throws OpenLREncoderProcessingException { if (LOG.isDebugEnabled()) { LOG.debug("route search between start (" + startLine.getID() + ") and dest (" + destLine.getID() + ")"); } RouteSearchResult result = null; if (startLine.getID() == destLine.getID() && location.size() > 1) { List<Line> route = new ArrayList<Line>(1); route.add(startLine); result = new RouteSearchResult( RouteSearchReturnCode.INTERMEDIATE_FOUND, route, location .get(1), 1); } else if (startLoopIndex == 0) { List<Line> route = new ArrayList<Line>(); route.add(startLine); result = new RouteSearchResult(RouteSearchReturnCode.INTERMEDIATE_FOUND, route, location.get(1), 1); } else { IntermediateHandler iHandler = new IntermediateHandler(location); RouteSearchData data = new RouteSearchData(); Node e = destLine.getEndNode(); destX = e.getLongitudeDeg(); destY = e.getLatitudeDeg(); int startLength = startLine.getLineLength(); PQElem startElem = new PQElem(startLine, 0, startLength, null); data.addToOpen(startElem); OpenLongHashSet locationIDs = new OpenLongHashSet(location.size()); for (Line l : location) { locationIDs.put(l.getID()); } while (!data.isOpenEmpty()) { PQElem actualElement = data.pollElement(); if (locationIDs.containsKey(actualElement.getLine().getID())) { result = iHandler.checkIntermediate(actualElement, data); if (result != null) { break; } } if (actualElement.getLine().getID() == destLine.getID()) { if (endLoopIndex >= 0) { List<Line> route = PathUtils .constructPath(actualElement.getPrevious()); result = new RouteSearchResult( RouteSearchReturnCode.INTERMEDIATE_FOUND, route, destLine, endLoopIndex); break; } else { List<Line> route = PathUtils .constructPath(actualElement); if (route.isEmpty()) { throw new OpenLREncoderProcessingException( EncoderProcessingError.ROUTE_CONSTRUCTION_ERROR); } else { result = new RouteSearchResult( RouteSearchResult.RouteSearchReturnCode.ROUTE_FOUND, route); break; } } } if (startLoopIndex > 0 && iHandler.getLastElemOnRoutePos() == startLoopIndex) { if (LOG.isDebugEnabled()) { LOG.debug("loop is traversed, intermediate found"); } List<Line> route = PathUtils.constructPath(actualElement.getPrevious()); result = new RouteSearchResult( RouteSearchReturnCode.INTERMEDIATE_FOUND, route, startLine, startLoopIndex); break; } extractNextLines(actualElement, data); } if (result == null) { result = new RouteSearchResult(RouteSearchReturnCode.NO_ROUTE_FOUND); } } return result; } RouteSearch(final List<? extends Line> loc); }
RouteSearch { public final RouteSearchResult calculateRoute() throws OpenLREncoderProcessingException { if (LOG.isDebugEnabled()) { LOG.debug("route search between start (" + startLine.getID() + ") and dest (" + destLine.getID() + ")"); } RouteSearchResult result = null; if (startLine.getID() == destLine.getID() && location.size() > 1) { List<Line> route = new ArrayList<Line>(1); route.add(startLine); result = new RouteSearchResult( RouteSearchReturnCode.INTERMEDIATE_FOUND, route, location .get(1), 1); } else if (startLoopIndex == 0) { List<Line> route = new ArrayList<Line>(); route.add(startLine); result = new RouteSearchResult(RouteSearchReturnCode.INTERMEDIATE_FOUND, route, location.get(1), 1); } else { IntermediateHandler iHandler = new IntermediateHandler(location); RouteSearchData data = new RouteSearchData(); Node e = destLine.getEndNode(); destX = e.getLongitudeDeg(); destY = e.getLatitudeDeg(); int startLength = startLine.getLineLength(); PQElem startElem = new PQElem(startLine, 0, startLength, null); data.addToOpen(startElem); OpenLongHashSet locationIDs = new OpenLongHashSet(location.size()); for (Line l : location) { locationIDs.put(l.getID()); } while (!data.isOpenEmpty()) { PQElem actualElement = data.pollElement(); if (locationIDs.containsKey(actualElement.getLine().getID())) { result = iHandler.checkIntermediate(actualElement, data); if (result != null) { break; } } if (actualElement.getLine().getID() == destLine.getID()) { if (endLoopIndex >= 0) { List<Line> route = PathUtils .constructPath(actualElement.getPrevious()); result = new RouteSearchResult( RouteSearchReturnCode.INTERMEDIATE_FOUND, route, destLine, endLoopIndex); break; } else { List<Line> route = PathUtils .constructPath(actualElement); if (route.isEmpty()) { throw new OpenLREncoderProcessingException( EncoderProcessingError.ROUTE_CONSTRUCTION_ERROR); } else { result = new RouteSearchResult( RouteSearchResult.RouteSearchReturnCode.ROUTE_FOUND, route); break; } } } if (startLoopIndex > 0 && iHandler.getLastElemOnRoutePos() == startLoopIndex) { if (LOG.isDebugEnabled()) { LOG.debug("loop is traversed, intermediate found"); } List<Line> route = PathUtils.constructPath(actualElement.getPrevious()); result = new RouteSearchResult( RouteSearchReturnCode.INTERMEDIATE_FOUND, route, startLine, startLoopIndex); break; } extractNextLines(actualElement, data); } if (result == null) { result = new RouteSearchResult(RouteSearchReturnCode.NO_ROUTE_FOUND); } } return result; } RouteSearch(final List<? extends Line> loc); final RouteSearchResult calculateRoute(); @Override final String toString(); }
RouteSearch { public final RouteSearchResult calculateRoute() throws OpenLREncoderProcessingException { if (LOG.isDebugEnabled()) { LOG.debug("route search between start (" + startLine.getID() + ") and dest (" + destLine.getID() + ")"); } RouteSearchResult result = null; if (startLine.getID() == destLine.getID() && location.size() > 1) { List<Line> route = new ArrayList<Line>(1); route.add(startLine); result = new RouteSearchResult( RouteSearchReturnCode.INTERMEDIATE_FOUND, route, location .get(1), 1); } else if (startLoopIndex == 0) { List<Line> route = new ArrayList<Line>(); route.add(startLine); result = new RouteSearchResult(RouteSearchReturnCode.INTERMEDIATE_FOUND, route, location.get(1), 1); } else { IntermediateHandler iHandler = new IntermediateHandler(location); RouteSearchData data = new RouteSearchData(); Node e = destLine.getEndNode(); destX = e.getLongitudeDeg(); destY = e.getLatitudeDeg(); int startLength = startLine.getLineLength(); PQElem startElem = new PQElem(startLine, 0, startLength, null); data.addToOpen(startElem); OpenLongHashSet locationIDs = new OpenLongHashSet(location.size()); for (Line l : location) { locationIDs.put(l.getID()); } while (!data.isOpenEmpty()) { PQElem actualElement = data.pollElement(); if (locationIDs.containsKey(actualElement.getLine().getID())) { result = iHandler.checkIntermediate(actualElement, data); if (result != null) { break; } } if (actualElement.getLine().getID() == destLine.getID()) { if (endLoopIndex >= 0) { List<Line> route = PathUtils .constructPath(actualElement.getPrevious()); result = new RouteSearchResult( RouteSearchReturnCode.INTERMEDIATE_FOUND, route, destLine, endLoopIndex); break; } else { List<Line> route = PathUtils .constructPath(actualElement); if (route.isEmpty()) { throw new OpenLREncoderProcessingException( EncoderProcessingError.ROUTE_CONSTRUCTION_ERROR); } else { result = new RouteSearchResult( RouteSearchResult.RouteSearchReturnCode.ROUTE_FOUND, route); break; } } } if (startLoopIndex > 0 && iHandler.getLastElemOnRoutePos() == startLoopIndex) { if (LOG.isDebugEnabled()) { LOG.debug("loop is traversed, intermediate found"); } List<Line> route = PathUtils.constructPath(actualElement.getPrevious()); result = new RouteSearchResult( RouteSearchReturnCode.INTERMEDIATE_FOUND, route, startLine, startLoopIndex); break; } extractNextLines(actualElement, data); } if (result == null) { result = new RouteSearchResult(RouteSearchReturnCode.NO_ROUTE_FOUND); } } return result; } RouteSearch(final List<? extends Line> loc); final RouteSearchResult calculateRoute(); @Override final String toString();  }