/** * {@inheritDoc} */ @Override public Set<E> edgesOf(V vertex) { return delegate.edgesOf(vertex); }
@Override public Set< EE > edgesOf( final VV vertex ) { return graph.edgesOf( vertex ); } }
@Override public Set< EE > edgesOf( final VV vertex ) { return graph.edgesOf( vertex ); } }
public Set<Scope> edgesOf( FlowElement vertex ) { return graph.edgesOf( vertex ); }
public static Set outgoingEdgesOf(Graph g, Object node) { if (g instanceof DirectedGraph) { return ((DirectedGraph) g).outgoingEdgesOf(node); } else { return g.edgesOf(node); } }
/** * {@inheritDoc} */ @Override public Set<E> edgesOf(V vertex) { assertVertexExist(vertex); return base.edgesOf(vertex).stream().filter(edgeSet::contains).collect( Collectors.toCollection(LinkedHashSet::new)); }
/** * Compute the sum of the weights entering a vertex * * @param v the vertex * @return the sum of the weights entering a vertex */ public double vertexWeight(Set<V> v) { double wsum = 0.0; for (DefaultWeightedEdge e : workingGraph.edgesOf(v)) { wsum += workingGraph.getEdgeWeight(e); } return wsum; }
/** * {@inheritDoc} */ @Override public Set<E> edgesOf(V vertex) { boolean inG1 = g1.containsVertex(vertex); boolean inG2 = g2.containsVertex(vertex); if (inG1 && inG2) { return new UnmodifiableUnionSet<>(g1.edgesOf(vertex), g2.edgesOf(vertex)); } else if (inG1) { return Collections.unmodifiableSet(g1.edgesOf(vertex)); } else if (inG2) { return Collections.unmodifiableSet(g2.edgesOf(vertex)); } else { throw new IllegalArgumentException("no such vertex in graph: " + vertex.toString()); } }
/** * Returns a set of vertices that are neighbors of a specified vertex. * * @param g the graph to look for neighbors in * @param vertex the vertex to get the neighbors of * @param <V> the graph vertex type * @param <E> the graph edge type * @return a set of the vertices that are neighbors of the specified vertex */ public static <V, E> Set<V> neighborSetOf(Graph<V, E> g, V vertex) { Set<V> neighbors = new LinkedHashSet<>(); for (E e : g.edgesOf(vertex)) { neighbors.add(Graphs.getOppositeVertex(g, e, vertex)); } return neighbors; }
/** * Returns true if vertex v is incident to an edge in this matching. * * @param v vertex * @return true if vertex v is incident to an edge in this matching. */ default boolean isMatched(V v) { Set<E> edges = getEdges(); return getGraph().edgesOf(v).stream().anyMatch(edges::contains); }
/** * Returns a list of vertices that are the neighbors of a specified vertex. If the graph is a * multigraph vertices may appear more than once in the returned list. * * <p> * The method uses {@link Graph#edgesOf(Object)} to traverse the graph. * * @param g the graph to look for neighbors in * @param vertex the vertex to get the neighbors of * @param <V> the graph vertex type * @param <E> the graph edge type * * @return a list of the vertices that are the neighbors of the specified vertex. */ public static <V, E> List<V> neighborListOf(Graph<V, E> g, V vertex) { List<V> neighbors = new ArrayList<>(); for (E e : g.edgesOf(vertex)) { neighbors.add(getOppositeVertex(g, e, vertex)); } return neighbors; }
/** * Returns the predecessors of {@code vertex} in the order defined by {@code map}. More * precisely, returns those of {@code vertex}, whose mapped index in {@code map} is less then * the index of {@code vertex}. * * @param vertexInOrder defines the mapping of vertices in {@code graph} to their indices in * order. * @param vertex the vertex whose predecessors in order are to be returned. * @return the predecessors of {@code vertex} in order defines by {@code map}. */ private Set<V> getPredecessors(Map<V, Integer> vertexInOrder, V vertex) { Set<V> predecessors = new HashSet<>(); Integer vertexPosition = vertexInOrder.get(vertex); Set<E> edges = graph.edgesOf(vertex); for (E edge : edges) { V oppositeVertex = Graphs.getOppositeVertex(graph, edge, vertex); Integer destPosition = vertexInOrder.get(oppositeVertex); if (destPosition < vertexPosition) predecessors.add(oppositeVertex); } return predecessors; }
/** * Returns the predecessors of {@code vertex} in the order defined by {@code map}. More * precisely, returns those of {@code vertex}, whose mapped index in {@code map} is less then * the index of {@code vertex}. * * @param vertexInOrder defines the mapping of vertices in {@code graph} to their indices in * order. * @param vertex the vertex whose predecessors in order are to be returned. * @return the predecessors of {@code vertex} in order defines by {@code map}. */ private Set<V> getPredecessors(Map<V, Integer> vertexInOrder, V vertex) { Set<V> predecessors = new HashSet<>(); Integer vertexPosition = vertexInOrder.get(vertex); Set<E> edges = graph.edgesOf(vertex); for (E edge : edges) { V oppositeVertex = Graphs.getOppositeVertex(graph, edge, vertex); Integer destPosition = vertexInOrder.get(oppositeVertex); if (destPosition < vertexPosition) predecessors.add(oppositeVertex); } return predecessors; }
/** * Returns the predecessors of {@code vertex} in the order defined by {@code map}. More * precisely, returns those of {@code vertex}, whose mapped index in {@code map} is less then * the index of {@code vertex}. * * @param vertexInOrder defines the mapping of vertices in {@code graph} to their indices in * order. * @param vertex the vertex whose predecessors in order are to be returned. * @return the predecessors of {@code vertex} in order defines by {@code map}. */ private Set<V> getPredecessors(Map<V, Integer> vertexInOrder, V vertex) { Set<V> predecessors = new HashSet<>(); Integer vertexPosition = vertexInOrder.get(vertex); Set<E> edges = graph.edgesOf(vertex); for (E edge : edges) { V oppositeVertex = Graphs.getOppositeVertex(graph, edge, vertex); Integer destPosition = vertexInOrder.get(oppositeVertex); if (destPosition < vertexPosition) { predecessors.add(oppositeVertex); } } return predecessors; }
/** * Returns the predecessors of {@code vertex} in the order defined by {@code map}. More * precisely, returns those of {@code vertex}, whose mapped index in {@code map} is less then * the index of {@code vertex}. * * @param vertexInOrder defines the mapping of vertices in {@code graph} to their indices in * order. * @param vertex the vertex whose predecessors in order are to be returned. * @return the predecessors of {@code vertex} in order defines by {@code map}. */ private Set<V> getPredecessors(Map<V, Integer> vertexInOrder, V vertex) { Set<V> predecessors = new HashSet<>(); Integer vertexPosition = vertexInOrder.get(vertex); Set<E> edges = graph.edgesOf(vertex); for (E edge : edges) { V oppositeVertex = Graphs.getOppositeVertex(graph, edge, vertex); Integer destPosition = vertexInOrder.get(oppositeVertex); if (destPosition < vertexPosition) predecessors.add(oppositeVertex); } return predecessors; } }
/** * {@inheritDoc} */ @Override public Set<E> edgesOf(V vertex) { assertVertexExist(vertex); return new MaskEdgeSet<>(base, base.edgesOf(vertex), vertexMask, edgeMask); }
private void simpleHeuristic() { for (V v : partition1) { E maxEdge = null; BigDecimal maxWeight = BigDecimal.ZERO; for (E e : graph.edgesOf(v)) { BigDecimal w = BigDecimal.valueOf(graph.getEdgeWeight(e)); if (comparator.compare(w, maxWeight) > 0) { maxWeight = w; maxEdge = e; } } pot.put(v, maxWeight); if (maxEdge != null) { V u = Graphs.getOppositeVertex(graph, maxEdge, v); if (!matchedEdge.containsKey(u)) { matching.add(maxEdge); matchingWeight = matchingWeight.add(maxWeight); matchedEdge.put(v, maxEdge); matchedEdge.put(u, maxEdge); } } } } }
/** * Computes and returns neighbours of {@code vertex} which haven't been visited by this * iterator. * * @param vertex the vertex, whose neighbours are being explored. * @return neighbours of {@code vertex} which have yet to be visited by this iterator. */ private Set<V> getUnvisitedNeighbours(V vertex) { Set<V> unmapped = new HashSet<>(); Set<E> edges = graph.edgesOf(vertex); for (E edge : edges) { V oppositeVertex = Graphs.getOppositeVertex(graph, edge, vertex); if (bucketList.containsBucketWith(oppositeVertex)) { unmapped.add(oppositeVertex); } } return unmapped; }
/** * Increments the cardinalities of the neighbours of the {@code vertex} by 1. If the maximum * cardinality increases, increments {@code maxCardinality} by 1. * * @param vertex the vertex whose neighbours are to be updated. */ private void updateNeighbours(V vertex) { Set<V> processed = new HashSet<>(); for (E edge : graph.edgesOf(vertex)) { V opposite = Graphs.getOppositeVertex(graph, edge, vertex); if (cardinalityMap.containsKey(opposite) && !processed.contains(opposite)) { processed.add(opposite); addToBucket(opposite, removeFromBucket(opposite) + 1); } } if (maxCardinality < graph.vertexSet().size() && maxCardinality >= 0 && buckets.get(maxCardinality + 1) != null) { ++maxCardinality; } } }