0

I am working an m_coloring problem wherein I have to determine the chromatic number m of an undirected graph using backtracking. The (java) solution I have thus far is increment m, try the m_Coloring method, and then repeat if a solution is not found. However, for the larger files, if m is over 6, the computation takes forever. I have been told that the algorithm we were given to use does not have pruning incorporated, so I am trying to figure out how to put it in and am having no luck after a week of searching.

vColor = new int[nodes+1];
vColor[1] = 1;
while(unsolved)
{
    m++;
    mColoring(1);
}

static void mColoring(int i)
{
    int color;
    if (promising(i))
    {
        if (i==nodes)
        {
            unsolved = false;
        }
        else
        {
            for(color = 1; color<=m; color++)
            {
                if(unsolved)
                {
                    vColor[i+1] = color;
                    mColoring(i+1);
                }
            }
        }
    }
}

static public boolean promising (int i)
{
    int j=1;
    boolean promise = true;

    while(j<i && promise)
    {
        if(adjMatrix[i][j] && vColor[i] == vColor[j])
        {
            promise = false;
        }
        j++;
    }
    return promise;
}
thejames42
  • 447
  • 6
  • 22
  • [Here](https://secweb.cs.odu.edu/~zeil/cs361/web/website/Lectures/npprobs/pages/ar01s01s01.html) is some C++ code that implements your algorithm; it's close enough to Java that it ought to be enough to get you started. – Zim-Zam O'Pootertoot Apr 15 '13 at 04:27

1 Answers1

0

A simple, efficient and well known exact algorithm uses Brélaz minimum degree of saturation heuristic DSATUR (i.e. choose as new candidate vertex the one with less available colors, alias with more different colored neighbors) for branching inside a full enumeration scheme.

The basic pruning strategy is implicit: every candidate vertex can only have at most as many colors as used in the preceding vertices + 1 (the new color, assigned if it is saturated). This means that the search can be pruned along any branch which backtracks on a vertex whose last assignment was a new color.

I am sorry I can give you no reference to a Java implementation of an exact DSATUR-based algorithm but I can give C, C++ refs if you are interested.

chesslover
  • 347
  • 2
  • 6