com.google.common.graph.Graph.inDegree()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(257)

本文整理了Java中com.google.common.graph.Graph.inDegree()方法的一些代码示例,展示了Graph.inDegree()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.inDegree()方法的具体详情如下:
包路径:com.google.common.graph.Graph
类名称:Graph
方法名:inDegree

Graph.inDegree介绍

[英]Returns the count of node's incoming edges (equal to predecessors(node).size()) in a directed graph. In an undirected graph, returns the #degree(Object).

If the count is greater than Integer.MAX_VALUE, returns Integer.MAX_VALUE.
[中]返回节点传入边的计数(等于前导边(节点))。有向图中的size()。在无向图中,返回#度(对象)。
如果计数大于整数。最大值,返回整数。最大值。

代码示例

代码示例来源:origin: google/guava

@Override
public int outDegree(N node) {
 return delegate().inDegree(node); // transpose
}

代码示例来源:origin: google/j2objc

@Override
public int outDegree(N node) {
 return delegate().inDegree(node); // transpose
}

代码示例来源:origin: wildfly/wildfly

@Override
public int outDegree(N node) {
 return delegate().inDegree(node); // transpose
}

代码示例来源:origin: google/guava

assertThat(graph.degree(node)).isEqualTo(graph.inDegree(node) + graph.outDegree(node));
 assertThat(graph.predecessors(node)).hasSize(graph.inDegree(node));
 assertThat(graph.successors(node)).hasSize(graph.outDegree(node));
} else {
 assertThat(graph.predecessors(node)).isEqualTo(graph.adjacentNodes(node));
 assertThat(graph.successors(node)).isEqualTo(graph.adjacentNodes(node));
 assertThat(graph.inDegree(node)).isEqualTo(graph.degree(node));
 assertThat(graph.outDegree(node)).isEqualTo(graph.degree(node));

代码示例来源:origin: google/guava

@After
public void validateGraphState() {
 assertStronglyEquivalent(graph, Graphs.copyOf(graph));
 assertStronglyEquivalent(graph, ImmutableValueGraph.copyOf(graph));
 Graph<Integer> asGraph = graph.asGraph();
 AbstractGraphTest.validateGraph(asGraph);
 assertThat(graph.nodes()).isEqualTo(asGraph.nodes());
 assertThat(graph.edges()).isEqualTo(asGraph.edges());
 assertThat(graph.nodeOrder()).isEqualTo(asGraph.nodeOrder());
 assertThat(graph.isDirected()).isEqualTo(asGraph.isDirected());
 assertThat(graph.allowsSelfLoops()).isEqualTo(asGraph.allowsSelfLoops());
 for (Integer node : graph.nodes()) {
  assertThat(graph.adjacentNodes(node)).isEqualTo(asGraph.adjacentNodes(node));
  assertThat(graph.predecessors(node)).isEqualTo(asGraph.predecessors(node));
  assertThat(graph.successors(node)).isEqualTo(asGraph.successors(node));
  assertThat(graph.degree(node)).isEqualTo(asGraph.degree(node));
  assertThat(graph.inDegree(node)).isEqualTo(asGraph.inDegree(node));
  assertThat(graph.outDegree(node)).isEqualTo(asGraph.outDegree(node));
  for (Integer otherNode : graph.nodes()) {
   boolean hasEdge = graph.hasEdgeConnecting(node, otherNode);
   assertThat(hasEdge).isEqualTo(asGraph.hasEdgeConnecting(node, otherNode));
   assertThat(graph.edgeValueOrDefault(node, otherNode, null) != null).isEqualTo(hasEdge);
   assertThat(!graph.edgeValueOrDefault(node, otherNode, DEFAULT).equals(DEFAULT))
     .isEqualTo(hasEdge);
  }
 }
}

代码示例来源:origin: google/guava

@Test
public void transpose_directedGraph() {
 MutableGraph<Integer> directedGraph = GraphBuilder.directed().allowsSelfLoops(true).build();
 directedGraph.putEdge(N1, N3);
 directedGraph.putEdge(N3, N1);
 directedGraph.putEdge(N1, N2);
 directedGraph.putEdge(N1, N1);
 directedGraph.putEdge(N3, N4);
 MutableGraph<Integer> expectedTranspose = GraphBuilder.directed().allowsSelfLoops(true).build();
 expectedTranspose.putEdge(N3, N1);
 expectedTranspose.putEdge(N1, N3);
 expectedTranspose.putEdge(N2, N1);
 expectedTranspose.putEdge(N1, N1);
 expectedTranspose.putEdge(N4, N3);
 Graph<Integer> transpose = transpose(directedGraph);
 assertThat(transpose).isEqualTo(expectedTranspose);
 assertThat(transpose(transpose)).isSameAs(directedGraph);
 AbstractGraphTest.validateGraph(transpose);
 for (Integer node : directedGraph.nodes()) {
  assertThat(directedGraph.inDegree(node)).isSameAs(transpose.outDegree(node));
  assertThat(directedGraph.outDegree(node)).isSameAs(transpose.inDegree(node));
 }
 assertThat(transpose.successors(N1)).doesNotContain(N2);
 directedGraph.putEdge(N2, N1);
 // View should be updated.
 assertThat(transpose.successors(N1)).contains(N2);
 AbstractGraphTest.validateGraph(transpose);
}

代码示例来源:origin: com.io7m.jgrapht/jgrapht-guava

@Override
public int inDegreeOf(V vertex)
{
  return graph.inDegree(vertex);
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

@Override
public int outDegree(N node) {
 return delegate().inDegree(node); // transpose
}

代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger

@Override
public int outDegree(N node) {
 return delegate().inDegree(node); // transpose
}

代码示例来源:origin: com.google.guava/guava-tests

assertThat(graph.degree(node)).isEqualTo(graph.inDegree(node) + graph.outDegree(node));
 assertThat(graph.predecessors(node)).hasSize(graph.inDegree(node));
 assertThat(graph.successors(node)).hasSize(graph.outDegree(node));
} else {
 assertThat(graph.predecessors(node)).isEqualTo(graph.adjacentNodes(node));
 assertThat(graph.successors(node)).isEqualTo(graph.adjacentNodes(node));
 assertThat(graph.inDegree(node)).isEqualTo(graph.degree(node));
 assertThat(graph.outDegree(node)).isEqualTo(graph.degree(node));

代码示例来源:origin: com.google.guava/guava-tests

@After
public void validateGraphState() {
 assertStronglyEquivalent(graph, Graphs.copyOf(graph));
 assertStronglyEquivalent(graph, ImmutableValueGraph.copyOf(graph));
 Graph<Integer> asGraph = graph.asGraph();
 AbstractGraphTest.validateGraph(asGraph);
 assertThat(graph.nodes()).isEqualTo(asGraph.nodes());
 assertThat(graph.edges()).isEqualTo(asGraph.edges());
 assertThat(graph.nodeOrder()).isEqualTo(asGraph.nodeOrder());
 assertThat(graph.isDirected()).isEqualTo(asGraph.isDirected());
 assertThat(graph.allowsSelfLoops()).isEqualTo(asGraph.allowsSelfLoops());
 for (Integer node : graph.nodes()) {
  assertThat(graph.adjacentNodes(node)).isEqualTo(asGraph.adjacentNodes(node));
  assertThat(graph.predecessors(node)).isEqualTo(asGraph.predecessors(node));
  assertThat(graph.successors(node)).isEqualTo(asGraph.successors(node));
  assertThat(graph.degree(node)).isEqualTo(asGraph.degree(node));
  assertThat(graph.inDegree(node)).isEqualTo(asGraph.inDegree(node));
  assertThat(graph.outDegree(node)).isEqualTo(asGraph.outDegree(node));
  for (Integer otherNode : graph.nodes()) {
   boolean hasEdge = graph.hasEdgeConnecting(node, otherNode);
   assertThat(hasEdge).isEqualTo(asGraph.hasEdgeConnecting(node, otherNode));
   assertThat(graph.edgeValueOrDefault(node, otherNode, null) != null).isEqualTo(hasEdge);
   assertThat(!graph.edgeValueOrDefault(node, otherNode, DEFAULT).equals(DEFAULT))
     .isEqualTo(hasEdge);
  }
 }
}

代码示例来源:origin: com.google.guava/guava-tests

@Test
public void transpose_directedGraph() {
 MutableGraph<Integer> directedGraph = GraphBuilder.directed().allowsSelfLoops(true).build();
 directedGraph.putEdge(N1, N3);
 directedGraph.putEdge(N3, N1);
 directedGraph.putEdge(N1, N2);
 directedGraph.putEdge(N1, N1);
 directedGraph.putEdge(N3, N4);
 MutableGraph<Integer> expectedTranspose = GraphBuilder.directed().allowsSelfLoops(true).build();
 expectedTranspose.putEdge(N3, N1);
 expectedTranspose.putEdge(N1, N3);
 expectedTranspose.putEdge(N2, N1);
 expectedTranspose.putEdge(N1, N1);
 expectedTranspose.putEdge(N4, N3);
 Graph<Integer> transpose = transpose(directedGraph);
 assertThat(transpose).isEqualTo(expectedTranspose);
 assertThat(transpose(transpose)).isSameAs(directedGraph);
 AbstractGraphTest.validateGraph(transpose);
 for (Integer node : directedGraph.nodes()) {
  assertThat(directedGraph.inDegree(node)).isSameAs(transpose.outDegree(node));
  assertThat(directedGraph.outDegree(node)).isSameAs(transpose.inDegree(node));
 }
 assertThat(transpose.successors(N1)).doesNotContain(N2);
 directedGraph.putEdge(N2, N1);
 // View should be updated.
 assertThat(transpose.successors(N1)).contains(N2);
 AbstractGraphTest.validateGraph(transpose);
}

相关文章