Created
December 12, 2012 22:34
-
-
Save soundsmitten/4272283 to your computer and use it in GitHub Desktop.
Java M-Coloring Graph algorithm.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Wikipedia: a way of coloring the vertices of a graph such that no two | |
// adjacent vertices share the same color; this is called a vertex coloring. | |
// Similarly, an edge coloring assigns a color to each edge so that no two adjacent | |
// edges share the same color, and a face coloring of a planar graph assigns a color to | |
// each face or region so that no two faces that share a boundary have the same color. | |
// In NP-complete | |
boolean mcolor(int i, int m, int n, bool [][] W, int [] vcolor, int n) | |
{ | |
// i: last colored vertex | |
// m: number of colors | |
// n: number of vertices | |
if (promising(i, vcolor, W)) { | |
if(i ==n) | |
{ | |
for (k=1;k<=n;k++) | |
System.out.println(k + ": " + vcolor[k]); | |
} | |
else | |
for (k=1; k<=m; k++) | |
{ | |
vcolor[i+1] = k; | |
mcolor (i+1,m,n,vcolor) | |
} | |
} | |
} | |
boolean promising (int i, int[] vcolor, bool[][]W) | |
{ | |
for (int k; k<i; k++) | |
if(W[i][k] && vcolor[i] == vcolor[k]) | |
return false; | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment