@Override protected void checkMoveValidity(Point objLoc, Point nextHop) { super.checkMoveValidity(objLoc, nextHop); // check if there is a vehicle driving in the opposite direction if (!objLoc.equals(nextHop)) { final Connection<?> conn = getConnection(objLoc, nextHop); if (graph.hasConnection(conn.to(), conn.from()) && registry() .hasObjectOn(Connection.create(conn.to(), conn.from()))) { throw new DeadlockException(conn); } } }
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()); }
@Override public Connection<E> getConnection(Point from, Point to) { return Connection.create(from, to); }
@Nullable MultiAttributeData getData(Graph<?> graph, Point from, Point to) { if (graph.hasConnection(from, to)) { final Connection<?> conn = graph.getConnection(from, to); safeToCast = lastGraph == graph && safeToCast; lastGraph = graph; if (conn.data().isPresent() && (safeToCast || conn.data().get() instanceof MultiAttributeData)) { safeToCast = true; return (MultiAttributeData) conn.data().get(); } } return null; }
/** * 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); } }
@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); } }
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; }
/** * Create a new connection. * @param from The starting point of the connection. * @param to The end point of the connection. * @param data The data associated to the connection. * @param <E> The type of {@link ConnectionData}. * @return A new {@link Connection} instance. */ public static <E extends ConnectionData> Connection<E> create(Point from, Point to, E data) { return create(from, to, Optional.of(data)); }
@Nullable MultiAttributeData getData(Graph<?> graph, Point from, Point to) { if (graph.hasConnection(from, to)) { final Connection<?> conn = graph.getConnection(from, to); safeToCast = lastGraph == graph && safeToCast; lastGraph = graph; if (conn.data().isPresent() && (safeToCast || conn.data().get() instanceof MultiAttributeData)) { safeToCast = true; return (MultiAttributeData) conn.data().get(); } } return null; }
@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); } }
connA = Connection.create(A, B, MultiAttributeData.builder().setMaxSpeed(100).build()); connB = Connection.create(B, C, MultiAttributeData.builder().setMaxSpeed(100).build()); connC = Connection.create(C, D, MultiAttributeData.builder().setMaxSpeed(100).build()); connD = Connection.create(D, E, MultiAttributeData.builder().setMaxSpeed(100).build()); connE = Connection.create(E, F, MultiAttributeData.builder().setMaxSpeed(100).build()); assertEquals(conns.get(i).from(), event.getFrom()); assertEquals(conns.get(i).to(), event.getTo()); assertEquals(factors[i], event.getFactor(), DELTA);
@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); .getIncomingConnections(conn.from()); && nextFroms.iterator().next().equals(conn.to())) { leafNodes.add(conn); return events; if (nextFrom.equals(conn.to())) { graph.get().getConnection(nextFrom, conn.from()); shockwave.offer(new ShockwaveSimulation(shockwave, conn, nextConn, nextRelExTimestamp, nextRelReTimestamp, nextActualExTimestamp, nextActualReTimestamp, distance + conn.getLength(), scenarioLength));