Interface IEdgeSet

All Superinterfaces:
Collection<Integer>, EdgeSet<Integer,Integer>, IntCollection, IntIterable, IntSet, Iterable<Integer>, Set<Integer>

public interface IEdgeSet extends EdgeSet<Integer,Integer>, IntSet
Set of int graph edges.

This interface is a specification of EdgeSet for IntGraph.

A set of integers, each represent an edge ID in a graph

 
 IntGraph g = ...;
 int vertex = ...;
 for (IEdgeIter eit = g.outEdges(vertex).iterator(); eit.hasNext();) {
 	int e = eit.nextInt();
 	int u = eit.sourceInt();
 	int v = eit.targetInt();
 	assert vertex == u;
 	System.out.println("Out edge of " + vertex + ": " + e + "(" + u + ", " + v + ")");
 }
 
Author:
Barak Ugav
See Also:
  • Method Details

    • iterator

      IEdgeIter iterator()
      Return an edge iterator that iterate over the edges in this set.
      Specified by:
      iterator in interface Collection<Integer>
      Specified by:
      iterator in interface EdgeSet<Integer,Integer>
      Specified by:
      iterator in interface IntCollection
      Specified by:
      iterator in interface IntIterable
      Specified by:
      iterator in interface IntSet
      Specified by:
      iterator in interface Iterable<Integer>
      Specified by:
      iterator in interface Set<Integer>
    • intIterator

      default IEdgeIter intIterator()
      Return an edge iterator that iterate over the edges in this set.
      Specified by:
      intIterator in interface IntCollection
      Specified by:
      intIterator in interface IntIterable
    • 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