Exemplo n.º 1
0
  /**
   * @param label The label of the Vertex to remove
   * @return Vertex The removed Vertex object
   */
  public Vertex removeVertex(String label) {
    Vertex v = vertices.remove(label);

    while (v.getNeighborCount() > 0) {
      this.removeEdge(v.getNeighbor((0)));
    }

    return v;
  }
Exemplo n.º 2
0
  /**
   * This method adds a Vertex to the graph. If a Vertex with the same label as the parameter exists
   * in the Graph, the existing Vertex is overwritten only if overwriteExisting is true. If the
   * existing Vertex is overwritten, the Edges incident to it are all removed from the Graph.
   *
   * @param vertex
   * @param overwriteExisting
   * @return true iff vertex was added to the Graph
   */
  public boolean addVertex(Vertex vertex, boolean overwriteExisting) {
    Vertex current = this.vertices.get(vertex.getLabel());
    if (current != null) {
      if (!overwriteExisting) {
        return false;
      }

      while (current.getNeighborCount() > 0) {
        this.removeEdge(current.getNeighbor(0));
      }
    }

    vertices.put(vertex.getLabel(), vertex);
    return true;
  }
  private void discharge(Vertex u) {
    // System.out.println("Discharging " + u);
    while (u.getExcess() > 0) {
      if (u.getCurrNeighbor() >= u.getNumNeighbors()) {
        relabel(u);
        u.setCurrNeighbor(0);
      } else {
        Vertex v = u.getNeighbor(u.getCurrNeighbor());

        if (getResidualCapacity(u, v) > 0 && u.getHeight() == v.getHeight() + 1) {
          push(u, v);
        } else {
          u.incNextNeighbor();
        }
      }
    }
  }