コード例 #1
1
ファイル: ColorAlgs.java プロジェクト: Masoumeh/GraphTea
  /**
   * Compute a distance-2 coloring of a bipartite graph G_b restricted to required edges
   *
   * <p>Input: - G_b bipartite graph with required egdes given as weights edge_weight - V contained
   * vertices are colored in the given ordering v_1, ..., v_n
   *
   * <p>Output: - G_b bipartite graph with colors as weights vertex_color
   */
  public static int PartialD2ColoringRestricted(GraphModel g, Vector<Integer> V) {
    Vector<Integer> N2 = new Vector<>();
    Vector<Integer> forbidden = new Vector<>(g.numOfVertices());
    for (int i = 0; i < g.numOfVertices(); i++) forbidden.add(-1);
    for (int v : V) g.getVertex(v).setColor(0);

    for (int v : V) {
      forbidden.set(0, v);
      if (IncidentToReqEdge(g, v)) {
        N2 = Neighbors.N_2_restricted(g, v);
        for (int n2 : N2) {
          if (g.getVertex(n2).getColor() > 0) {
            forbidden.set(g.getVertex(n2).getColor(), v);
          }
        }
        for (int i = 0; i < forbidden.size(); i++) {
          if (forbidden.get(i) != v) {
            g.getVertex(v).setColor(i);
            break;
          }
        }
      } else {
        g.getVertex(v).setColor(0);
      }
    }

    return getNumOfCols(g);
  }
コード例 #2
0
ファイル: DFS.java プロジェクト: kuity/kotlin
 private static <N> void doDfs(
     @NotNull N current,
     @NotNull Neighbors<N> neighbors,
     @NotNull Visited<N> visited,
     @NotNull NodeHandler<N, ?> handler) {
   if (!visited.checkAndMarkVisited(current)) {
     return;
   }
   handler.beforeChildren(current);
   for (N neighbor : neighbors.getNeighbors(current)) {
     doDfs(neighbor, neighbors, visited, handler);
   }
   handler.afterChildren(current);
 }
コード例 #3
0
 /** Determines if all the given Neighbors are held by this set. */
 public boolean has(Neighbors neighbors) {
   return (ordinal() & neighbors.ordinal()) == neighbors.ordinal();
 }
コード例 #4
0
 /**
  * Returns a set of neighbors that contains all those held by this set, less those held by the
  * given set.
  */
 public Neighbors remove(Neighbors neighbors) {
   return Neighbors.values()[ordinal() & ~neighbors.ordinal()];
 }
コード例 #5
0
 /**
  * Returns the set of neighbors shared by this and the given Neighbors. Also known as an
  * <b>intersection</b>.
  */
 public Neighbors shared(Neighbors neighbors) {
   return Neighbors.values()[ordinal() & neighbors.ordinal()];
 }
コード例 #6
0
 /**
  * Returns the set of neighbors held by either this or the given Neighbors. Also known as a
  * <b>union</b>.
  */
 public Neighbors add(Neighbors neighbors) {
   return Neighbors.values()[ordinal() | neighbors.ordinal()];
 }