Exemplo n.º 1
0
        public static void Go()
        {
            File.Delete(WinnersFile);

            var allColors = Enumerable.Range(0, C).To_long();
            var w         = 0;

            var assignmentLookup = LoadLookup();

            for (var R = MinRingSize; R <= 9; R++)
            {
                System.Console.WriteLine("generating assignments for ring size " + R + "...");

                var partitionFile        = @"C:\Users\landon\Google Drive\research\Graph6\noncrossing\non_crossing" + R + ".txt";
                var possibleAssociations = NonCrossing.Load(partitionFile);
                var contractionsPile     = possibleAssociations.Select(ll => ll.Where(l => l.Count >= 2).Select(l => l.ToUInt64()).ToList()).Where(ll => ll.Count > 1).ToList();
                foreach (var contraction in contractionsPile)
                {
                    var key = new Key(R, contraction);
                    List <List <long> > assignments;
                    if (!assignmentLookup.TryGetValue(key, out assignments))
                    {
                        assignments           = RingAssignmentGenerator.GenerateAssignments(R, C, Fold, contraction);
                        assignmentLookup[key] = assignments;
                    }
                }
            }

            SaveLookup(assignmentLookup);

            for (int N = MinVertices; N <= MaxVertices; N++)
            {
                System.Console.ForegroundColor = ConsoleColor.DarkCyan;
                System.Console.WriteLine("Checking " + N + " vertex graphs...");
                System.Console.ForegroundColor = ConsoleColor.White;

                for (var R = MinRingSize; R <= MaxRingSize; R++)
                {
                    System.Console.ForegroundColor = ConsoleColor.DarkGray;
                    System.Console.WriteLine("Checking ring size " + R + "...");
                    System.Console.ForegroundColor = ConsoleColor.White;

                    var path = string.Format(@"C:\Users\landon\Google Drive\research\Graph6\triangulation\disk\triangulation{0}_{1}.g6.tri.weighted.txt", N, R);
                    if (!File.Exists(path))
                    {
                        continue;
                    }

                    var partitionFile        = @"C:\Users\landon\Google Drive\research\Graph6\noncrossing\non_crossing" + R + ".txt";
                    var possibleAssociations = NonCrossing.Load(partitionFile);
                    var contractionsPile     = possibleAssociations.Select(ll => ll.Where(l => l.Count >= 2).Select(l => l.ToUInt64()).ToList()).Where(ll => ll.Count > 1).ToList();

                    var lookupCount = assignmentLookup.Count;
                    foreach (var g in path.EnumerateWeightedGraphs())
                    {
                        var ring               = g.Vertices.Where(v => g.VertexWeight[v] == 99).ToList();
                        var inside             = g.Vertices.Except(ring).ToList();
                        var cyclicRingOrdering = GetCyclicOrdering(g, ring);

                        var allGood = false;
                        foreach (var contraction in contractionsPile)
                        {
                            var key = new Key(R, contraction);
                            List <List <long> > assignments;
                            if (!assignmentLookup.TryGetValue(key, out assignments))
                            {
                                assignments           = RingAssignmentGenerator.GenerateAssignments(R, C, Fold, contraction);
                                assignmentLookup[key] = assignments;
                                //if (assignmentLookup.Count - lookupCount > 50)
                                //    SaveLookup(assignmentLookup);
                            }

                            var good = true;
                            foreach (var stacks in assignments)
                            {
                                var insideAssignment = Enumerable.Repeat <long>(0, g.N).ToList();
                                foreach (var v in inside)
                                {
                                    var neighborColors = g.Neighbors[v].Intersect(ring).Aggregate(0L, (tot, z) => tot | stacks[cyclicRingOrdering.IndexOf(z)]);
                                    insideAssignment[v] = allColors & ~neighborColors;
                                }

                                if (!g.IsFoldChoosable(insideAssignment, inside, Fold))
                                {
                                    good = false;
                                    break;
                                }
                            }

                            if (good)
                            {
                                allGood = true;
                                break;
                            }
                        }

                        if (allGood)
                        {
                            var gh = g.Clone();
                            gh.VertexWeight = g.VertexWeight.Select(ww => ww == 99 ? 0 : ww).ToList();
                            gh.AppendWeightStringToFile(WinnersFile);

                            w++;
                            System.Console.ForegroundColor = ConsoleColor.Green;
                            System.Console.WriteLine(string.Format("found {0} reducible graph{1} so far", w, w > 1 ? "s" : ""));
                            System.Console.ForegroundColor = ConsoleColor.White;
                        }
                    }

                    if (lookupCount < assignmentLookup.Count)
                    {
                        SaveLookup(assignmentLookup);
                    }
                }
            }
        }
        public static void Go()
        {
            var RNG = new Random(DateTime.Now.Millisecond);

            File.Delete(WinnersFile);

            var allColors = Enumerable.Range(0, C).To_long();
            var w         = 0;

            var assignmentLookup = FindFractionalColorable.LoadLookup();

            System.Console.Write("Loading graphs...");
            var graphs = Enumerable.Range(MinVertices, MaxVertices - MinVertices + 1).CartesianProduct(Enumerable.Range(MinRingSize, MaxRingSize - MinRingSize + 1)).SelectMany(tup =>
            {
                var N = tup.Item1;
                var R = tup.Item2;

                var path = string.Format(@"C:\Users\landon\Google Drive\research\Graph6\triangulation\disk\triangulation{0}_{1}.g6.tri.weighted.txt", N, R);
                if (!File.Exists(path))
                {
                    return new Graph[] { }
                }
                ;

                return(path.EnumerateWeightedGraphs().Where(gg => InsideLowerLimit <= gg.Vertices.Count(v => gg.VertexWeight[v] != 99) && gg.Vertices.Count(v => gg.VertexWeight[v] != 99) <= InsideUpperLimit));
            }).Reverse().ToList();

            System.Console.WriteLine(" found " + graphs.Count);

            System.Console.Write("Loading contractions...");
            var totalContractions  = 0;
            var contractionsLookup = new Dictionary <int, List <List <ulong> > >();

            for (var R = MinRingSize; R <= MaxRingSize; R++)
            {
                var minHave       = GetMinContractionSize(R);
                var partitionFile = @"C:\Users\landon\Google Drive\research\Graph6\noncrossing\non_crossing" + R + ".txt";
                if (File.Exists(partitionFile))
                {
                    var vv = NonCrossing.Load(partitionFile).ToList();
                    var possibleAssociations = NonCrossing.Load(partitionFile).Where(ll => ll.Any(l => l.Count >= minHave)).ToList();
                    totalContractions    += possibleAssociations.Count();
                    contractionsLookup[R] = possibleAssociations.Select(ll => ll.Where(l => l.Count >= 2).Select(l => l.ToUInt64()).ToList()).Where(ll => ll.Count >= 1).ToList();
                }
            }

            System.Console.WriteLine(" found " + totalContractions);

            while (graphs.Count > 0)
            {
                System.Console.Write("selecting contractions... ");
                var count = graphs.Count;

                var lookupCount = assignmentLookup.Count;
                var randomContractionAssignments = new Dictionary <int, List <List <long> > >();
                for (var R = MinRingSize; R <= MaxRingSize; R++)
                {
                    List <List <ulong> > contractions;
                    if (contractionsLookup.TryGetValue(R, out contractions))
                    {
                        if (contractions.Count <= 0)
                        {
                            continue;
                        }

                        var q = RNG.Next(contractions.Count);

                        var contraction = contractions[q];
                        contractions.RemoveAt(q);

                        var key = new FindFractionalColorable.Key(R, contraction);
                        List <List <long> > assignments;
                        if (!assignmentLookup.TryGetValue(key, out assignments))
                        {
                            assignments = RingAssignmentGenerator.GenerateAssignments(R, C, Fold, contraction);
                            if (!FindFractionalColorable.SkipLookup)
                            {
                                assignmentLookup[key] = assignments;
                            }
                        }

                        randomContractionAssignments[R] = assignments;
                    }

                    System.Console.Write(R + ",");
                }

                if (randomContractionAssignments.Count <= 0)
                {
                    break;
                }

                if (assignmentLookup.Count > lookupCount)
                {
                    FindFractionalColorable.SaveLookup(assignmentLookup);
                }

                System.Console.WriteLine();
                System.Console.Write("checking reducibility...");
                for (int i = graphs.Count - 1; i >= 0; i--)
                {
                    var g = graphs[i];

                    var ring = g.Vertices.Where(v => g.VertexWeight[v] == 99).ToList();
                    if (!randomContractionAssignments.ContainsKey(ring.Count))
                    {
                        continue;
                    }

                    var inside             = g.Vertices.Except(ring).ToList();
                    var cyclicRingOrdering = FindFractionalColorable.GetCyclicOrdering(g, ring);

                    var assignments = randomContractionAssignments[ring.Count];

                    var good = true;
                    foreach (var stacks in assignments)
                    {
                        var insideAssignment = Enumerable.Repeat <long>(0, g.N).ToList();
                        foreach (var v in inside)
                        {
                            var neighborColors = g.Neighbors[v].Intersect(ring).Aggregate(0L, (tot, z) => tot | stacks[cyclicRingOrdering.IndexOf(z)]);
                            insideAssignment[v] = allColors & ~neighborColors;
                        }

                        if (!g.IsFoldChoosable(insideAssignment, inside, Fold))
                        {
                            good = false;
                            break;
                        }
                    }

                    if (good)
                    {
                        var gh = g.Clone();
                        gh.VertexWeight = g.VertexWeight.Select(ww => ww == 99 ? 0 : ww).ToList();
                        gh.AppendWeightStringToFile(WinnersFile);

                        w++;
                        graphs.RemoveAt(i);
                    }
                }

                var reduced = count - graphs.Count;
                System.Console.WriteLine(" found " + reduced);
            }
        }