PDPGraphRoadModel.builderForGraphRm( RoadModelBuilders.staticGraph(g) .withDistanceUnit(SI.METER) .withSpeedUnit(SI.METERS_PER_SECOND)) .withAllowVehicleDiversion(true) .build(graphdp);
/** * Tests that unregistering an not registered object fails. */ @Test public void unregisterFailNotRegisteredObject() { final ModelManager mm = new ModelManager( ImmutableSet.of( RoadModelBuilders.staticGraph(new MultimapGraph<LengthData>()) .build(mock(DependencyProvider.class)), RoadModelBuilders.staticGraph(new MultimapGraph<LengthData>()) .build(mock(DependencyProvider.class)))); boolean fail = false; try { mm.unregister(new RoadUser() { @Override public void initRoadUser(RoadModel model) {} }); } catch (final IllegalArgumentException e) { fail = true; } assertTrue(fail); }
/** * Construct a new {@link RoadModelBuilders.StaticGraphRMB} for creating a * {@link GraphRoadModel}. * @param graph The graph which will be used as road structure. * @return A new {@link RoadModelBuilders.StaticGraphRMB}. */ public static RoadModelBuilders.StaticGraphRMB staticGraph(Graph<?> graph) { return StaticGraphRMB.create(Suppliers.ofInstance(graph)); }
.withDistanceUnit(SI.KILOMETER) .withSpeedUnit(NonSI.KILOMETERS_PER_HOUR)) .withAllowVehicleDiversion(allowDiversion) .build(dep);
graph = rmType.newInstance(); rm = RoadModelBuilders.staticGraph(graph) .build(mock(DependencyProvider.class));
final DependencyProvider graphdp = mock(DependencyProvider.class); final PDPRoadModel graphRm = PDPGraphRoadModel.builderForGraphRm( RoadModelBuilders.staticGraph(g).withDistanceUnit(SI.METER) .withSpeedUnit(SI.METERS_PER_SECOND)) .withAllowVehicleDiversion(true) .build(graphdp);
@SuppressWarnings("unchecked") @Test public void getMaxSpeed() { final Point A = new Point(0, 0); final Point B = new Point(10, 0); final Graph<LengthData> g = new MultimapGraph<>(); final GraphRoadModelImpl rm = RoadModelBuilders.staticGraph(g).build( mock(DependencyProvider.class)); g.addConnection(A, B, LengthData.create(3)); final UnitConverter conv = NonSI.KILOMETERS_PER_HOUR .getConverterTo(RoadUnits.INTERNAL_SPEED_UNIT); assertEquals(conv.convert(10), rm.getMaxSpeed(new SpeedyRoadUser(10), A, B), EPSILON); ((Graph<MultiAttributeData>) graph).addConnection(SE, SW, MultiAttributeData.builder().setLength(3).setMaxSpeed(5d).build()); assertEquals(conv.convert(5), model.getMaxSpeed(new SpeedyRoadUser(10), SE, SW), EPSILON); ((Graph<MultiAttributeData>) graph).addConnection(NE, SE, MultiAttributeData.builder().setLength(3).build()); assertEquals(conv.convert(10), model.getMaxSpeed(new SpeedyRoadUser(10), NE, SE), EPSILON); }
/** * Tests that an exception thrown by a model during unregister bubbles up. */ @Test public void unregisterWithBrokenModel() { final ModelManager mm = new ModelManager( ImmutableSet.of(RoadModelBuilders.staticGraph( new MultimapGraph<LengthData>()) .build(mock(DependencyProvider.class)), new BrokenRoadModel(new MultimapGraph<LengthData>()))); boolean fail = false; try { mm.unregister(new RoadUser() { @Override public void initRoadUser(RoadModel model) {} }); } catch (final RuntimeException e) { fail = true; } assertThat(fail).isTrue(); }
@Test public void moveToHeuristicTest() { final MovingRoadUser fastestPathAgent = new SpeedyRoadUser(10); final MovingRoadUser shortestPathAgent = new SpeedyRoadUser(10); final Point origin = new Point(0, 0); final Point destination = new Point(0, 10); final Point midway = new Point(5, 5); // Graph with slow direct (shortest) route, but fast longer route. final Graph<MultiAttributeData> graph = new TableGraph<>(); graph.addConnection(origin, destination, MultiAttributeData.builder().setLength(10).setMaxSpeed(1).build()); graph.addConnection(origin, midway, MultiAttributeData.builder().setLength(10).setMaxSpeed(10).build()); graph.addConnection(midway, destination, MultiAttributeData.builder().setLength(10).setMaxSpeed(10).build()); final RoadModel moveModel = RoadModelBuilders.staticGraph(graph) .withDistanceUnit(SI.KILOMETER).withSpeedUnit(NonSI.KILOMETERS_PER_HOUR) .build(mock(DependencyProvider.class)); moveModel.addObjectAt(fastestPathAgent, origin); moveModel.addObjectAt(shortestPathAgent, origin); moveModel.moveTo(fastestPathAgent, destination, hour(1), GeomHeuristics.time(10)); moveModel.moveTo(shortestPathAgent, destination, hour(1), GeomHeuristics.euclidean()); // Agent chose speedy route assertEquals(midway, moveModel.getPosition(fastestPathAgent)); // Agent chose shortest route assertEquals(new Point(0, 1), moveModel.getPosition(shortestPathAgent)); }
/** * Tests that exception thrown by the broken model bubbles up. */ @Test(expected = RuntimeException.class) public void registerWithBrokenModel() { final ModelManager mm = new ModelManager(ImmutableSet.of( RoadModelBuilders.staticGraph( new MultimapGraph<LengthData>()) .build(mock(DependencyProvider.class)), new BrokenRoadModel(new MultimapGraph<LengthData>()))); mm.register(new RoadUser() { @Override public void initRoadUser(RoadModel model) {} }); }
static StaticGraphRMB create(Supplier<? extends Graph<?>> graph) { return create(DEFAULT_DISTANCE_UNIT, DEFAULT_SPEED_UNIT, graph); }
StaticGraphRMB() { setProvidingTypes(RoadModel.class, GraphRoadModel.class); }
@Override public StaticGraphRMB withSpeedUnit(Unit<Velocity> unit) { return create(getDistanceUnit(), unit, getGraphSupplier()); }
@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); }
/** * A model can not be registered. */ @Test(expected = IllegalArgumentException.class) public void canNotRegisterModel() { emptyManager.register(RoadModelBuilders.staticGraph( new MultimapGraph<LengthData>()).build(mock(DependencyProvider.class))); }
@Override public GraphRoadModelImpl build(DependencyProvider dependencyProvider) { return new GraphRoadModelImpl(getGraph(), this); }
@Override public GenericRoadModel create(ForwardingRoadModelTest testClass) { return new ForwardingRoadModel(new ForwardingRoadModel( new ForwardingRoadModel(RoadModelBuilders.staticGraph(testClass .createGraph()).build(mock(DependencyProvider.class))))); } }}});
@Override public GenericRoadModel create(ForwardingRoadModelTest testClass) { return new ForwardingRoadModel(RoadModelBuilders.staticGraph(testClass .createGraph()).build(mock(DependencyProvider.class))); } }}, {new Creator() {
/** * Construct a new {@link RoadModelBuilders.StaticGraphRMB} for creating a * {@link GraphRoadModel}. * @param graphSupplier The supplier that creates a graph that will be used as * road structure. * @return A new {@link RoadModelBuilders.StaticGraphRMB}. */ public static RoadModelBuilders.StaticGraphRMB staticGraph( Supplier<? extends Graph<?>> graphSupplier) { return StaticGraphRMB.create(graphSupplier); }
@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()); }