Exemplo n.º 1
0
  /**
   * Make sure that distances are marked on the graph before running this.
   *
   * <p>For each node, this code checks any combination of from-to distance pairs. If the node is on
   * a shortest+k path between from-to, then the to_from_path_map is used to mark this.
   */
  public void run() {
    for (Node node : graph.getNodes()) {
      Map<Node, Integer> distFrom = (Map<Node, Integer>) node.getLabel(MarkDistances.DIST_FROM);
      Map<Node, Integer> distTo = (Map<Node, Integer>) node.getLabel(MarkDistances.DIST_TO);

      // Ignore nodes that are not in the middle of something

      if (distFrom == null || distTo == null) {
        continue;
      }

      // for each from-to pairs  check if this node is on a shortest+k path

      for (Node from : distFrom.keySet()) {
        assert from.hasSignificantExperimentalChange(ExperimentData.EXPRESSION_DATA);

        // We do not want to mark this node as on its shortest path
        //				if (from == node)
        //				{
        //					continue;
        //				}

        for (Node to : distTo.keySet()) {
          // We do not want to mark this node as on its shortest path
          //					if (to == node)
          //					{
          //						continue;
          //					}
          if (from == node) {
            continue;
          }

          int s = getShortestDistance(from, to);

          if (s <= limit) {
            // If shortest+k is higher than limit, then use limit
            int d = Math.min(s + k, limit);

            // If the length of the path from-to that contains this node
            // is within limits, mark it.

            int foundDistance = distFrom.get(from) + distTo.get(to);

            if (!node.isBreadthNode()) {
              foundDistance++;
            }

            if (foundDistance <= d) {
              Map<Node, Set<Node>> tofromPathMap = getToFromPathMap(node);

              if (!tofromPathMap.containsKey(to)) {
                tofromPathMap.put(to, new HashSet<Node>());
              }

              Set<Node> fromSet = tofromPathMap.get(to);
              fromSet.add(from);

              // So, during a backwards traversing, starting at "to", when we visit
              // this node, then we will know where to go.
            }
          }
        }
      }
    }
  }
Exemplo n.º 2
0
 public void clearLabels() {
   graph.removeLabels(
       Arrays.asList(TO_FROM_PATH_MAP, MarkDistances.DIST_FROM, MarkDistances.DIST_TO));
 }