private void konigDFS(Set<Vertex> konigSet, Vertex v, boolean edgesInMatch) {
    if (!konigSet.contains(v)) {
      konigSet.add(v);

      for (Vertex neighb : v.getNeighbors()) {
        if (neighb.getId() != SOURCE_ID && neighb.getId() != SINK_ID) {
          if (edgesInMatch == (getFlow(v, neighb) > 0 || getFlow(neighb, v) > 0)) {
            konigDFS(konigSet, neighb, !edgesInMatch);
          }
        }
      }
    }
  }
 private void computeMatchSet() {
   for (Vertex v : LV) {
     for (Vertex neighb : v.getNeighbors()) {
       if (neighb.getId() != SOURCE_ID && getFlow(v, neighb) > 0) {
         matches.add(v);
         matches.add(neighb);
       }
     }
   }
 }
Esempio n. 3
0
 private void writeVertexProperties(Writer writer, Vertex e) throws IOException {
   Object blueprintsId = e.getId();
   if (!useId) {
     writeKey(writer, vertexIdKey);
     if (blueprintsId instanceof Number) {
       writeNumberProperty(writer, (Number) blueprintsId);
     } else {
       writeStringProperty(writer, blueprintsId);
     }
   }
   writeProperties(writer, e);
 }
Esempio n. 4
0
 private void writeVerticies(Writer writer, List<Vertex> verticies, Map<Vertex, Integer> ids)
     throws IOException {
   int count = 1;
   for (Vertex v : verticies) {
     if (useId) {
       Integer id = Integer.valueOf(v.getId().toString());
       writeVertex(writer, v, id);
       ids.put(v, id);
     } else {
       writeVertex(writer, v, count);
       ids.put(v, count++);
     }
   }
 }
  // Uses Konig's theorem to compute min vertex cover
  // Compute in both directions as the friend, may or may not appear in a
  // particular vertex cover, depending on graph structure
  private void computeInvitees() {
    Set<Vertex> result;
    Set<Vertex> minVertexCovers1 = computeMinVertexCover(LV, RV);
    Set<Vertex> minVertexCovers2 = computeMinVertexCover(RV, LV);

    if (minVertexCovers1.contains(friend)) {
      result = minVertexCovers1;
    } else {
      result = minVertexCovers2;
    }

    for (Vertex v : result) {
      invitees.add(v.getId());
    }
  }