Пример #1
0
 public static <NodeLabel, EdgeLabel> String toString(
     Graph<NodeLabel, EdgeLabel> graph, Edge edge) {
   return String.format(
       "(%s,%s)",
       graph.getNodeLabel(edge.getSourceNodeID()).toString(),
       graph.getNodeLabel(edge.getDestNodeID()).toString());
 }
Пример #2
0
  /**
   * compute the transitive closure of the input graph
   *
   * @param <NodeLabel>
   * @param <EdgeLabel>
   * @param original
   * @return
   */
  public static <NodeLabel, EdgeLabel> Graph<NodeLabel, EdgeLabel> transitiveClosure(
      Graph<NodeLabel, EdgeLabel> input) {
    Graph<NodeLabel, EdgeLabel> graph = AdjacencyList.copy(input);

    int numChange = 0;
    do {
      numChange = 0;
      for (NodeLabel from : graph.getNodeLabelSet()) {
        for (NodeLabel to : graph.getNodeLabelSet()) {
          if (graph.hasEdge(from, to)) continue;

          int destNodeID = graph.getNodeID(to);
          for (Edge startPoint : graph.getOutEdgeSet(from)) {
            int intermediateNodeID = startPoint.getDestNodeID();

            if (graph.hasEdge(new Edge(intermediateNodeID, destNodeID))) {
              graph.addEdge(from, to);
              ++numChange;
              break;
            }
          }
        }
      }
    } while (numChange > 0);

    return graph;
  }
Пример #3
0
 public static <NodeLabel, EdgeLabel> NodeLabel getDestNodeLabel(
     Graph<NodeLabel, EdgeLabel> graph, Edge edge) {
   return graph.getNodeLabel(edge.getDestNodeID());
 }