src/main/java/de/dfki/lt/loot/digraph/algo/TransitiveClosure.java
@SuppressWarnings("unchecked")
  public static <EdgeInfo> VertexPropertyMap<Set<Integer>>
  transitiveClosure(DiGraph<EdgeInfo> graph, boolean reflexive) {
    DiGraph<EdgeInfo> reduction = acyclicSccReduction(graph);

    // now do transitive closure on the acyclic graph
    VertexPropertyMap<Set<Integer>> redClosure = acyclicClosure(reduction);
    VertexPropertyMap<List<Integer>> origSccs =
        (VertexPropertyMap<List<Integer>>) reduction.getPropertyMap("originalSCCs");
    //VertexPropertyMap<Integer> redRepresentatives =
    //    (VertexPropertyMap<Integer>) graph.getPropertyMap("redRepresentatives");
    // and extend it to the components
    VertexPropertyMap<Set<Integer>> closure =
        new VertexListPropertyMap<Set<Integer>>(graph);
    // v is the representative of the SCC we're working on
    for (int v = 0; v < reduction.getNumberOfVertices(); ++v) {
      List<Integer> component = origSccs.get(v);
      int srcRepresentative = component.get(0);
      // add all component vertices to the closure
      Set<Integer> srcClosure = new HashSet<Integer>();
      closure.put(srcRepresentative, srcClosure);
      // when the graph is simple trivial components don't reach themselves
      if (component.size() > 1 || reflexive) {
        srcClosure.addAll(component);
      }
      for (int redVertex : redClosure.get(v)) {
        srcClosure.addAll(origSccs.get(redVertex));
      }
      // for all non-representative nodes, set the closure to the same set as
      // for the representative
      for (int i = 1; i < component.size(); ++i) {
        closure.put(component.get(i), srcClosure);
      }
    }
    return closure;
  }
/** Transitive closure on an cyclic graph. First compute the strongly
   *  connected components, reduce the graph to its acyclic residue, do the
   *  transitive closure on the acyclic part, and add the proper values to all
   *  non-representatives of the original graph.
   *
   *  @return the closure as VertexPropertyMap, mapping each vertex to all its
   *          reachable nodes.
   */
Transitive closure on an cyclic graph. First compute the strongly
connected components, reduce the graph to its acyclic residue, do the
transitive closure on the acyclic part, and add the proper values to all
non-representatives of the original graph.

@return the closure as VertexPropertyMap, mapping each vertex to all its
reachable nodes.
Transitive closure on an cyclic graph . First compute the strongly connected components reduce the graph to its acyclic residue do the transitive closure on the acyclic part and add the proper values to all non - representatives of the original graph . @return the closure as VertexPropertyMap mapping each vertex to all its reachable nodes .
@SuppressWarnings("unchecked")
  public static <EdgeInfo> VertexPropertyMap<Set<Integer>>
  transitiveClosure(DiGraph<EdgeInfo> graph, boolean reflexive) {
    DiGraph<EdgeInfo> reduction = acyclicSccReduction(graph);
    VertexPropertyMap<Set<Integer>> redClosure = acyclicClosure(reduction);
    VertexPropertyMap<List<Integer>> origSccs =
        (VertexPropertyMap<List<Integer>>) reduction.getPropertyMap("originalSCCs");
    VertexPropertyMap<Set<Integer>> closure =
        new VertexListPropertyMap<Set<Integer>>(graph);
    for (int v = 0; v < reduction.getNumberOfVertices(); ++v) {
      List<Integer> component = origSccs.get(v);
      int srcRepresentative = component.get(0);
      Set<Integer> srcClosure = new HashSet<Integer>();
      closure.put(srcRepresentative, srcClosure);
      if (component.size() > 1 || reflexive) {
        srcClosure.addAll(component);
      }
      for (int redVertex : redClosure.get(v)) {
        srcClosure.addAll(origSccs.get(redVertex));
      }
      for (int i = 1; i < component.size(); ++i) {
        closure.put(component.get(i), srcClosure);
      }
    }
    return closure;
  }
@ SuppressWarnings ( "unchecked" ) public static < EdgeInfo > VertexPropertyMap < Set < Integer > > transitiveClosure ( DiGraph < EdgeInfo > graph , boolean reflexive ) { DiGraph < EdgeInfo > reduction = acyclicSccReduction ( graph ) ; VertexPropertyMap < Set < Integer > > redClosure = acyclicClosure ( reduction ) ; VertexPropertyMap < List < Integer > > origSccs = ( VertexPropertyMap < List < Integer > > ) reduction . getPropertyMap ( "originalSCCs" ) ; VertexPropertyMap < Set < Integer > > closure = new VertexListPropertyMap < Set < Integer > > ( graph ) ; for ( int v = 0 ; v < reduction . getNumberOfVertices ( ) ; ++ v ) { List < Integer > component = origSccs . get ( v ) ; int srcRepresentative = component . get ( 0 ) ; Set < Integer > srcClosure = new HashSet < Integer > ( ) ; closure . put ( srcRepresentative , srcClosure ) ; if ( component . size ( ) > 1 || reflexive ) { srcClosure . addAll ( component ) ; } for ( int redVertex : redClosure . get ( v ) ) { srcClosure . addAll ( origSccs . get ( redVertex ) ) ; } for ( int i = 1 ; i < component . size ( ) ; ++ i ) { closure . put ( component . get ( i ) , srcClosure ) ; } } return closure ; }
Transitive closure on an cyclic graph.
Transitive closure on an cyclic graph .
// now do transitive closure on the acyclic graph //VertexPropertyMap<Integer> redRepresentatives = //    (VertexPropertyMap<Integer>) graph.getPropertyMap("redRepresentatives"); // and extend it to the components // v is the representative of the SCC we're working on // add all component vertices to the closure // when the graph is simple trivial components don't reach themselves // for all non-representative nodes, set the closure to the same set as // for the representative