コード例 #1
0
        static bool IsChoosable(this IGraph_long graph, long[] colorGraph, long liveVertexBits, int c)
        {
            graph.BeGreedy(colorGraph, ref liveVertexBits, c);
            if (liveVertexBits == 0)
            {
                return(true);
            }
            if ((liveVertexBits & ~colorGraph.Or(c)) != 0)
            {
                return(false);
            }

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

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

            return(choosable);
        }
コード例 #2
0
 public static bool IsChoosable(this IGraph_long graph, long[] colorGraph)
 {
     return(graph.IsChoosable(colorGraph, Enumerable.Range(0, graph.N).To_long(), 0));
 }
コード例 #3
0
 public static bool IsChoosable(this IGraph_long graph, long[] colorGraph, long subset)
 {
     return(graph.IsChoosable(colorGraph, subset, 0));
 }
コード例 #4
0
        public static bool IsFChoosable(this IGraph_long graph, Func <int, int> f, out List <List <int> > badAssignment)
        {
            badAssignment = null;

            var liveVertexBits = Enumerable.Range(0, graph.N).To_long();
            var sizes          = graph.Vertices.Select(v => f(v)).ToList();
            var maxListSize    = sizes.Max();

            for (int potSize = maxListSize; potSize < graph.N; potSize++)
            {
                foreach (var colorGraph in BitLevelGeneration.Assignments_long.Enumerate(sizes, potSize))
                {
                    if (potSize > maxListSize)
                    {
                        var xx = 0L;
                        for (int i = 0; i < colorGraph.Length; i++)
                        {
                            xx |= colorGraph[i];

                            if (xx.PopulationCount() <= i + 1)
                            {
                                goto skip;
                            }
                        }

                        for (int i = 0; i < colorGraph.Length; i++)
                        {
                            for (int j = i + 1; j < colorGraph.Length; j++)
                            {
                                if ((colorGraph[i] & colorGraph[j]) == 0)
                                {
                                    goto skip;
                                }
                            }
                        }

                        foreach (var color in colorGraph)
                        {
                            if (graph.IsIndependent(color))
                            {
                                goto skip;
                            }
                        }
                    }


                    if (!graph.IsChoosable(colorGraph, liveVertexBits, 0))
                    {
                        badAssignment = new List <List <int> >();
                        foreach (var v in graph.Vertices)
                        {
                            var list = new List <int>();
                            var bit  = 1L << v;
                            for (int i = 0; i < colorGraph.Length; i++)
                            {
                                if ((bit & colorGraph[i]) != 0)
                                {
                                    list.Add(i);
                                }
                            }

                            badAssignment.Add(list);
                        }

                        return(false);
                    }

                    skip :;
                }
            }

            return(true);
        }