@Override public Graph<? extends ConnectionData> getGraph() { return grm.getGraph(); }
@Override public Optional<? extends Connection<?>> getConnection(RoadUser obj) { return grm.getConnection(obj); }
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 long getShortestTravelTime(Point from, Point to) { final Iterator<Point> path = roadModel.getShortestPathTo(from, to) .iterator(); @SuppressWarnings("unchecked") final Connection<T> conn = (Connection<T>) roadModel.getGraph().getConnection(prev, cur); conn.getLength(), roadModel.getDistanceUnit()); try { travelTime += Measure.valueOf( ((MultiAttributeData) conn.data().get()).getMaxSpeed().get(), roadModel.getSpeedUnit()), distance, timeUnit)); } catch (final Exception e) {
GraphTravelTimes(GraphRoadModel rm, Unit<Duration> tu, Point centerMostPoint, Iterator<Vehicle> vehicles) { roadModel = rm; double max = 0; while (vehicles.hasNext()) { final Vehicle v = vehicles.next(); max = Math.max(max, v.getDTO().getSpeed()); } vehicleSpeed = Measure.valueOf(max, roadModel.getSpeedUnit()); depotLocations = ImmutableList.of(centerMostPoint); this.timeUnit = tu; }
GraphTravelTimes(GraphRoadModel rm, Unit<Duration> tu, Iterable<? extends AddDepotEvent> depots, Iterable<? extends AddVehicleEvent> vehicles) { roadModel = rm; double max = 0; for (final AddVehicleEvent ave : vehicles) { max = Math.max(max, ave.getVehicleDTO().getSpeed()); } vehicleSpeed = Measure.valueOf(max, roadModel.getSpeedUnit()); final ImmutableList.Builder<Point> depotBuilder = ImmutableList.builder(); for (final AddDepotEvent ade : depots) { depotBuilder.add(ade.getPosition()); } depotLocations = depotBuilder.build(); timeUnit = tu; }
@Override public Graph<? extends ConnectionData> getGraph() { return grm.getGraph(); }
@Override public Optional<? extends Connection<?>> getConnection(RoadUser obj) { return grm.getConnection(obj); }
@Override public Optional<ViewRect> getViewRect() { checkState(!model.getGraph().isEmpty(), "graph may not be empty at this point"); final List<Point> extremes = Graphs.getExtremes(model.getGraph()); return Optional.of(new ViewRect( PointUtil.sub(extremes.get(0), margin), PointUtil.add(extremes.get(1), margin))); }
conn = ((GraphRoadModel) rm).getConnection(vehicle);
((GraphRoadModel) graphRm).getConnection(mv1);
@Test(expected = RuntimeException.class) public void impossiblePath() throws InstantiationException, IllegalAccessException { final Graph<?> gg = rmType.newInstance(); final GraphRoadModel roads = RoadModelBuilders.staticGraph(gg).build( mock(DependencyProvider.class)); gg.addConnection(a, b); gg.addConnection(b, c); Graphs.shortestPathEuclideanDistance(roads.getGraph(), b, a); }
@Test public void getGraphTest() { final Graph<ConnectionData> g = new MultimapGraph<ConnectionData>(); g.addConnection(NE, SW); g.addConnection(SW, NW); final GraphRoadModel rm = RoadModelBuilders.staticGraph(g) .withDistanceUnit(SI.METER) .withSpeedUnit(SI.METERS_PER_SECOND) .build(mock(DependencyProvider.class)); assertEquals(g, rm.getGraph()); g.addConnection(NE, NW); assertEquals(g, rm.getGraph()); }
@Override public void renderStatic(GC gc, ViewPort vp) { helper.adapt(gc, vp); final Graph<? extends ConnectionData> graph = model.getGraph();
sim.getModelProvider().getModel(GraphRoadModel.class).getGraph(); assertThat(graphInSim).isEqualTo(g);