@Override public CollisionGraphRoadModelImpl build( DependencyProvider dependencyProvider) { checkArgument(getDistanceUnit() == SI.METER, "Currently only %s is supported, found %s.", SI.METER, getDistanceUnit()); final double minConnectionLength = getVehicleLength(); checkArgument( getMinDistance() <= minConnectionLength, "Min distance must be smaller than 2 * vehicle length (%s), but is %s.", getVehicleLength(), getMinDistance()); final ListenableGraph<?> graph = getGraph(); for (final Connection<?> conn : graph.getConnections()) { CollisionGraphRoadModelImpl .checkConnectionLength(minConnectionLength, conn); } return new CollisionGraphRoadModelImpl(graph, minConnectionLength, this); }
/** * Returns a copy of this builder with the specified vehicle length. The * vehicle length defines the length of each vehicle added to the * {@link CollisionGraphRoadModel} that will be constructed by this builder. * The vehicle length must be a strictly positive number. The default value * is {@link #DEFAULT_VEHICLE_LENGTH}. * @param length A length expressed in the unit set by * {@link #withDistanceUnit(Unit)}. * @return A new builder instance. */ @CheckReturnValue public CollisionGraphRMB withVehicleLength(double length) { checkArgument(length > 0d, "Only positive vehicle lengths are allowed, found %s.", length); checkArgument(Doubles.isFinite(length), "%s is not a valid vehicle length.", length); return create(getDistanceUnit(), getSpeedUnit(), getGraphSupplier(), isModCheckEnabled(), length, getMinDistance()); }
.addModel(RoadModelBuilders.dynamicGraph(graph) .withCollisionAvoidance() .withDistanceUnit(SI.METER)) .addModel( View.builder()
.addModel(RoadModelBuilders.dynamicGraph(graph) .withCollisionAvoidance() .withDistanceUnit(SI.METER)) .addModel( View.builder()
dynamicGraph(new ListenableGraph<>(new TableGraph<>())) .withCollisionAvoidance() .withVehicleLength(7d)); assertThat(coll).isNotEqualTo( dynamicGraph(new ListenableGraph<>(new TableGraph<>())) .withCollisionAvoidance() .withDistanceUnit(NonSI.YARD));
assertEquals(0d, RoadModelBuilders.dynamicGraph(graph) .withCollisionAvoidance() .withMinDistance(0d) .withDistanceUnit(SI.METER) .build(mock(DependencyProvider.class)) .getMinDistance(), 0); .withDistanceUnit(SI.METER) .withCollisionAvoidance() .withMinDistance(2d) .build(mock(DependencyProvider.class)) RoadModelBuilders.dynamicGraph(graph) .withCollisionAvoidance() .withVehicleLength(1d) .withMinDistance(2.000000001) .build(mock(DependencyProvider.class)); } catch (final IllegalArgumentException e) { fail = true; final CollisionGraphRMB b = RoadModelBuilders.dynamicGraph(graph) .withCollisionAvoidance() .withMinDistance(-1d); } catch (final IllegalArgumentException e) { fail = true;
RoadModelBuilders.dynamicGraph(GraphCreator.createSimpleGraph()) .withCollisionAvoidance() .withDistanceUnit(SI.METER) .withVehicleLength(VEHICLE_LENGTH)) .addModel(viewBuilder) .build();
.withDistanceUnit(SI.METER) .withVehicleLength(2d) .withMinDistance(.25) .build(mock(DependencyProvider.class));
final CollisionGraphRMB b = RoadModelBuilders.dynamicGraph(graph) .withCollisionAvoidance() .withVehicleLength(0d); } catch (final IllegalArgumentException e) { fail = true; final CollisionGraphRMB b = RoadModelBuilders.dynamicGraph(graph) .withCollisionAvoidance() .withVehicleLength(Double.POSITIVE_INFINITY); } catch (final IllegalArgumentException e) { fail = true; .withDistanceUnit(SI.METER) .withVehicleLength(5d) .build(mock(DependencyProvider.class));
RoadModelBuilders.dynamicGraph(GraphCreator.createSimpleGraph()) .withCollisionAvoidance() .withDistanceUnit(SI.METER) .withVehicleLength(VEHICLE_LENGTH)) .addModel(viewBuilder) .build();
/** * Sets up a simple environment. */ @Before public void setUp() { final ListenableGraph<LengthData> graph = new ListenableGraph<>( new TableGraph<LengthData>()); NW = new Point(0, 0); NE = new Point(10, 0); SE = new Point(10, 10); SW = new Point(0, 10); Graphs.addBiPath(graph, NW, NE, SE, SW, NW); assertEquals(8, graph.getNumberOfConnections()); assertEquals(4, graph.getNumberOfNodes()); simulator = Simulator.builder() .setTickLength(1) .setTimeUnit(SI.SECOND) .addModel( RoadModelBuilders.dynamicGraph(graph) .withCollisionAvoidance() .withVehicleLength(1d) .withDistanceUnit(SI.METER) .withMinDistance(0) .withSpeedUnit(SI.METERS_PER_SECOND)) .addModel(DefaultPDPModel.builder()) .build(); rm = simulator.getModelProvider().getModel(CollisionGraphRoadModelImpl.class); pm = simulator.getModelProvider().getModel(DefaultPDPModel.class); }
/** * Some graphs are not compatible with {@link CollisionGraphRoadModelImpl}. */ @Test public void testDetectInvalidConnAtConstruction() { final ListenableGraph<?> g = new ListenableGraph<>( new TableGraph<LengthData>()); // this connection is allowed: g.addConnection(new Point(0, 0), new Point(1, 0)); // this connection is not allowed: g.addConnection(new Point(0, 0), new Point(.99, 0)); boolean fail = false; try { RoadModelBuilders.dynamicGraph(g) .withCollisionAvoidance() .withVehicleLength(1d) .withMinDistance(.25) .build(mock(DependencyProvider.class)); } catch (final IllegalArgumentException e) { fail = true; } assertTrue(fail); }
/** * Tests that vehicle length and min distance are set correctly (important * because they are both doubles). */ @Test @Ignore public void testCollisionGraphRMB() { final CollisionGraphRMB b = RoadModelBuilders .dynamicGraph(new ListenableGraph<>( new TableGraph<>())) .withCollisionAvoidance() .withVehicleLength(78d) .withMinDistance(3d); final double precision = 0.0000001; assertThat(b.getMinDistance()).isWithin(precision).of(3d); assertThat(b.getVehicleLength()).isWithin(precision).of(78d); final CollisionGraphRoadModel m = b.build(mock(DependencyProvider.class)); assertThat(m.getMinConnLength()).isWithin(precision) .of(b.getMinDistance()); assertThat(m.getVehicleLength()).isWithin(precision) .of(b.getVehicleLength()); }
/** * Set up a simple squared graph. */ @Before public void setUp() { graph = new ListenableGraph<>(new TableGraph<LengthData>()); model = RoadModelBuilders.dynamicGraph(graph) .withCollisionAvoidance() .withDistanceUnit(SI.METER) .withVehicleLength(1d) .withMinDistance(0) .build(mock(DependencyProvider.class)); NW = new Point(0, 0); NE = new Point(10, 0); SE = new Point(10, 10); SW = new Point(0, 10); Graphs.addBiPath(graph, NW, NE, SE, SW, NW); assertEquals(8, graph.getNumberOfConnections()); assertEquals(4, graph.getNumberOfNodes()); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof RoadModelBuilders.CollisionGraphRMB) { RoadModelBuilders.CollisionGraphRMB that = (RoadModelBuilders.CollisionGraphRMB) o; return (this.distanceUnit.equals(that.getDistanceUnit())) && (this.speedUnit.equals(that.getSpeedUnit())) && (this.graphSupplier.equals(that.getGraphSupplier())) && (this.modCheckEnabled == that.isModCheckEnabled()) && (Double.doubleToLongBits(this.vehicleLength) == Double.doubleToLongBits(that.getVehicleLength())) && (Double.doubleToLongBits(this.minDistance) == Double.doubleToLongBits(that.getMinDistance())); } return false; }
/** * Returns a copy of this builder with the specified min distance. The min * distance defines the minimum required distance between two vehicles. The * minimum distance must be a positive number ≤ to 2 * vehicle length. * The default value is {@link #DEFAULT_MIN_DISTANCE}. * @param dist A distance expressed in the unit set by * {@link #withDistanceUnit(Unit)}. * @return A new builder instance. */ @CheckReturnValue public CollisionGraphRMB withMinDistance(double dist) { checkArgument(dist >= 0d); return create(getDistanceUnit(), getSpeedUnit(), getGraphSupplier(), isModCheckEnabled(), getVehicleLength(), dist); }
static CollisionGraphRMB create(Unit<Length> distanceUnit, Unit<Velocity> speedUnit, Supplier<ListenableGraph<?>> graphSupplier, boolean isGmcEnabled, double vehicleLength, double minDistance) { return new AutoValue_RoadModelBuilders_CollisionGraphRMB(distanceUnit, speedUnit, graphSupplier, isGmcEnabled, vehicleLength, minDistance); } }
CollisionGraphRoadModelImpl(ListenableGraph<?> g, double pMinConnLength, RoadModelBuilders.CollisionGraphRMB builder) { super(g, builder); vehicleLength = unitConversion.toInDist(builder.getVehicleLength()); minDistance = unitConversion.toInDist(builder.getMinDistance()); minConnLength = unitConversion.toInDist(pMinConnLength); occupiedNodes = Multimaps.synchronizedSetMultimap(CategoryMap .<MovingRoadUser, Point>create()); getGraph().getEventAPI().addListener( new ModificationChecker(minConnLength), ListenableGraph.EventTypes.ADD_CONNECTION, ListenableGraph.EventTypes.CHANGE_CONNECTION_DATA); }
/** * Will return a new builder that constructs {@link CollisionGraphRoadModel} * instances instead of {@link DynamicGraphRoadModel} instances. Note that * all connections in the specified graph must have length * <code>2 * vehicleLength</code>, where vehicle length can be specified in * {@link CollisionGraphRMB#withVehicleLength(double)}. * @return A new {@link CollisionGraphRMB} instance. */ @CheckReturnValue public CollisionGraphRMB withCollisionAvoidance() { return CollisionGraphRMB.create(this); }
@Override public CollisionGraphRMB withModificationCheck(boolean enabled) { return create(getDistanceUnit(), getSpeedUnit(), getGraphSupplier(), enabled, getVehicleLength(), getMinDistance()); }