コード例 #1
0
  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();
        }
      }
    }
  }
コード例 #2
0
  private void setupSourceSide(Set<Employee> emps) {
    for (Employee e : emps) {
      Vertex u = Vertex.vertexFromEmployee(e);
      LV.add(u);

      source.addToNeighbors(u);
      u.addToNeighbors(source);

      setCapacity(source, u, 1);
      setFlow(source, u, 1);
      u.setExcess(1);

      // Prioritize friend for initial flow
      if (e.getId() == ProjectParams.FRIEND_ID) {
        V.addFirst(u);
      } else {
        V.add(u);
      }
    }

    source.setExcess(source.getExcess() - source.getNumNeighbors());
  }