Exemplo n.º 1
0
        static bool IsChoosable(this IGraph_uint graph, uint[] colorGraph, uint liveVertexBits, int c, Dictionary <BitLevelGeneration.HashedAssignment_uint, bool> cache, ref long nodesVisited, ref long cacheHits)
        {
            nodesVisited++;

            graph.BeGreedy(colorGraph, ref liveVertexBits, c);
            if (liveVertexBits == 0)
            {
                return(true);
            }
            if ((liveVertexBits & ~colorGraph.Or(c)) != 0)
            {
                return(false);
            }

            //bool cachedResult;
            //var key = new BitLevelGeneration.HashedAssignment_uint(colorGraph, c, liveVertexBits);
            //if (cache.TryGetValue(key, out cachedResult))
            //{
            //    cacheHits++;
            //    return cachedResult;
            //}

            var choosable = false;
            var V         = colorGraph[c] & liveVertexBits;

            foreach (var C in graph.MaximalIndependentSubsets(V))
            {
                if (graph.IsChoosable(colorGraph, liveVertexBits ^ C, c + 1, cache, ref nodesVisited, ref cacheHits))
                {
                    choosable = true;
                    break;
                }
            }

            //cache[key] = choosable;
            return(choosable);
        }