@Override public boolean isDirected() { return network.isDirected(); }
@Override public boolean isDirected() { return delegate().isDirected(); }
/** * Returns a view of {@code network} with the direction (if any) of every edge reversed. All other * properties remain intact, and further updates to {@code network} will be reflected in the view. */ public static <N, E> Network<N, E> transpose(Network<N, E> network) { if (!network.isDirected()) { return network; // the transpose of an undirected network is an identical network } if (network instanceof TransposedNetwork) { return ((TransposedNetwork<N, E>) network).network; } return new TransposedNetwork<>(network); }
/** * Returns a view of {@code network} with the direction (if any) of every edge reversed. All other * properties remain intact, and further updates to {@code network} will be reflected in the view. */ public static <N, E> Network<N, E> transpose(Network<N, E> network) { if (!network.isDirected()) { return network; // the transpose of an undirected network is an identical network } if (network instanceof TransposedNetwork) { return ((TransposedNetwork<N, E>) network).network; } return new TransposedNetwork<>(network); }
@Override public boolean isDirected() { return delegate().isDirected(); }
/** Returns an {@link EndpointPair} representing the endpoints of an edge in {@code network}. */ static <N> EndpointPair<N> of(Network<?, ?> network, N nodeU, N nodeV) { return network.isDirected() ? ordered(nodeU, nodeV) : unordered(nodeU, nodeV); }
/** * Returns a view of {@code network} with the direction (if any) of every edge reversed. All other * properties remain intact, and further updates to {@code network} will be reflected in the view. */ public static <N, E> Network<N, E> transpose(Network<N, E> network) { if (!network.isDirected()) { return network; // the transpose of an undirected network is an identical network } if (network instanceof TransposedNetwork) { return ((TransposedNetwork<N, E>) network).network; } return new TransposedNetwork<>(network); }
@Override public boolean isDirected() { return delegate().isDirected(); }
/** Returns an {@link EndpointPair} representing the endpoints of an edge in {@code network}. */ static <N> EndpointPair<N> of(Network<?, ?> network, N nodeU, N nodeV) { return network.isDirected() ? ordered(nodeU, nodeV) : unordered(nodeU, nodeV); }
@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)); }
/** Returns an {@link EndpointPair} representing the endpoints of an edge in {@code network}. */ static <N> EndpointPair<N> of(Network<?, ?> network, N nodeU, N nodeV) { return network.isDirected() ? ordered(nodeU, nodeV) : unordered(nodeU, nodeV); }
/** * Returns true if {@code network} has at least one cycle. A cycle is defined as a non-empty * subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges) * starting and ending with the same node. * * <p>This method will detect any non-empty cycle, including self-loops (a cycle of length 1). */ public static boolean hasCycle(Network<?, ?> network) { // In a directed graph, parallel edges cannot introduce a cycle in an acyclic graph. // However, in an undirected graph, any parallel edge induces a cycle in the graph. if (!network.isDirected() && network.allowsParallelEdges() && network.edges().size() > network.asGraph().edges().size()) { return true; } return hasCycle(network.asGraph()); }
@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)); }
/** * Returns true if {@code network} has at least one cycle. A cycle is defined as a non-empty * subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges) * starting and ending with the same node. * * <p>This method will detect any non-empty cycle, including self-loops (a cycle of length 1). */ public static boolean hasCycle(Network<?, ?> network) { // In a directed graph, parallel edges cannot introduce a cycle in an acyclic graph. // However, in an undirected graph, any parallel edge induces a cycle in the graph. if (!network.isDirected() && network.allowsParallelEdges() && network.edges().size() > network.asGraph().edges().size()) { return true; } return hasCycle(network.asGraph()); }
@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)); }
/** * Returns a {@link NetworkBuilder} initialized with all properties queryable from {@code * network}. * * <p>The "queryable" properties are those that are exposed through the {@link Network} interface, * such as {@link Network#isDirected()}. Other properties, such as {@link * #expectedNodeCount(int)}, are not set in the new builder. */ public static <N, E> NetworkBuilder<N, E> from(Network<N, E> network) { return new NetworkBuilder<N, E>(network.isDirected()) .allowsParallelEdges(network.allowsParallelEdges()) .allowsSelfLoops(network.allowsSelfLoops()) .nodeOrder(network.nodeOrder()) .edgeOrder(network.edgeOrder()); }
private static <N, E> NetworkConnections<N, E> connectionsOf(Network<N, E> network, N node) { if (network.isDirected()) { Map<E, N> inEdgeMap = Maps.asMap(network.inEdges(node), sourceNodeFn(network)); Map<E, N> outEdgeMap = Maps.asMap(network.outEdges(node), targetNodeFn(network)); int selfLoopCount = network.edgesConnecting(node, node).size(); return network.allowsParallelEdges() ? DirectedMultiNetworkConnections.ofImmutable(inEdgeMap, outEdgeMap, selfLoopCount) : DirectedNetworkConnections.ofImmutable(inEdgeMap, outEdgeMap, selfLoopCount); } else { Map<E, N> incidentEdgeMap = Maps.asMap(network.incidentEdges(node), adjacentNodeFn(network, node)); return network.allowsParallelEdges() ? UndirectedMultiNetworkConnections.ofImmutable(incidentEdgeMap) : UndirectedNetworkConnections.ofImmutable(incidentEdgeMap); } }
/** * Returns a {@link NetworkBuilder} initialized with all properties queryable from {@code * network}. * * <p>The "queryable" properties are those that are exposed through the {@link Network} interface, * such as {@link Network#isDirected()}. Other properties, such as {@link * #expectedNodeCount(int)}, are not set in the new builder. */ public static <N, E> NetworkBuilder<N, E> from(Network<N, E> network) { return new NetworkBuilder<N, E>(network.isDirected()) .allowsParallelEdges(network.allowsParallelEdges()) .allowsSelfLoops(network.allowsSelfLoops()) .nodeOrder(network.nodeOrder()) .edgeOrder(network.edgeOrder()); }
/** * Returns a {@link NetworkBuilder} initialized with all properties queryable from {@code * network}. * * <p>The "queryable" properties are those that are exposed through the {@link Network} interface, * such as {@link Network#isDirected()}. Other properties, such as {@link * #expectedNodeCount(int)}, are not set in the new builder. */ public static <N, E> NetworkBuilder<N, E> from(Network<N, E> network) { return new NetworkBuilder<N, E>(network.isDirected()) .allowsParallelEdges(network.allowsParallelEdges()) .allowsSelfLoops(network.allowsSelfLoops()) .nodeOrder(network.nodeOrder()) .edgeOrder(network.edgeOrder()); }
private static <N, E> NetworkConnections<N, E> connectionsOf(Network<N, E> network, N node) { if (network.isDirected()) { Map<E, N> inEdgeMap = Maps.asMap(network.inEdges(node), sourceNodeFn(network)); Map<E, N> outEdgeMap = Maps.asMap(network.outEdges(node), targetNodeFn(network)); int selfLoopCount = network.edgesConnecting(node, node).size(); return network.allowsParallelEdges() ? DirectedMultiNetworkConnections.ofImmutable(inEdgeMap, outEdgeMap, selfLoopCount) : DirectedNetworkConnections.ofImmutable(inEdgeMap, outEdgeMap, selfLoopCount); } else { Map<E, N> incidentEdgeMap = Maps.asMap(network.incidentEdges(node), adjacentNodeFn(network, node)); return network.allowsParallelEdges() ? UndirectedMultiNetworkConnections.ofImmutable(incidentEdgeMap) : UndirectedNetworkConnections.ofImmutable(incidentEdgeMap); } }