@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); }
@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); }
/** * 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()); }
@Override public CollisionGraphRMB withSpeedUnit(Unit<Velocity> unit) { return create(getDistanceUnit(), unit, getGraphSupplier(), isModCheckEnabled(), getVehicleLength(), getMinDistance()); }
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); }
@Override public CollisionGraphRMB withDistanceUnit(Unit<Length> unit) { return create(unit, getSpeedUnit(), getGraphSupplier(), isModCheckEnabled(), getVehicleLength(), getMinDistance()); }
@Override public CollisionGraphRMB withModificationCheck(boolean enabled) { return create(getDistanceUnit(), getSpeedUnit(), getGraphSupplier(), enabled, getVehicleLength(), getMinDistance()); }