本文整理了Java中com.github.rinde.rinsim.geom.Graph
类的一些代码示例,展示了Graph
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph
类的具体详情如下:
包路径:com.github.rinde.rinsim.geom.Graph
类名称:Graph
[英]Common interface for graphs (V,E). Nodes are represented by Points and connections are represented by Connections. Graphs are directed.
[中]图(V,E)的公共接口。节点由点表示,连接由连接表示。图形是有方向的。
代码示例来源:origin: com.github.rinde/rinsim-geom
@Override
public void addConnection(Point from, Point to) {
delegate.addConnection(from, to);
}
代码示例来源:origin: rinde/RinSim
@Override
public Set<Point> getNodes() {
return delegate.getNodes();
}
代码示例来源:origin: com.github.rinde/rinsim-geom
@Override
public Point getRandomNode(RandomGenerator generator) {
return delegate.getRandomNode(generator);
}
代码示例来源:origin: rinde/RinSim
@Override
public void removeConnection(Point from, Point to) {
final Connection<?> conn = delegate.getConnection(from, to);
delegate.removeConnection(from, to);
eventDispatcher
.dispatchEvent(new GraphEvent(
EventTypes.REMOVE_CONNECTION, this, conn));
}
代码示例来源:origin: com.github.rinde/rinsim-geom
@Override
public void removeNode(Point node) {
// collect data of removed connections but only if there is a listener
final List<Connection<?>> removedConnections = newArrayList();
if (eventDispatcher.hasListenerFor(EventTypes.REMOVE_CONNECTION)) {
for (final Point p : delegate.getIncomingConnections(node)) {
removedConnections.add(delegate.getConnection(p, node));
}
for (final Point p : delegate.getOutgoingConnections(node)) {
removedConnections.add(delegate.getConnection(node, p));
}
}
delegate.removeNode(node);
// notify listeners
for (final Connection<?> c : removedConnections) {
eventDispatcher.dispatchEvent(new GraphEvent(
EventTypes.REMOVE_CONNECTION, this, c));
}
}
代码示例来源:origin: rinde/RinSim
assertEquals(6, graph.getNodes().size());
assertTrue(graph.containsNode(n0));
assertTrue(graph.containsNode(n1));
assertTrue(graph.containsNode(n2));
assertTrue(graph.containsNode(n3));
assertTrue(graph.containsNode(n19663));
assertTrue(graph.containsNode(n16767));
assertEquals(8, graph.getConnections().size());
assertTrue(graph.hasConnection(n0, n1));
assertTrue(graph.hasConnection(n0, n19663));
assertTrue(graph.hasConnection(n0, n16767));
assertTrue(graph.hasConnection(n1, n0));
assertTrue(graph.hasConnection(n1, n2));
assertTrue(graph.hasConnection(n2, n1));
assertTrue(graph.hasConnection(n2, n3));
assertTrue(graph.hasConnection(n3, n2));
assertEquals(1.4, graph.getConnection(n0, n1).data().get().getLength()
.get().doubleValue(), 0);
assertEquals(.8, graph.getConnection(n0, n19663).data().get().getLength()
.get().doubleValue(), 0);
assertEquals(1.0, graph.getConnection(n0, n16767).data().get().getLength()
.get().doubleValue(), 0);
assertEquals(1.4, graph.getConnection(n1, n0).data().get().getLength()
.get().doubleValue(), 0);
assertEquals(1.6, graph.getConnection(n1, n2).data().get().getLength()
.get().doubleValue(), 0);
assertEquals(1.6, graph.getConnection(n2, n1).data().get().getLength()
代码示例来源:origin: rinde/RinSim
@Test
public void unmodifiable() {
final Point N = new Point(0, 5);
final Point E = new Point(5, 0);
final Point S = new Point(0, -5);
final Point W = new Point(-5, 0);
Graphs.addBiPath(graph, N, E, S, W, N);
final Graph<LengthData> g = Graphs.unmodifiableGraph(graph);
g.hashCode();
assertEquals(graph, g);
assertEquals(g, graph);
assertFalse(g.equals(new Object()));
assertFalse(g.isEmpty());
for (final Point p : g.getNodes()) {
assertArrayEquals(graph.getIncomingConnections(p).toArray(), g
.getIncomingConnections(p).toArray());
}
for (final Connection<LengthData> c : g.getConnections()) {
assertEquals(graph.connectionLength(c.from(), c.to()),
g.connectionLength(c.from(), c.to()), DELTA);
}
}
代码示例来源:origin: rinde/RinSim
affectedGraph.addConnection(conn);
.getIncomingConnections(conn.from());
graph.get().getConnection(nextFrom, conn.from());
shockwave.offer(new ShockwaveSimulation(shockwave, conn, nextConn,
nextRelExTimestamp, nextRelReTimestamp, nextActualExTimestamp,
代码示例来源:origin: com.github.rinde/rinsim-geom
@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;
}
代码示例来源:origin: rinde/RinSim
@Test
public void isEmtpy() {
assertTrue(graph.isEmpty());
graph.addConnection(new Point(0, 0), new Point(1, 0));
assertFalse(graph.isEmpty());
graph.removeConnection(new Point(0, 0), new Point(1, 0));
assertTrue(graph.isEmpty());
}
代码示例来源:origin: rinde/RinSim
@Test
public void connDataUsage() {
final Point A = new Point(0, 0), B = new Point(0, 1), C = new Point(1, 0);
graph.addConnection(A, B);
graph.addConnection(Connection.create(B, A, LengthData.create(1.5)));
graph.addConnection(B, C, LengthData.create(2));
// explicit empty value
graph.addConnection(A, C);
assertFalse("existing but empty", graph.connectionData(A, B).isPresent());
assertFalse("non existing", graph.connectionData(C, A).isPresent());
assertTrue("existing B->A", graph.connectionData(B, A).isPresent());
assertTrue("existing B->C", graph.connectionData(B, C).isPresent());
// use of the connection data
assertEquals(1, graph.connectionLength(A, B), DELTA);
assertEquals(1.5, graph.connectionLength(B, A), DELTA);
assertEquals(2, graph.connectionLength(B, C), DELTA);
try {
graph.connectionLength(C, B);
fail();
} catch (final IllegalArgumentException e) {}
}
代码示例来源:origin: rinde/RinSim
@Test
public void unmodifiable2() {
final Point N = new Point(0, 5);
final Point E = new Point(5, 0);
final Point S = new Point(0, -5);
final Point W = new Point(-5, 0);
Graphs.addBiPath(graph, N, E, S, W, N);
final Graph<LengthData> unmod = Graphs.unmodifiableGraph(graph);
graph.addConnection(N, S);
assertEquals(graph.getConnection(N, S), unmod.getConnection(N, S));
}
代码示例来源:origin: rinde/RinSim
private void drawNodes() {
for (final Point p : graph.getNodes()) {
if (showNodes) {
adapter.setBackgroundSysCol(SWT.COLOR_RED);
conns.addAll(graph.getIncomingConnections(p));
conns.addAll(graph.getOutgoingConnections(p));
代码示例来源:origin: rinde/RinSim
@Test
public void incomingConnectionsOrder() {
final Point incoming = new Point(0, 0);
final Point p0 = new Point(1, 0);
final Point p1 = new Point(2, 0);
final Point p2 = new Point(3, 0);
final Point p3 = new Point(4, 0);
final Point p4 = new Point(5, 0);
final Point p5 = new Point(6, 0);
final List<Point> points = Arrays.asList(p0, p1, p2, p3, p4, p5);
for (final Point p : points) {
graph.addConnection(p, incoming);
}
final List<Point> incomingConn = new ArrayList<Point>(
graph.getIncomingConnections(incoming));
for (int i = 0; i < incomingConn.size(); i++) {
assertSame(incomingConn.get(i), points.get(i));
}
}
代码示例来源:origin: rinde/RinSim
@Override
public <T extends ConnectionData> boolean hasConnection(
Connection<T> connection) {
return delegate.hasConnection(connection);
}
代码示例来源:origin: rinde/RinSim
@Test
public void removeNode() {
final Point N = new Point(0, 5);
final Point E = new Point(5, 0);
final Point S = new Point(0, -5);
final Point W = new Point(-5, 0);
Graphs.addBiPath(graph, N, E, S, W, N);
final Graph<LengthData> unmod = Graphs.unmodifiableGraph(graph);
assertEquals(graph, unmod);
assertEquals(4, graph.getNodes().size());
assertEquals(8, graph.getConnections().size());
graph.removeNode(N);
assertEquals(graph, unmod);
assertEquals(3, graph.getNodes().size());
assertEquals(4, graph.getConnections().size());
}
代码示例来源:origin: rinde/RinSim
private void checkAssertions(Point A, Point B, Point C, Point D) {
// contain nodes
assertTrue("contains A", graph.containsNode(A));
assertTrue("contains B", graph.containsNode(B));
assertTrue("contains C", graph.containsNode(C));
assertTrue("contains D", graph.containsNode(D));
assertTrue("connection A->B", graph.hasConnection(A, B));
assertTrue("connection B->C", graph.hasConnection(B, C));
assertTrue("connection B->D", graph.hasConnection(B, D));
assertFalse("!connection B->A", graph.hasConnection(B, A));
assertFalse("!connection C->B", graph.hasConnection(A, C));
assertFalse("!connection D->B", graph.hasConnection(A, D));
assertFalse("!connection A->C", graph.hasConnection(A, C));
assertFalse("!connection A->D", graph.hasConnection(A, D));
}
代码示例来源:origin: rinde/RinSim
for (final Point p : graph.getNodes()) {
string.append(NODE_PREFIX)
.append(nodeId)
for (final Connection<E> entry : graph.getConnections()) {
string.append(NODE_PREFIX)
.append(idMap.get(entry.from()))
代码示例来源:origin: rinde/RinSim
@Override
public void doSetUp() {
model = supplier.build(mock(DependencyProvider.class));
graph = model.graph;
// graph.addConnection(SW, SE);
// graph.addConnection(SE, NE);
// graph.addConnection(NE, NW);
final Set<Point> points = graph.getNodes();
assertEquals(4, points.size());
assertTrue(points.contains(SW));
assertTrue(points.contains(SE));
assertTrue(points.contains(NE));
assertEquals(3, graph.getNumberOfConnections());
assertEquals(4, graph.getNumberOfNodes());
}
代码示例来源:origin: com.github.rinde/rinsim-geom
@Override
public Set<Connection<E>> getConnections() {
return delegate.getConnections();
}
内容来源于网络,如有侵权,请联系作者删除!