/** * {@inheritDoc} */ @Override public Set<E> edgeSet() { return delegate.edgeSet(); }
public Set<Scope> edgeSet() { return graph.edgeSet(); }
/** * Test whether a graph is empty. An empty graph on n nodes consists of n isolated vertices with * no edges. * * @param graph the input graph * @param <V> the graph vertex type * @param <E> the graph edge type * @return true if the graph is empty, false otherwise */ public static <V, E> boolean isEmpty(Graph<V, E> graph) { Objects.requireNonNull(graph, GRAPH_CANNOT_BE_NULL); return graph.edgeSet().isEmpty(); }
private void init() { blocks = new LinkedHashSet<>(); cutpoints = new LinkedHashSet<>(); bridges = new LinkedHashSet<>(); connectedSets = new LinkedHashSet<>(); stack = new ArrayDeque<>(graph.edgeSet().size()); for (V v : graph.vertexSet()) discTime.put(v, -1); }
/** * Calculate the density of the graph as the * number of edges divided by the number of vertices * @param g the graph * @return the density */ public static double calculateDensity(Graph<?,?> g) { return (double)g.edgeSet().size() / (double)g.vertexSet().size(); }
/** * Returns the set of edges which run from the source partition to the sink partition, in the * $s-t$ cut obtained after the last invocation of {@link #calculateMinCut(Set, boolean)} * * @return set of edges which have one endpoint in the source partition and one endpoint in the * sink partition. */ public Set<E> getCutEdges() { Predicate<E> predicate = e -> sourcePartitionMinimumCut.contains(network.getEdgeSource(e)) ^ sourcePartitionMinimumCut.contains(network.getEdgeTarget(e)); return network.edgeSet().stream().filter(predicate).collect( Collectors.toCollection(LinkedHashSet::new)); }
/** * Test whether a graph is <a href="https://en.wikipedia.org/wiki/Overfull_graph">overfull</a>. * A graph is overfull if $|E|>\Delta(G)\lfloor |V|/2 \rfloor$, where $\Delta(G)$ is the * maximum degree of the graph. * * @param graph the input graph * @param <V> the graph vertex type * @param <E> the graph edge type * @return true if the graph is overfull, false otherwise */ public static <V, E> boolean isOverfull(Graph<V, E> graph) { int maxDegree = graph.vertexSet().stream().mapToInt(graph::degreeOf).max().getAsInt(); return graph.edgeSet().size() > maxDegree * Math.floor(graph.vertexSet().size() / 2.0); }
@Override public Set<E> getCutEdges() { Set<E> cutEdges = new LinkedHashSet<>(); Set<V> sourcePartion = this.getSourcePartition(); for (E e : network.edgeSet()) { V source = network.getEdgeSource(e); V sink = network.getEdgeTarget(e); if (sourcePartion.contains(source) ^ sourcePartion.contains(sink)) cutEdges.add(e); } return cutEdges; } }
/** * Test whether an undirected graph is a tree. * * @param graph the input graph * @param <V> the graph vertex type * @param <E> the graph edge type * @return true if the graph is tree, false otherwise */ public static <V, E> boolean isTree(Graph<V, E> graph) { if (!graph.getType().isUndirected()) { throw new IllegalArgumentException(GRAPH_MUST_BE_UNDIRECTED); } return (graph.edgeSet().size() == (graph.vertexSet().size() - 1)) && isConnected(graph); }
public static <V, E> int hashCodeIgnoreAnnotations( Graph<V, E> graph ) { int hash = graph.vertexSet().hashCode(); for( E e : graph.edgeSet() ) { int part = e.hashCode(); int source = graph.getEdgeSource( e ).hashCode(); int target = graph.getEdgeTarget( e ).hashCode(); int pairing = pair( source, target ); part = ( 27 * part ) + pairing; long weight = (long) graph.getEdgeWeight( e ); part = ( 27 * part ) + (int) ( weight ^ ( weight >>> 32 ) ); hash += part; } return hash; }
/** * Creates a weak chordality inspector for the {@code graph} * * @param graph the inspected {@code graph} */ public WeakChordalityInspector(Graph<V, E> graph) { this.graph = Objects.requireNonNull(graph); if (graph.getType().isDirected()) { this.graph = new AsUndirectedGraph<>(graph); } n = graph.vertexSet().size(); m = graph.edgeSet().size(); initMappings(); }
private void exportAsEdgeList(Graph<V, E> g, PrintWriter out) { boolean exportEdgeWeights = parameters.contains(CSVFormat.Parameter.EDGE_WEIGHTS); for (E e : g.edgeSet()) { exportEscapedField(out, vertexIDProvider.getName(g.getEdgeSource(e))); out.print(delimiter); exportEscapedField(out, vertexIDProvider.getName(g.getEdgeTarget(e))); if (exportEdgeWeights) { out.print(delimiter); exportEscapedField(out, String.valueOf(g.getEdgeWeight(e))); } out.println(); } }
private static <V, E> Graph<V, E> disconnectExtentsAndExclude( Graph<V, E> full, Set<E> withoutEdges ) { IdentityMultiGraphGraph<V, E> copy = (IdentityMultiGraphGraph<V, E>) new IdentityMultiGraphGraph<>( Object.class ); Graphs.addAllVertices( copy, full.vertexSet() ); copy.removeVertex( (V) Extent.head ); copy.removeVertex( (V) Extent.tail ); Set<E> edges = full.edgeSet(); if( !withoutEdges.isEmpty() ) { edges = new HashSet<>( edges ); edges.removeAll( withoutEdges ); } Graphs.addAllEdges( copy, full, edges ); return copy; }
/** * Draws a given graph with all its vertices and edges. * * @param graph the graph to be added to the existing graph. */ private void insertJGraphT(Graph<V, E> graph) { for (V vertex : graph.vertexSet()) { addJGraphTVertex(vertex); } for (E edge : graph.edgeSet()) { addJGraphTEdge(edge); } } }
/** * Draws a given graph with all its vertices and edges. * * @param graph the graph to be added to the existing graph. */ private void insertJGraphT(Graph<V, E> graph) { for (V vertex : graph.vertexSet()) { addJGraphTVertex(vertex); } for (E edge : graph.edgeSet()) { addJGraphTEdge(edge); } } }
/** * {@inheritDoc} */ @Override public MinimumCostFlow<E> getMinimumCostFlow( final MinimumCostFlowProblem<V, E> minimumCostFlowProblem) { this.problem = Objects.requireNonNull(minimumCostFlowProblem); if (problem.getGraph().getType().isUndirected()) { throw new IllegalArgumentException( "The algorithm doesn't support undirected flow networks"); } n = problem.getGraph().vertexSet().size(); m = problem.getGraph().edgeSet().size(); calculateMinimumCostFlow(); return minimumCostFlow; }
static public <V, E> void copyTo(Graph<V, E> source, Graph<V, E> target) { for (V vertex : source.vertexSet()) { target.addVertex(vertex); } for (E edge : source.edgeSet()) { final boolean added = target.addEdge(source.getEdgeSource(edge), source.getEdgeTarget(edge), edge); if (!added) { throw new IllegalArgumentException("Target graph does not support addition of (some) source edges."); } } }
public DirectedMultiGraph( Graph<FlowElement, Scope> parent ) { this(); // safe to assume there are no unconnected vertices for( Scope edge : parent.edgeSet() ) { FlowElement s = parent.getEdgeSource( edge ); FlowElement t = parent.getEdgeTarget( edge ); addVertex( s ); addVertex( t ); addEdge( s, t, edge ); } }