Beispiel #1
0
 private static int smallByDomain(int nodes, ArrayList l) {
   int arr[] = g.getSortedDeg();
   int n, nod = 0;
   int m, min = 10000;
   for (int i = 2 * nodes / 3; i >= 0; i--) {
     if (!l.contains(arr[i])) {
       n = arr[i];
       m = 0;
       for (int j = 0; j < noOfColors; j++) {
         if (domainOfNode[i][j] != 0) m++;
       }
       if (m < min) {
         min = m;
         nod = n;
       }
     }
   }
   return nod;
 }
Beispiel #2
0
  private static void colorTheGraph(int nodes) {
    initialiseDomain(nodes);
    int arr[] = g.getSortedDeg();
    ArrayList<Integer> l = new ArrayList<Integer>();
    int n;
    for (int i = nodes - 1; i > 2 * nodes / 3; i--) {
      n = arr[i];
      n = colorNodes(nodes, n);
      boolean check = checkConstraints(nodes, n);
      if (check == false) n = backtrack(nodes, n);
      else l.add(n);
    }

    for (int i = 2 * nodes / 3; i >= 0; i--) {
      n = smallByDomain(nodes, l);
      n = colorNodes(nodes, n);
      boolean check = checkConstraints(nodes, n);
      if (check == false) {
        n = backtrack(nodes, n);
      } else {
        l.add(n);
      }
    }
  }