static void checkConnectionLength(double minConnLength, Connection<?> conn) { checkArgument( Point.distance(conn.from(), conn.to()) >= minConnLength, "Invalid graph: the minimum connection length is %s, connection %s->%s" + " is too short.", minConnLength, conn.from(), conn.to()); checkArgument( conn.getLength() >= minConnLength, "Invalid graph: the minimum connection length is %s, connection %s->%s " + "defines length data that is too short: %s.", minConnLength, conn.from(), conn.to(), conn.getLength()); }
@Nonnull final Double factor = behaviourSupplier.get(rng.nextLong()) .apply(distance + conn.getLength() / 2); final Double factorInverse = 1 / factor; @Nonnull (long) (relExpandingTimestamp + conn.getLength() / forwardSpeed); nextActualExTimestamp = (long) (actualExpandingTimestamp + conn.getLength() / forwardSpeed); (long) (relRecedingTimestamp + conn.getLength() / recedingSpeed); nextActualReTimestamp = (long) (actualRecedingTimestamp + conn.getLength() / recedingSpeed); nextRelExTimestamp, nextRelReTimestamp, nextActualExTimestamp, nextActualReTimestamp, distance + conn.getLength(), scenarioLength));
conn.getLength(), roadModel.getDistanceUnit()); try { travelTime +=
@Override public double calculateTravelTime(Graph<?> graph, Point from, Point to, Unit<Length> distanceUnit, Measure<Double, Velocity> speed, Unit<Duration> outputTimeUnit) { final Measure<Double, Length> distance = Measure .valueOf(graph.getConnection(from, to).getLength(), distanceUnit); return Measure.valueOf(distance.doubleValue(SI.METER) // divided by m/s / speed.doubleValue(SI.METERS_PER_SECOND), // gives seconds SI.SECOND) // convert to desired unit .doubleValue(outputTimeUnit); } }
@Override public double calculateTravelTime(Graph<?> graph, Point from, Point to, Unit<Length> distanceUnit, Measure<Double, Velocity> speed, Unit<Duration> outputTimeUnit) { final Measure<Double, Length> distance = Measure .valueOf(graph.getConnection(from, to).getLength(), distanceUnit); return Measure.valueOf(distance.doubleValue(SI.METER) // divided by m/s / speed.doubleValue(SI.METERS_PER_SECOND), // gives seconds SI.SECOND) // convert to desired unit .doubleValue(outputTimeUnit); } }
/** * Compute distance between the two specified points, both of which need to be * on the same connection (or are equal). If points are equal the distance is * 0. This method uses length stored in {@link ConnectionData} objects when * available. * @param from Start of the connection. * @param to End of the connection. * @return the distance between two points, must be ≥ 0. * @throws IllegalArgumentException when two points are part of the graph but * are not equal or there is no connection between them */ protected double computeDistanceOnConnection(Point from, Point to) { if (from.equals(to)) { return 0; } final boolean fromIsOnConn = registry().isOnConnection(from); final boolean toIsOnConn = registry().isOnConnection(to); final Connection<?> conn = getConnection(from, to); if (fromIsOnConn && toIsOnConn) { return Math.abs(registry().getRelativePosition(from) - registry().getRelativePosition(to)); } else if (fromIsOnConn) { return conn.getLength() - registry().getRelativePosition(from); } else if (toIsOnConn) { return registry().getRelativePosition(to); } return conn.getLength(); }
public Point addAt(T obj, Connection<?> conn, double relPos, double precision) { final Point diff = Point.diff(conn.to(), conn.from()); final double perc = relPos / conn.getLength(); final Point pos; final ConnLoc connLoc; if (perc + precision >= 1) { connLoc = null; pos = conn.to(); } else { pos = new Point( conn.from().x + perc * diff.x, conn.from().y + perc * diff.y); connLoc = ConnLoc.create(pos, conn, relPos); } addAt(obj, pos, connLoc); return pos; }
/ Point.distance(conn.from(), conn.to()); stats.totalDistance += vso.getConnection().get().getLength()
/** * Tests correct implementation of get length. */ @Test public void testGetLength() { final Point a = new Point(0, 0); final Point b = new Point(10, 0); assertEquals(10, Connection.create(a, b).getLength(), GraphRoadModelImpl.DELTA); final Connection<MultiAttributeData> conn = Connection.create(a, b, MultiAttributeData.builder() .setLength(12) .setMaxSpeed(1d) .build()); assertEquals(12, conn.getLength(), GraphRoadModelImpl.DELTA); final Connection<MultiAttributeData> conn2 = Connection.create(a, b, MultiAttributeData.builder() .setMaxSpeed(1d) .build()); assertEquals(10, conn2.getLength(), GraphRoadModelImpl.DELTA); } }
relPos - (conn.getLength() - vehicleLength - minDistance);