Interface IEdgeSet

    • Method Detail

      • of

        static IEdgeSet of​(IntSet edges,
                           IntGraph g)
        Create an edge set object from a plain set of edges.

        A 'plain' set of edges is a set of the edges identifiers. It does not include any information about the endpoints (source and target) of each edge. This method creates an IEdgeSet, which does contains information about the endpoints, given a plain set of edges and the graph in which the edges are defined in.

        The returned set is a view of the given set and graph. Namely, its updated when the original set is updated and visa vera, and the endpoints in the IEdgeSet will be up to date with the given graph.

        No validation is performed to ensure that all the given edges are actually in the given graph. If this is not the case, an exception may be thrown later when the graph is queried for an edge source and target.

        Usually an IEdgeSet object is obtained via one of the method of a IntGraph, and rarely a user need to a create one, but it may be used to add multiple edges to a graph using the IntGraph.addEdges(EdgeSet) method. In the following snippet, a maximum cardinality matching is computed on a graph, and a new graph containing only the matching edges is created:

         
         IntGraph g = ...;
         IntSet matching = (IntSet) MatchingAlgo.newInstance().computeMaximumMatching(g, null).edges();
        
         IntGraph matchingGraph = IntGraph.newUndirected();
         matchingGraph.addVertices(g.vertices());
         matchingGraph.addEdges(IEdgeSet.of(matching, g));
         
        Parameters:
        edges - a set of edges identifiers
        g - the graph in which the edges are defined in, and from which the endpoints of the edges should be retrieved
        Returns:
        an IEdgeSet with the given edges, containing the endpoints information from the graph
      • allOf

        static IEdgeSet allOf​(IntGraph g)
        Create an edge set object of all the edges in a graph.

        The edge set returned by IntGraph.edges() is a 'plain' set of edges, namely it is a set of the edge identifiers themselves but does not include any information about the endpoints (source and target) of each edge. This method creates an IEdgeSet, which does contains information about the endpoints, of all the edges in a given graph.

        The returned set is a view of the given set and graph. Namely, its updated when the original set is updated and visa vera, and the endpoints in the IEdgeSet will be up to date with the given graph.

        Usually an IEdgeSet object is obtained via one of the method of a IntGraph, and rarely a user need to a create one, but it may be used to add multiple edges to a graph using the IntGraph.addEdges(EdgeSet) method. In the following snippet, an auxillary graph is created which is a copy of an original graph g with additional vertex connected to all the original vertices, for shortest path potential function computation (used in Johnson APSP):

         
         int auxillaryVertex = ...;
         IntGraph auxillaryGraph = IntGraph.newDirected();
         auxillaryGraph.addVertices(g.vertices());
         auxillaryGraph.addVertex(auxillaryVertex);
         auxillaryGraph.addEdges(IEdgeSet.allOf(g));
         for (int v : g.vertices())
         	auxillaryGraph.addEdge(auxillaryVertex, v);
         
        Parameters:
        g - a graph
        Returns:
        an IEdgeSet of all the edges in the graph