public static boolean StarBicoloringDynamicOrdering( GraphModel g, Vector<Integer> V_r, Vector<Integer> V_c, int Ordering) { Vector<Integer> forbiddenColors = new Vector<>(V_r.size()); for (int i = 0; i < V_r.size(); i++) forbiddenColors.add(-1); Vector<Integer> Vertices = new Vector<>(V_r.size() + V_c.size()); // GraphModel gg = g.getCopy(); for (int i = 0; i < V_r.size(); i++) { Vertices.add(g.getVertex(i).getId()); } for (int i = 0; i < V_c.size(); i++) { Vertices.add(g.getVertex(i).getId()); } if (Ordering != 0) { if (Ordering == 1) { Vertices = OrderingHeuristics.LFO(g, Vertices); } if (Ordering == 2) { Vertices = OrderingHeuristics.SLO(g, Vertices); } if (Ordering == 3) { Vertices = OrderingHeuristics.IDO(g, Vertices); } } for (int v : Vertices) { if (g.getVertex(v).getColor() != 0) { forbiddenColors.set(0, v); for (Vertex w : g.getNeighbors(g.getVertex(v))) { if (w.getColor() <= 0) { for (Vertex x : g.getNeighbors(w)) { if (x.getColor() > 0) forbiddenColors.set(x.getColor(), v); } } else { for (Vertex x : g.getNeighbors(w)) { if (x.getColor() > 0) { for (Vertex y : g.getNeighbors(x)) { if (y.getColor() > 0) { if (w.getColor() == y.getColor() && w.getId() != y.getId()) { forbiddenColors.set(x.getColor(), v); } } } } } } } } for (int i = 0; i < forbiddenColors.size(); i++) { if (forbiddenColors.get(i) != v) g.getVertex(v).setColor(i); } } return true; }
public static boolean StarBicoloringRestricted( GraphModel g, Vector<Integer> V_r, Vector<Integer> V_c) { Vector<Integer> forbiddenColors = new Vector<>(V_r.size()); for (int i = 0; i < V_r.size(); i++) forbiddenColors.add(-1); Vector<Integer> Vertices = new Vector<>(V_r.size() + V_c.size()); // GraphModel gg = g.getCopy(); for (int v_r : V_r) Vertices.add(v_r); for (int v_c : V_c) Vertices.add(v_c); for (int v : Vertices) { if (g.getVertex(v).getColor() != 0) { forbiddenColors.set(0, v); for (Vertex w : g.getNeighbors(g.getVertex(v))) { if (w.getColor() <= 0) { for (Vertex x : g.getNeighbors(w)) { if (x.getColor() > 0) { if (g.getEdge(x, w).getWeight() == 1 || g.getEdge(w, g.getVertex(v)).getWeight() == 1) { forbiddenColors.set(x.getColor(), v); } } } } else { for (Vertex x : g.getNeighbors(w)) { System.out.println(" jez " + g.getEdge(x, w).getWeight()); if (g.getEdge(x, w).getWeight() == 1) { if (x.getColor() > 0) { for (Vertex y : g.getNeighbors(x)) { if (y.getColor() > 0) { if (w.getColor() == y.getColor() && w.getId() != y.getId()) { forbiddenColors.set(x.getColor(), v); } } } } } } } } } for (int i = 0; i < forbiddenColors.size(); i++) { if (forbiddenColors.get(i) != v) { g.getVertex(v).setColor(i); } } } return true; }
public static int StarBicoloringSchemeCombinedVertexCoverColoringRestricted( GraphModel g, final Vector<Integer> V_rr, final Vector<Integer> V_cc, final int Mode) { Vector<Integer> IS = new Vector<>(); Vector<Integer> V_r = new Vector<>(); Vector<Integer> V_c = new Vector<>(); V_r.addAll(V_rr); V_c.addAll(V_cc); Vector<Integer> num_colors; Vector<Integer> V_r_aux = new Vector<>(); Vector<Integer> V_c_aux = new Vector<>(); V_r_aux.addAll(V_r); V_c_aux.addAll(V_c); GraphModel gaux = g.getCopy(); float ratio = 1; if (Mode != 1) ratio = Mode / 2; Vector<Pair<Integer, Integer>> Degree_V_r_aux = new Vector<>(); Vector<Pair<Integer, Integer>> Degree_V_c_aux = new Vector<>(); Vector<Pair<Integer, Integer>> copy_real_r = new Vector<>(); Vector<Pair<Integer, Integer>> copy_real_c = new Vector<>(); Vector<Integer> forbiddenColors = new Vector<>(V_r.size()); for (int i = 0; i < V_r.size(); i++) { forbiddenColors.add(-1); } Iterator<Integer> v_r_aux_it = V_r_aux.iterator(); for (int v_r : V_r) { if (v_r_aux_it.hasNext()) { int v_r_aux = v_r_aux_it.next(); copy_real_r.add(new Pair<>(v_r, v_r_aux)); } } Iterator<Integer> v_c_aux_it = V_c_aux.iterator(); for (int v_c : V_c) { if (v_c_aux_it.hasNext()) { int v_c_aux = v_c_aux_it.next(); copy_real_c.add(new Pair<>(v_c, v_c_aux)); } } for (int v_r : V_r_aux) { Degree_V_r_aux.add(new Pair<>(v_r, gaux.getDegree(gaux.getVertex(v_r)))); } for (int v_c : V_c_aux) { Degree_V_c_aux.add(new Pair<>(v_c, gaux.getDegree(gaux.getVertex(v_c)))); } while (gaux.getEdgesCount() > 0) { int max_degree_V_r_aux = 0; for (Pair<Integer, Integer> di : Degree_V_r_aux) { di.second = gaux.getDegree(gaux.getVertex(di.first)); int degree_v_r = di.second; if (degree_v_r > max_degree_V_r_aux) { max_degree_V_r_aux = degree_v_r; } } System.out.println("1"); int max_degree_V_c_aux = 0; for (Pair<Integer, Integer> di : Degree_V_c_aux) { di.second = gaux.getDegree(gaux.getVertex(di.first)); int degree_v_c = di.second; if (degree_v_c > max_degree_V_c_aux) { max_degree_V_c_aux = degree_v_c; } } System.out.println("2"); if (max_degree_V_r_aux > ratio * max_degree_V_c_aux) { Vector<Pair<Integer, Integer>> removedEdges = new Vector<>(); for (Pair<Integer, Integer> di : Degree_V_r_aux) { if (max_degree_V_r_aux == di.second) { Pair<Integer, Integer> cr = new Pair<>(0, 0); for (Pair<Integer, Integer> crtmp : copy_real_r) { if (crtmp.second.equals(di.first)) { cr = crtmp; break; } } int v = 0; for (int tmp : V_r) { if (cr.first == v) { v = tmp; break; } } System.out.println("33"); IndSet.clearVertex(gaux.getVertex(di.first), gaux); removedEdges.add(di); System.out.println("44"); forbiddenColors.set(0, v); for (Vertex w : g.getNeighbors(g.getVertex(v))) { if (w.getColor() <= 0) { for (Vertex x : g.getNeighbors(w)) { if (x.getColor() > 0) { if (g.getEdge(w, g.getVertex(v)).getWeight() == 1 || g.getEdge(w, x).getWeight() == 1) { forbiddenColors.set(x.getId(), v); } } } } else { // Color[w]>0 for (Vertex x : g.getNeighbors(w)) { if (x.getColor() > 0) { if (g.getEdge(w, x).getWeight() == 1) { for (Vertex y : g.getNeighbors(x)) { if (y.getColor() > 0) { if (w.getColor() == y.getColor() && w.getId() != y.getId()) { forbiddenColors.set(x.getId(), v); } } } } } } } System.out.println("45s"); } System.out.printf("456"); // Find first color which can be assigned to v_c for (int i = 0; i < forbiddenColors.size(); i++) { if (forbiddenColors.get(i) != v) { g.getVertex(v).setColor(forbiddenColors.get(i)); break; } } System.out.println("500"); } } Degree_V_r_aux.removeAll(removedEdges); } else { Vector<Pair<Integer, Integer>> removedEdges = new Vector<>(); for (Pair<Integer, Integer> di : Degree_V_c_aux) { if (max_degree_V_c_aux == di.second) { Pair<Integer, Integer> cr = new Pair<>(0, 0); for (Pair<Integer, Integer> crtmp : copy_real_c) { if (crtmp.second == di.first) { cr = crtmp; break; } } int v = 0; for (int tmp : V_c) { if (cr.first == v) { v = tmp; break; } } IndSet.clearVertex(gaux.getVertex(di.first), gaux); removedEdges.add(di); System.out.println("3"); forbiddenColors.set(0, v); System.out.println("3.0q" + v); for (Vertex w : g.getNeighbors(g.getVertex(v))) { System.out.println("3.1"); if (w.getColor() <= 0) { for (Vertex x : g.getNeighbors(w)) { if (x.getColor() > 0) { if (g.getEdge(w, g.getVertex(v)).getWeight() == 1 || g.getEdge(w, x).getWeight() == 1) { forbiddenColors.set(x.getId(), v); } } } System.out.println("3.2"); } else { // Color[w]>0 for (Vertex x : g.getNeighbors(w)) { System.out.println("3.3"); if (x.getColor() > 0) { if (g.getEdge(w, x).getWeight() == 1) { for (Vertex y : g.getNeighbors(x)) { if (y.getColor() > 0) { if (w.getColor() == y.getColor() && w.getId() != y.getId()) { forbiddenColors.set(x.getId(), v); } } } } } } } } System.out.println("3.5"); // Find first color which can be assigned to v_c for (int i = 0; i < forbiddenColors.size(); i++) { if (forbiddenColors.get(i) != v) { g.getVertex(v).setColor(forbiddenColors.get(i)); break; } } } } System.out.println("4"); Degree_V_c_aux.removeAll(removedEdges); } } for (Pair<Integer, Integer> di : Degree_V_r_aux) { IS.add(di.first); } for (Pair<Integer, Integer> di : Degree_V_c_aux) { IS.add(di.first); } for (int i = 0; i < IS.size(); i++) { g.getVertex(IS.get(i)).setColor(0); } return getNumOfCols(g); }