private Dictionary <int, int> ColourGraph(Graph graph, int upperBoundOnNumberOfSteps, double alphaRatio) { stopwatch.Restart(); var dummySolution = new Solution() { colourCount = int.MaxValue, }; var initialSolution = new Solution() { colourCount = 0, vertexToColour = new int[graph.VerticesKVPs.Length] }; for (int i = 0; i < graph.VerticesKVPs.Length; i++) { initialSolution.vertexToColour[i] = -1; } graph = graph.CloneNeighboursSorted(v => graph.VerticesKVPs[v].Length); var leftSteps = upperBoundOnNumberOfSteps; var solution = Recurse(graph, initialSolution, dummySolution, ref leftSteps, alphaRatio).vertexToColour; var dictionary = new Dictionary <int, int>(); for (int i = 0; i < solution.Length; i++) { dictionary.Add(i, solution[i]); } stopwatch.Stop(); return(dictionary); }
public Dictionary <int, int> ColourGraph(Graph graph) { stopwatch.Restart(); var dummySolution = new Solution() { colourCount = int.MaxValue, }; var initialSolution = new Solution() { colourCount = 0, colourLayer = new Stack <List <int> >() }; graph = graph.CloneNeighboursSorted(v => graph.VerticesKVPs[v].Length); // var solution = Recurse(graph, initialSolution, dummySolution, ref leftSteps, alphaRatio).vertexToColour; var dictionary = new Dictionary <int, int>(); //var misCount = 0; //var largestMIS = 0; //foreach (var mis in EnumerateMIS(graph)) //{ // misCount += 1; // if (mis.vertices.Count > largestMIS) // largestMIS = mis.vertices.Count; //} //System.Console.WriteLine($"MIS count: {misCount}, largest: {largestMIS}"); var ignoredVertices = new bool[graph.VerticesKVPs.Length]; var primaryGraph = new GraphFast(graph); var complementaryGraph = new GraphFast(graph); var bestSolution = Recurse(graph.VerticesKVPs.Length, primaryGraph, complementaryGraph, initialSolution, dummySolution); var layerColour = 0; foreach (var layer in bestSolution.colourLayer) { foreach (var vertex in layer) { dictionary.Add(vertex, layerColour); } layerColour += 1; } stopwatch.Stop(); return(dictionary); }