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

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

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

Graph.degree介绍

[英]Returns the count of node's incident edges, counting self-loops twice (equivalently, the number of times an edge touches node).

For directed graphs, this is equal to inDegree(node) + outDegree(node).

For undirected graphs, this is equal to incidentEdges(node).size() + (number of self-loops incident to node).

If the count is greater than Integer.MAX_VALUE, returns Integer.MAX_VALUE.
[中]

代码示例

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

  1. assertThat(graph.degree(node)).isEqualTo(graph.inDegree(node) + graph.outDegree(node));
  2. assertThat(graph.predecessors(node)).hasSize(graph.inDegree(node));
  3. assertThat(graph.successors(node)).hasSize(graph.outDegree(node));
  4. } else {
  5. int selfLoopCount = graph.adjacentNodes(node).contains(node) ? 1 : 0;
  6. assertThat(graph.degree(node)).isEqualTo(graph.adjacentNodes(node).size() + selfLoopCount);
  7. assertThat(graph.predecessors(node)).isEqualTo(graph.adjacentNodes(node));
  8. assertThat(graph.successors(node)).isEqualTo(graph.adjacentNodes(node));
  9. assertThat(graph.inDegree(node)).isEqualTo(graph.degree(node));
  10. assertThat(graph.outDegree(node)).isEqualTo(graph.degree(node));

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

  1. @After
  2. public void validateGraphState() {
  3. assertStronglyEquivalent(graph, Graphs.copyOf(graph));
  4. assertStronglyEquivalent(graph, ImmutableValueGraph.copyOf(graph));
  5. Graph<Integer> asGraph = graph.asGraph();
  6. AbstractGraphTest.validateGraph(asGraph);
  7. assertThat(graph.nodes()).isEqualTo(asGraph.nodes());
  8. assertThat(graph.edges()).isEqualTo(asGraph.edges());
  9. assertThat(graph.nodeOrder()).isEqualTo(asGraph.nodeOrder());
  10. assertThat(graph.isDirected()).isEqualTo(asGraph.isDirected());
  11. assertThat(graph.allowsSelfLoops()).isEqualTo(asGraph.allowsSelfLoops());
  12. for (Integer node : graph.nodes()) {
  13. assertThat(graph.adjacentNodes(node)).isEqualTo(asGraph.adjacentNodes(node));
  14. assertThat(graph.predecessors(node)).isEqualTo(asGraph.predecessors(node));
  15. assertThat(graph.successors(node)).isEqualTo(asGraph.successors(node));
  16. assertThat(graph.degree(node)).isEqualTo(asGraph.degree(node));
  17. assertThat(graph.inDegree(node)).isEqualTo(asGraph.inDegree(node));
  18. assertThat(graph.outDegree(node)).isEqualTo(asGraph.outDegree(node));
  19. for (Integer otherNode : graph.nodes()) {
  20. boolean hasEdge = graph.hasEdgeConnecting(node, otherNode);
  21. assertThat(hasEdge).isEqualTo(asGraph.hasEdgeConnecting(node, otherNode));
  22. assertThat(graph.edgeValueOrDefault(node, otherNode, null) != null).isEqualTo(hasEdge);
  23. assertThat(!graph.edgeValueOrDefault(node, otherNode, DEFAULT).equals(DEFAULT))
  24. .isEqualTo(hasEdge);
  25. }
  26. }
  27. }

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

  1. @Override
  2. public int degreeOf(V vertex)
  3. {
  4. return graph.degree(vertex);
  5. }

代码示例来源:origin: jrtom/jung

  1. /**
  2. * Returns the effective size of <code>v</code> divided by the number of alters in <code>v</code>
  3. * 's network. (In other words, <code>effectiveSize(v) / v.degree()</code>.) If <code>
  4. * v.degree() == 0</code>, returns 0.
  5. *
  6. * @param v the node whose properties are being measured
  7. * @return the effective size of the node divided by its degree
  8. */
  9. public double efficiency(N v) {
  10. double degree = g.degree(v);
  11. if (degree == 0) {
  12. return 0;
  13. } else {
  14. return effectiveSize(v) / degree;
  15. }
  16. }

代码示例来源:origin: jrtom/jung

  1. f = f * Math.pow(stretch / 100.0, (graph.degree(node1) + graph.degree(node2) - 2));

代码示例来源:origin: jrtom/jung

  1. if (g.degree(v1) != g.degree(v2)) {
  2. return false;

代码示例来源:origin: jrtom/jung

  1. int n = graph.degree(v);
  2. if (n < 2) {
  3. coefficients.put(v, new Double(0));

代码示例来源:origin: jrtom/jung

  1. double v_degree = g.degree(v);

代码示例来源:origin: jrtom/jung

  1. f = f * Math.pow(stretch, (graph.degree(node1) + graph.degree(node2) - 2));

代码示例来源:origin: jrtom/jung

  1. double result = g.degree(v);
  2. for (N u : g.adjacentNodes(v)) {

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

  1. assertThat(graph.degree(node)).isEqualTo(graph.inDegree(node) + graph.outDegree(node));
  2. assertThat(graph.predecessors(node)).hasSize(graph.inDegree(node));
  3. assertThat(graph.successors(node)).hasSize(graph.outDegree(node));
  4. } else {
  5. int selfLoopCount = graph.adjacentNodes(node).contains(node) ? 1 : 0;
  6. assertThat(graph.degree(node)).isEqualTo(graph.adjacentNodes(node).size() + selfLoopCount);
  7. assertThat(graph.predecessors(node)).isEqualTo(graph.adjacentNodes(node));
  8. assertThat(graph.successors(node)).isEqualTo(graph.adjacentNodes(node));
  9. assertThat(graph.inDegree(node)).isEqualTo(graph.degree(node));
  10. assertThat(graph.outDegree(node)).isEqualTo(graph.degree(node));

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

  1. @After
  2. public void validateGraphState() {
  3. assertStronglyEquivalent(graph, Graphs.copyOf(graph));
  4. assertStronglyEquivalent(graph, ImmutableValueGraph.copyOf(graph));
  5. Graph<Integer> asGraph = graph.asGraph();
  6. AbstractGraphTest.validateGraph(asGraph);
  7. assertThat(graph.nodes()).isEqualTo(asGraph.nodes());
  8. assertThat(graph.edges()).isEqualTo(asGraph.edges());
  9. assertThat(graph.nodeOrder()).isEqualTo(asGraph.nodeOrder());
  10. assertThat(graph.isDirected()).isEqualTo(asGraph.isDirected());
  11. assertThat(graph.allowsSelfLoops()).isEqualTo(asGraph.allowsSelfLoops());
  12. for (Integer node : graph.nodes()) {
  13. assertThat(graph.adjacentNodes(node)).isEqualTo(asGraph.adjacentNodes(node));
  14. assertThat(graph.predecessors(node)).isEqualTo(asGraph.predecessors(node));
  15. assertThat(graph.successors(node)).isEqualTo(asGraph.successors(node));
  16. assertThat(graph.degree(node)).isEqualTo(asGraph.degree(node));
  17. assertThat(graph.inDegree(node)).isEqualTo(asGraph.inDegree(node));
  18. assertThat(graph.outDegree(node)).isEqualTo(asGraph.outDegree(node));
  19. for (Integer otherNode : graph.nodes()) {
  20. boolean hasEdge = graph.hasEdgeConnecting(node, otherNode);
  21. assertThat(hasEdge).isEqualTo(asGraph.hasEdgeConnecting(node, otherNode));
  22. assertThat(graph.edgeValueOrDefault(node, otherNode, null) != null).isEqualTo(hasEdge);
  23. assertThat(!graph.edgeValueOrDefault(node, otherNode, DEFAULT).equals(DEFAULT))
  24. .isEqualTo(hasEdge);
  25. }
  26. }
  27. }

相关文章