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)); }
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)); }
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)); }
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);
@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); } } }
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));
/** * 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) < index(w), or if index(v) < index(w) < 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; } }
/** * 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; }
for (N u : g.adjacentNodes(v)) { for (N w : g.adjacentNodes(u)) {
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);
/** * 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; }
for (N w : g.adjacentNodes(v1)) {
for (N v : g.adjacentNodes(v1)) { denominator += mutualWeight(v1, v);
for (N w : g.adjacentNodes(v)) {
Collection<N> s = graph.adjacentNodes(current); while (true) { try {
/** * 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); }
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)); }
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)); }
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);
@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); } } }