private Point findNearestDepot(Point from) { final Iterator<Point> it = depotLocations.iterator(); Point nearestDepot = it.next(); final double dist = Graphs.pathLength(roadModel.getShortestPathTo(from, nearestDepot)); while (it.hasNext()) { final Point cur = it.next(); final double d = Graphs.pathLength(roadModel.getShortestPathTo(from, cur)); if (d < dist) { nearestDepot = cur; } } return nearestDepot; } }
@Override public Measure<Double, Length> getDistanceOfPath(Iterable<Point> path) throws IllegalArgumentException { final List<Point> pathAsList = Lists.newArrayList(path); checkArgument(pathAsList.size() > 1, "Cannot evaluate the distance of a path with less than two points."); return Measure.valueOf(Graphs.pathLength(pathAsList), getDistanceUnit()); }
public void compatibilityCheck(List<Point> t) { final MovingRoadUser truck = new TrivialRoadUser(); rm.addObjectAt(truck, t.get(0)); final double len = pathLength(t); // speed of trivial truck is 1 len per hour thus we need to travel 'len' // hours final MoveProgress progress = rm.followPath( truck, new LinkedList<Point>(t), TimeLapseFactory.create(NonSI.HOUR, 0, DoubleMath.roundToLong(len, RoundingMode.CEILING))); assertEquals(len, progress.distance().getValue(), EPSILON); }