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

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

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

Graph.adjacentNodes介绍

[英]Returns the nodes which have an incident edge in common with node in this graph.
[中]返回与此图中的节点具有共同事件边的节点。

代码示例

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

private static <N> GraphConnections<N, Presence> connectionsOf(Graph<N> graph, N node) {
 Function<Object, Presence> edgeValueFn = Functions.constant(Presence.EDGE_EXISTS);
 return graph.isDirected()
   ? DirectedGraphConnections.ofImmutable(
     graph.predecessors(node), Maps.asMap(graph.successors(node), edgeValueFn))
   : UndirectedGraphConnections.ofImmutable(
     Maps.asMap(graph.adjacentNodes(node), edgeValueFn));
}

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

private static <N> GraphConnections<N, Presence> connectionsOf(Graph<N> graph, N node) {
 Function<Object, Presence> edgeValueFn = Functions.constant(Presence.EDGE_EXISTS);
 return graph.isDirected()
   ? DirectedGraphConnections.ofImmutable(
     graph.predecessors(node), Maps.asMap(graph.successors(node), edgeValueFn))
   : UndirectedGraphConnections.ofImmutable(
     Maps.asMap(graph.adjacentNodes(node), edgeValueFn));
}

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

private static <N> GraphConnections<N, Presence> connectionsOf(Graph<N> graph, N node) {
 Function<Object, Presence> edgeValueFn = Functions.constant(Presence.EDGE_EXISTS);
 return graph.isDirected()
   ? DirectedGraphConnections.ofImmutable(
     graph.predecessors(node), Maps.asMap(graph.successors(node), edgeValueFn))
   : UndirectedGraphConnections.ofImmutable(
     Maps.asMap(graph.adjacentNodes(node), edgeValueFn));
}

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

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));
for (N adjacentNode : sanityCheckSet(graph.adjacentNodes(node))) {
 if (!graph.allowsSelfLoops()) {
  assertThat(node).isNotEqualTo(adjacentNode);

代码示例来源: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

assertThat(nodeString).contains(node.toString());
assertThat(network.adjacentNodes(node)).isEqualTo(asGraph.adjacentNodes(node));
assertThat(network.predecessors(node)).isEqualTo(asGraph.predecessors(node));
assertThat(network.successors(node)).isEqualTo(asGraph.successors(node));

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

/**
  * Return true iff this ordering is canonical and therefore we should build statistics for it.
  *
  * @param g the graph whose properties are being examined
  * @param id a list of the nodes in g; used to assign an index to each
  * @param u a node in g
  * @param v a node in g
  * @param w a node in g
  * @param <N> the node type
  * @param <E> the edge type
  * @return true if index(u) &lt; index(w), or if index(v) &lt; index(w) &lt; index(u) and v
  *     doesn't link to w; false otherwise
  */
 protected static <N, E> boolean shouldCount(Graph<N> g, List<N> id, N u, N v, N w) {
  int i_u = id.indexOf(u);
  int i_w = id.indexOf(w);
  if (i_u < i_w) {
   return true;
  }
  int i_v = id.indexOf(v);
  if ((i_v < i_w) && (i_w < i_u) && (!g.adjacentNodes(w).contains(v))) {
   return true;
  }
  return false;
 }
}

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

/**
 * Returns the weight of the edge from <code>v1</code> to <code>v2</code> plus the weight of the
 * edge from <code>v2</code> to <code>v1</code>; if either edge does not exist, it is treated as
 * an edge with weight 0. Undirected edges are treated as two antiparallel directed edges (that
 * is, if there is one undirected edge with weight <i>w</i> connecting <code>v1</code> to <code>v2
 * </code>, the value returned is 2<i>w</i>). Ignores parallel edges; if there are any such, one
 * is chosen at random. Throws <code>NullPointerException</code> if either edge is present but not
 * assigned a weight by the constructor-specified <code>NumberEdgeValue</code>.
 *
 * @param v1 the first node of the pair whose property is being measured
 * @param v2 the second node of the pair whose property is being measured
 * @return the weights of the edges {@code<v1, v2>} and {@code <v2, v1>}
 */
protected double mutualWeight(N v1, N v2) {
 double weight = 0;
 if (g.isDirected()) {
  if (g.successors(v1).contains(v2)) {
   weight += edge_weight.apply(v1, v2).doubleValue();
  }
  if (g.successors(v2).contains(v1)) {
   weight += edge_weight.apply(v2, v1).doubleValue();
  }
 } else {
  if (g.adjacentNodes(v1).contains(v2)) {
   weight += edge_weight.apply(v1, v2).doubleValue();
  }
 }
 return weight;
}

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

for (N u : g.adjacentNodes(v)) {
 for (N w : g.adjacentNodes(u)) {

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

for (N u : g.adjacentNodes(v)) {
 int triType = -1;
 if (id.indexOf(u) <= i_v) {
  continue;
 Set<N> neighbors = new HashSet<N>(g.adjacentNodes(u));
 neighbors.addAll(g.adjacentNodes(v));
 neighbors.remove(u);
 neighbors.remove(v);

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

/**
 * The aggregate constraint on <code>v</code>. Based on Burt's equation 2.7. Formally:
 *
 * <pre>
 * aggregateConstraint(v) = sum_{w in N(v)} localConstraint(v,w) * O(w)
 * </pre>
 *
 * where
 *
 * <ul>
 *   <li><code>N(v) = v.adjacentNodes()</code>
 *   <li><code>O(w) = organizationalMeasure(w)</code>
 * </ul>
 *
 * @param v the node whose properties are being measured
 * @return the aggregate constraint on v
 */
public double aggregateConstraint(N v) {
 double result = 0;
 for (N w : g.adjacentNodes(v)) {
  result += localConstraint(v, w) * organizationalMeasure(g, w);
 }
 return result;
}

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

for (N w : g.adjacentNodes(v1)) {

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

for (N v : g.adjacentNodes(v1)) {
 denominator += mutualWeight(v1, v);

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

for (N w : g.adjacentNodes(v)) {

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

Collection<N> s = graph.adjacentNodes(current);
while (true) {
 try {

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

/**
 * Returns the local constraint on <code>v1</code> from a lack of primary holes around its
 * neighbor <code>v2</code>. Based on Burt's equation 2.4. Formally:
 *
 * <pre>
 * localConstraint(v1, v2) = ( p(v1,v2) + ( sum_{w in N(v)} p(v1,w) * p(w, v2) ) )^2
 * </pre>
 *
 * where
 *
 * <ul>
 *   <li><code>N(v) = v.adjacentNodes()</code>
 *   <li><code>p(v,w) =</code> normalized mutual edge weight of v and w
 * </ul>
 *
 * @param v1 the first node whose local constraint is desired
 * @param v2 the second node whose local constraint is desired
 * @return the local constraint on (v1, v2)
 * @see #normalizedMutualEdgeWeight(Object, Object)
 */
public double localConstraint(N v1, N v2) {
 double nmew_vw = normalizedMutualEdgeWeight(v1, v2);
 double inner_result = 0;
 for (N w : g.adjacentNodes(v1)) {
  inner_result += normalizedMutualEdgeWeight(v1, w) * normalizedMutualEdgeWeight(w, v2);
 }
 return (nmew_vw + inner_result) * (nmew_vw + inner_result);
}

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

private static <N> GraphConnections<N, Presence> connectionsOf(Graph<N> graph, N node) {
 Function<Object, Presence> edgeValueFn = Functions.constant(Presence.EDGE_EXISTS);
 return graph.isDirected()
   ? DirectedGraphConnections.ofImmutable(
     graph.predecessors(node), Maps.asMap(graph.successors(node), edgeValueFn))
   : UndirectedGraphConnections.ofImmutable(
     Maps.asMap(graph.adjacentNodes(node), edgeValueFn));
}

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

private static <N> GraphConnections<N, Presence> connectionsOf(Graph<N> graph, N node) {
 Function<Object, Presence> edgeValueFn = Functions.constant(Presence.EDGE_EXISTS);
 return graph.isDirected()
   ? DirectedGraphConnections.ofImmutable(
     graph.predecessors(node), Maps.asMap(graph.successors(node), edgeValueFn))
   : UndirectedGraphConnections.ofImmutable(
     Maps.asMap(graph.adjacentNodes(node), edgeValueFn));
}

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

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));
for (N adjacentNode : sanityCheckSet(graph.adjacentNodes(node))) {
 if (!graph.allowsSelfLoops()) {
  assertThat(node).isNotEqualTo(adjacentNode);

代码示例来源: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);
  }
 }
}

相关文章