Example usage for com.google.common.graph ValueGraph edges

List of usage examples for com.google.common.graph ValueGraph edges

Introduction

In this page you can find the example usage for com.google.common.graph ValueGraph edges.

Prototype

@Override
Set<EndpointPair<N>> edges();

Source Link

Usage

From source file:io.acoia.graphs.MinimumSpanningTree.java

/**
 * Sorts the edges of the provided ValueGraph and then calls kruskals(ValueGraph<N, E> g,
 * List<EndpointPair<N>> sortedEdges). Due to the need to sort the edges this method requires edge
 * values in the graph to implement Comparable.
 * /* w  w w  . j av a2  s . com*/
 * Due to the need to sort this method sorts the edges (O(E log(E))) before calling Kruskal's (O(E (V))) .
 */
public static <N, E extends Comparable<E>> ValueGraph<N, E> kruskals(ValueGraph<N, E> g) {
    Set<EndpointPair<N>> edges = g.edges();

    List<EndpointPair<N>> sortedEdges = edges.stream().sorted((ep1, ep2) -> g
            .edgeValue(ep1.nodeU(), ep1.nodeV()).compareTo(g.edgeValue(ep2.nodeU(), ep2.nodeV())))
            .collect(Collectors.toList());

    return kruskals(g, sortedEdges);
}