@Override public double calculateCost(Graph<?> graph, Point from, Point to) { final double speed = getSpeed(graph, from, to); final double length = graph.connectionLength(from, to); // Potential metric conflict, shouldn't affect relative outcome return length / speed; }
@Override public void merge(Graph<E> other) { for (final Connection<E> connection : other.getConnections()) { addConnection(connection); } }
/** * @return The length of this connection as specified by the data or * alternatively by the euclidean distance between the two points. */ public double getLength() { if (data().isPresent() && data().get().getLength().isPresent()) { return data().get().getLength().get(); } return Point.distance(from(), to()); }
@Override public void addConnection(Connection<E> c) { addConnection(c.from(), c.to(), c.data()); }
@Test(expected = UnsupportedOperationException.class) public void unmodAddConn() { Graphs.unmodifiableGraph(graph).addConnection(new Point(1, 2), new Point(2, 3)); }
@Override public void addConnection(Point from, Point to, E connData) { delegate.addConnection(from, to, connData); eventDispatcher.dispatchEvent(new GraphEvent(EventTypes.ADD_CONNECTION, this, getConnection(from, to))); }
Graph<?> createGraph() { final Graph<?> g = new MultimapGraph<>(); g.addConnection(SW, SE); g.addConnection(SE, NE); g.addConnection(NE, NW); return g; }
/** * Computes the shortest path based on the Euclidean distance. * @param graph The {@link Graph} on which the shortest path is searched. * @param from The start point of the path. * @param to The destination of the path. * @param <E> The type of connection data. * @return The shortest path that exists between <code>from</code> and * <code>to</code>. */ public static <E extends ConnectionData> List<Point> shortestPathEuclideanDistance( Graph<E> graph, final Point from, final Point to) { return Graphs.shortestPath(graph, from, to, GeomHeuristics.euclidean()); }
@Override public Optional<E> setConnectionData(Point from, Point to, E connectionData) { final Optional<E> val = delegate.setConnectionData(from, to, connectionData); eventDispatcher.dispatchEvent(new GraphEvent( EventTypes.CHANGE_CONNECTION_DATA, this, getConnection(from, to))); return val; }
@Override public Optional<E> removeConnectionData(Point from, Point to) { final Optional<E> val = delegate.removeConnectionData(from, to); eventDispatcher.dispatchEvent(new GraphEvent( EventTypes.CHANGE_CONNECTION_DATA, this, getConnection(from, to))); return val; }
@Override public void merge(Graph<E> other) { addConnections(other.getConnections()); }
@Override public void addConnection(Point from, Point to) { delegate.addConnection(from, to); eventDispatcher.dispatchEvent(new GraphEvent(EventTypes.ADD_CONNECTION, this, getConnection(from, to))); }
@Override public void merge(Graph<E> other) { for (final Connection<E> connection : other.getConnections()) { addConnection(connection); } }
@Override public Optional<E> removeConnectionData(Point from, Point to) { final Optional<E> val = delegate.removeConnectionData(from, to); eventDispatcher.dispatchEvent(new GraphEvent( EventTypes.CHANGE_CONNECTION_DATA, this, getConnection(from, to))); return val; }
@Override public void merge(Graph<E> other) { addConnections(other.getConnections()); }
@Override public double calculateCost(Graph<?> graph, Point from, Point to) { final double speed = getSpeed(graph, from, to); final double length = graph.connectionLength(from, to); // Potential metric conflict, shouldn't affect relative outcome return length / speed; }
@Override public void addConnection(Point from, Point to, E connData) { delegate.addConnection(from, to, connData); eventDispatcher.dispatchEvent(new GraphEvent(EventTypes.ADD_CONNECTION, this, getConnection(from, to))); }