private static <N, E> Map<N, NetworkConnections<N, E>> getNodeConnections(Network<N, E> network) { // ImmutableMap.Builder maintains the order of the elements as inserted, so the map will have // whatever ordering the network's nodes do, so ImmutableSortedMap is unnecessary even if the // input nodes are sorted. ImmutableMap.Builder<N, NetworkConnections<N, E>> nodeConnections = ImmutableMap.builder(); for (N node : network.nodes()) { nodeConnections.put(node, connectionsOf(network, node)); } return nodeConnections.build(); }
@Override public Set<N> nodes() { return delegate().nodes(); }
@Override public Set<N> nodes() { return network.nodes(); }
private static <N, E> Map<N, NetworkConnections<N, E>> getNodeConnections(Network<N, E> network) { // ImmutableMap.Builder maintains the order of the elements as inserted, so the map will have // whatever ordering the network's nodes do, so ImmutableSortedMap is unnecessary even if the // input nodes are sorted. ImmutableMap.Builder<N, NetworkConnections<N, E>> nodeConnections = ImmutableMap.builder(); for (N node : network.nodes()) { nodeConnections.put(node, connectionsOf(network, node)); } return nodeConnections.build(); }
@Override public Set<N> nodes() { return delegate().nodes(); }
private static <N, E> Map<N, NetworkConnections<N, E>> getNodeConnections(Network<N, E> network) { // ImmutableMap.Builder maintains the order of the elements as inserted, so the map will have // whatever ordering the network's nodes do, so ImmutableSortedMap is unnecessary even if the // input nodes are sorted. ImmutableMap.Builder<N, NetworkConnections<N, E>> nodeConnections = ImmutableMap.builder(); for (N node : network.nodes()) { nodeConnections.put(node, connectionsOf(network, node)); } return nodeConnections.build(); }
@Override public Set<N> nodes() { return delegate().nodes(); }
@Override public final boolean equals(@Nullable Object obj) { if (obj == this) { return true; } if (!(obj instanceof Network)) { return false; } Network<?, ?> other = (Network<?, ?>) obj; return isDirected() == other.isDirected() && nodes().equals(other.nodes()) && edgeIncidentNodesMap(this).equals(edgeIncidentNodesMap(other)); }
/** Creates a mutable copy of {@code network} with the same nodes and edges. */ public static <N, E> MutableNetwork<N, E> copyOf(Network<N, E> network) { MutableNetwork<N, E> copy = NetworkBuilder.from(network) .expectedNodeCount(network.nodes().size()) .expectedEdgeCount(network.edges().size()) .build(); for (N node : network.nodes()) { copy.addNode(node); } for (E edge : network.edges()) { EndpointPair<N> endpointPair = network.incidentNodes(edge); copy.addEdge(endpointPair.nodeU(), endpointPair.nodeV(), edge); } return copy; }
@Override public final boolean equals(@NullableDecl Object obj) { if (obj == this) { return true; } if (!(obj instanceof Network)) { return false; } Network<?, ?> other = (Network<?, ?>) obj; return isDirected() == other.isDirected() && nodes().equals(other.nodes()) && edgeIncidentNodesMap(this).equals(edgeIncidentNodesMap(other)); }
@Override public final boolean equals(@NullableDecl Object obj) { if (obj == this) { return true; } if (!(obj instanceof Network)) { return false; } Network<?, ?> other = (Network<?, ?>) obj; return isDirected() == other.isDirected() && nodes().equals(other.nodes()) && edgeIncidentNodesMap(this).equals(edgeIncidentNodesMap(other)); }
/** Creates a mutable copy of {@code network} with the same nodes and edges. */ public static <N, E> MutableNetwork<N, E> copyOf(Network<N, E> network) { MutableNetwork<N, E> copy = NetworkBuilder.from(network) .expectedNodeCount(network.nodes().size()) .expectedEdgeCount(network.edges().size()) .build(); for (N node : network.nodes()) { copy.addNode(node); } for (E edge : network.edges()) { EndpointPair<N> endpointPair = network.incidentNodes(edge); copy.addEdge(endpointPair.nodeU(), endpointPair.nodeV(), edge); } return copy; }
/** Creates a mutable copy of {@code network} with the same nodes and edges. */ public static <N, E> MutableNetwork<N, E> copyOf(Network<N, E> network) { MutableNetwork<N, E> copy = NetworkBuilder.from(network) .expectedNodeCount(network.nodes().size()) .expectedEdgeCount(network.edges().size()) .build(); for (N node : network.nodes()) { copy.addNode(node); } for (E edge : network.edges()) { EndpointPair<N> endpointPair = network.incidentNodes(edge); copy.addEdge(endpointPair.nodeU(), endpointPair.nodeV(), edge); } return copy; }
assertThat(network.nodes()).isEqualTo(asGraph.nodes()); assertThat(network.edges().size()).isAtLeast(asGraph.edges().size()); assertThat(network.nodeOrder()).isEqualTo(asGraph.nodeOrder()); assertThat(network.nodes()).contains(incidentNode); for (E adjacentEdge : network.incidentEdges(incidentNode)) { assertTrue( for (N node : sanityCheckSet(network.nodes())) { assertThat(nodeString).contains(node.toString()); for (N otherNode : network.nodes()) { Set<E> edgesConnecting = sanityCheckSet(network.edgesConnecting(node, otherNode)); switch (edgesConnecting.size()) {
public boolean contains(Network inGraph, Object inNode) { boolean contained = false; if (inGraph.nodes().contains(inNode)) { // inNode is one of the nodes in inGraph return true; } for (Object node : inGraph.nodes()) { contained |= (node instanceof Network) && contains((Network) node, inNode); } return contained; }
/** * Creates an instance for the specified graph and alpha (random jump probability) parameter. The * edge weights are all set to 1. * * @param g the input graph * @param alpha the probability of a hub giving some authority to all nodes, and of an authority * increasing the score of all hubs (not just those connected via links) */ public HITS(Network<N, E> g, double alpha) { super(g, ScoringUtils.getHITSUniformRootPrior(g.nodes()), alpha); }
/** * Initialize incoming EIGRP message queues for each adjacency * * @param eigrpTopology The topology representing EIGRP adjacencies */ void initQueues(Network<EigrpInterface, EigrpEdge> eigrpTopology) { _incomingRoutes = _interfaces.stream() .filter(eigrpTopology.nodes()::contains) .flatMap(n -> eigrpTopology.inEdges(n).stream()) .collect(toImmutableSortedMap(Function.identity(), e -> new ConcurrentLinkedQueue<>())); }
/** * A graph is "forest-shaped" if it is directed, acyclic, and each node has at most one * predecessor. */ public static <N> boolean isForestShaped(Network<N, ?> graph) { checkNotNull(graph, "graph"); return graph.isDirected() && !Graphs.hasCycle(graph) && graph.nodes().stream().allMatch(node -> graph.predecessors(node).size() <= 1); }
public void setNetwork(Network<N, E> network, boolean forceUpdate) { log.trace("setNetwork to n:{} e:{}", network.nodes(), network.edges()); this.network = network; this.layoutModel.setGraph(network.asGraph()); if (forceUpdate && this.layoutAlgorithm != null) { log.trace("will accept {}", layoutAlgorithm); layoutModel.accept(this.layoutAlgorithm); log.trace("will fire stateChanged"); changeSupport.fireStateChanged(); log.trace("fired stateChanged"); } }
protected Collection<N> getFilteredNodes() { Set<N> nodes = vv.getModel().getNetwork().nodes(); return nodesAreFiltered() ? Sets.filter(nodes, vv.getRenderContext().getNodeIncludePredicate()::test) : nodes; }