Exemplo n.º 1
0
  private boolean depthFirstSearchRecursive(
      VertexType vertex, VertexType fromVertex, PreWorkPostWorkHandler<VertexType> handler)
      throws InvalidVertexException {
    // TODO:Implementing non-recursive version
    // int vertexId = vertex.getId();
    vertex.setMark(true);
    if (handler != null) if (handler.doPreWork(fromVertex, vertex)) return true;
    dispatchEvent(new PreWorkEvent<VertexType, EdgeType>(fromVertex, vertex, graph));
    EventUtils.algorithmStep(this, "visit: " + vertex.getId());
    VertexType lastInDepthVertex = vertex;

    for (VertexType i : graph) {
      if (graph.isEdge(vertex, i)) {
        if (!i.getMark()) {
          lastInDepthVertex = i;
          if (depthFirstSearchRecursive(i, vertex, handler)) return true;
        }
      }
    }

    dispatchEvent(new PostWorkEvent<VertexType, EdgeType>(lastInDepthVertex, vertex, graph));
    EventUtils.algorithmStep(this, "leave: " + vertex.getId());

    if (handler != null) if (handler.doPostWork(lastInDepthVertex, vertex)) return true;

    return false;
  }
Exemplo n.º 2
0
  /**
   * A wrapper for getting vertex Id's which supports multiple vertex owners.
   *
   * @param v Vertex which the caller intends to get its Id.
   * @return The Id.
   */
  protected int getId(VertexType v) {
    if (subgraphIndex != 0) {
      return v.getSubgraphId(subgraphIndex);
    }

    return v.getId();
  }
Exemplo n.º 3
0
  private void informVertices() {
    if (isSubgraph) superGraph.informVertices();

    for (VertexType v : this) {
      v.informNewSubgraph();
    }
  }
 public EdgeType createEdge(VertexType source, VertexType target) {
   EdgeType edge = allocateEdge(source, target);
   edgeList.add(edge);
   source.addOutgoingEdge(edge);
   target.addIncomingEdge(edge);
   edge.setLabel(maxEdgeLabel++);
   return edge;
 }
Exemplo n.º 5
0
 @Override
 public int compareTo(ActualEdgeType other) {
   int cmp = source.compareTo(other.getSource());
   if (cmp != 0) {
     return cmp;
   }
   return target.compareTo(other.getTarget());
 }
Exemplo n.º 6
0
 @Override
 public boolean equals(Object o) {
   if (!(o instanceof AbstractEdge)) {
     return false;
   }
   AbstractEdge<?, ?> other = (AbstractEdge<?, ?>) o;
   return source.equals(other.source) && target.equals(other.target);
 }
Exemplo n.º 7
0
  /**
   * Runs Depth First Search (DFS) algorithm on the graph starting from vertex <I>vertexId</I>. A
   * reference to a PreWorkPostWorkHandler is supplied that contains implementation of pre-work and
   * post-work operations that depends on the application of DFS.
   *
   * @param vertex Index of the starting vertex of the traversal.
   * @param handler A reference to a PreWorkPostWorkHandler that contains implementation of pre-work
   *     and post-work operations that depends on the application of DFS.
   * @param resetMarks If the search should reset vertex visit marks.
   * @return Whether the traversal has stopped at the middle by the handler.
   */
  public boolean doSearch(
      VertexType vertex, PreWorkPostWorkHandler<VertexType> handler, boolean resetMarks)
      throws InvalidVertexException, InvalidGraphException {

    if (graph == null) throw new InvalidGraphException("Graph object is null.");

    if (resetMarks) for (VertexType v : graph) v.setMark(false);

    return depthFirstSearchRecursive(vertex, vertex, handler);
  }
Exemplo n.º 8
0
 @Override
 public int hashCode() {
   int result = kmer != null ? kmer.hashCode() : 0;
   result = 31 * result + pos;
   result = 31 * result + (vertexType != null ? vertexType.hashCode() : 0);
   result = 31 * result + (missingFromGraph ? 1 : 0);
   result = 31 * result + cov;
   return result;
 }
Exemplo n.º 9
0
  public Vector<VertexType> acyclicSP(BaseGraph<VertexType, EdgeType> g, VertexType v)
      throws InvalidVertexException {
    BaseGraph<VertexType, EdgeType> gcopy = g.copy(gc);
    final Integer dist[] = new Integer[g.getVerticesCount()];
    Vector<VertexType> prev = new Vector<VertexType>();
    Queue<VertexType> Q = new LinkedList<VertexType>();
    HashMap<VertexType, VertexType> gcopy2g = new HashMap<VertexType, VertexType>();
    HashMap<Integer, VertexType> t = new HashMap<Integer, VertexType>();
    for (VertexType type : gcopy) t.put(type.getId(), type);
    for (VertexType type : g) gcopy2g.put(t.get(type.getId()), type);
    for (int i = 0; i < dist.length; i++) dist[i] = Integer.MAX_VALUE;

    dist[v.getId()] = 0;

    for (VertexType u : gcopy) {
      if (gcopy.getInDegree(u) == 0) {
        Q.add(u);
      }
    }

    while (!Q.isEmpty()) {
      VertexType u = Q.poll();
      Iterator<EdgeType> iet = gcopy.edgeIterator(u);
      while (iet.hasNext()) {
        EdgeType e = iet.next();
        if ((dist[u.getId()] + e.getWeight()) < dist[e.target.getId()]) {
          dist[e.target.getId()] = dist[u.getId()] + e.getWeight();
          prev.add(e.target.getId(), u);
          dispatchEvent(
              new PreWorkEvent<VertexType, EdgeType>(gcopy2g.get(e.target), gcopy2g.get(u), gcopy));
          //                    System.out.println(e.target.getId());
        }
        if (gcopy.getInDegree((VertexType) e.target) == 1) Q.add((VertexType) e.target);
      }
      gcopy.removeVertex(u);
    }
    return prev;
  }
Exemplo n.º 10
0
 /**
  * Deep copy.
  *
  * @param vt vertexType to be deep copied.
  */
 public VertexType(VertexType vt) {
   setValue(vt.getValue());
 }
 public IncomingEdgeIterator(VertexType target) {
   this.edge = target.getFirstIncomingEdge();
 }
 public OutgoingEdgeIterator(VertexType source) {
   this.edge = source.getFirstOutgoingEdge();
 }
 public void addVertex(VertexType v) {
   vertexList.add(v);
   v.setLabel(maxVertexLabel++);
 }
Exemplo n.º 14
0
 @Override
 public int hashCode() {
   return source.hashCode() + target.hashCode() * 3;
 }