本文整理了Java中com.google.common.graph.Graph.degree()
方法的一些代码示例,展示了Graph.degree()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.degree()
方法的具体详情如下:
包路径:com.google.common.graph.Graph
类名称: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
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 {
int selfLoopCount = graph.adjacentNodes(node).contains(node) ? 1 : 0;
assertThat(graph.degree(node)).isEqualTo(graph.adjacentNodes(node).size() + selfLoopCount);
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: com.io7m.jgrapht/jgrapht-guava
@Override
public int degreeOf(V vertex)
{
return graph.degree(vertex);
}
代码示例来源:origin: jrtom/jung
/**
* Returns the effective size of <code>v</code> divided by the number of alters in <code>v</code>
* 's network. (In other words, <code>effectiveSize(v) / v.degree()</code>.) If <code>
* v.degree() == 0</code>, returns 0.
*
* @param v the node whose properties are being measured
* @return the effective size of the node divided by its degree
*/
public double efficiency(N v) {
double degree = g.degree(v);
if (degree == 0) {
return 0;
} else {
return effectiveSize(v) / degree;
}
}
代码示例来源:origin: jrtom/jung
f = f * Math.pow(stretch / 100.0, (graph.degree(node1) + graph.degree(node2) - 2));
代码示例来源:origin: jrtom/jung
if (g.degree(v1) != g.degree(v2)) {
return false;
代码示例来源:origin: jrtom/jung
int n = graph.degree(v);
if (n < 2) {
coefficients.put(v, new Double(0));
代码示例来源:origin: jrtom/jung
double v_degree = g.degree(v);
代码示例来源:origin: jrtom/jung
f = f * Math.pow(stretch, (graph.degree(node1) + graph.degree(node2) - 2));
代码示例来源:origin: jrtom/jung
double result = g.degree(v);
for (N u : g.adjacentNodes(v)) {
代码示例来源: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 {
int selfLoopCount = graph.adjacentNodes(node).contains(node) ? 1 : 0;
assertThat(graph.degree(node)).isEqualTo(graph.adjacentNodes(node).size() + selfLoopCount);
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);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!