Beispiel #1
0
        public static void WriteProof()
        {
            //  var uiG = GraphsCore.CompactSerializer.Deserialize("webgraph:7qM`$!.4bH!!!R&a9[/.`!KrS!Aa_K%n$+I!*C1-pbPd:TFX<n1&s-S7JJ\\_\"eHt>8?!.J7JQ4#6hiD:#64`)!<=YO!!!'6/-5ne/-I40\"U#Ji#\"0\"-!!!\"L\"p\"]T!<<"); //small tree aka fig1 left
            //     var uiG = GraphsCore.CompactSerializer.Deserialize("webgraph:7oB<e!-S>B!!#8TJd$*0\\-lgI!AXY2';,k%#;Z?^)[2gP(C-Of'0ujY!!N?&!.ZPL!<E0O!=+(&I\"$HlIKBKg/-?eA!uhdS2\\:FcIXV"); // fig1 middle

            //   var uiG = GraphsCore.CompactSerializer.Deserialize("webgraph:7qDZ#!2KSp!!#7s_?WaT\\-lgI!Aa^d)5%L-#>?-AShqSoSn&^p'0ujY!)+Du>Qb&\"e2/>6>R(6/!<E0O!=+(&I\"$HlIK0Hg/-6b%!s0Al\"<.mU.hDa^!.Y84&:T\"UIK"); // fig1 right

            //  var uiG = GraphsCore.CompactSerializer.Deserialize("webgraph:8!X,T!$D:B!!&)lOptM4\\-lgI!Aa^@+,/T#,DG#?+.s-1#;Q9])[2f],6a[K$V?KmJ;)mR%u&ns'8>>R$O*,X'*Xu#%gAPD(XNCQ#;Z>g!!*'#!6>-?Uf-F^IXZZnI\"$MF!ZK,^!?0#^$P3Il&-`@Xa9[/)$6$tl\"rbPjHP\"$p#ljsUL^OUs(<CrPIXV"); // big tree

            var uiG = GraphsCore.CompactSerializer.Deserialize("webgraph:7RI.U!'1)[!!@T`X:8\\?!AXXc)8lhl!!+kU9HC2DA,lWc!!3-$!!*'N!=+(&I\"$HlIK9KN!%\\-UIXZZnI\"$M"); // val

            var potSize  = uiG.Vertices.Max(v => int.Parse(v.Label));
            var g        = new Choosability.Graph(uiG.GetEdgeWeights());
            var template = new Template(g.Vertices.Select(v => potSize + g.Degree(v) - uiG.Vertices[v].Label.TryParseInt().Value).ToList());

            var mind = new Choosability.FixerBreaker.KnowledgeEngine.Slim.Super.SuperSlimMind(g, proofFindingMode: true);

            mind.MaxPot = potSize;
            //   mind.MissingEdgeIndex = 0;
            //   mind.OnlyConsiderNearlyColorableBoards = true;

            int j   = 0;
            var win = mind.Analyze(template);

            if (win)
            {
                var pb    = new MaximumDegreeThreeProofBuilder(mind);
                var proof = pb.WriteProof();
            }
        }
Beispiel #2
0
        void TestGraph <T>(string name, int totalPositions, bool shouldWin, bool shouldWinNearlyColorable)
            where T : IMind
        {
            var graphFile = Path.Combine(RootPath, name);

            Assert.IsTrue(File.Exists(graphFile), graphFile + " does not exist.");

            var graph = GraphUtility.LoadGraph(graphFile);
            var G     = new Choosability.Graph(graph.GetEdgeWeights());

            var potSize  = graph.Vertices.Max(v => v.Label.TryParseInt().Value);
            var template = new Template(G.Vertices.Select(v => potSize + G.Degree(v) - graph.Vertices[v].Label.TryParseInt().Value).ToList());

            var mind = (SuperSlimMind)Activator.CreateInstance(typeof(T), G);

            mind.MaxPot = potSize;

            var win = mind.Analyze(template, null);

            Assert.AreEqual(totalPositions, mind.TotalBoards, "total positions fail");
            Assert.AreEqual(shouldWin, win, "outright win fail");

            if (!win)
            {
                mind        = (SuperSlimMind)Activator.CreateInstance(typeof(T), G);
                mind.MaxPot = potSize;
                mind.OnlyConsiderNearlyColorableBoards = true;

                win = mind.Analyze(template, null);
                Assert.AreEqual(shouldWinNearlyColorable, win, "nearly colorable fail");
            }
        }
Beispiel #3
0
        static IEnumerable <Choosability.Graph> EnumerateWeightings(Choosability.Graph g)
        {
            var space = Not ? g.Vertices.Select(v => Enumerable.Range(0, Spread)).CartesianProduct() : g.Vertices.Select(v => Enumerable.Range(0, Spread).Reverse()).CartesianProduct();

            foreach (var weighting in space)
            {
                var www = weighting.ToList();
                if (www.Count(w => w > 0) > MaxHighs)
                {
                    continue;
                }

                if (g.Vertices.Any(v => g.Degree(v) - www[v] <= 1))
                {
                    continue;
                }

                if (LowMinDegree > 0)
                {
                    var low = www.IndicesWhere(w => w == 0).ToList();
                    if (g.InducedSubgraph(low).MinDegree < LowMinDegree)
                    {
                        continue;
                    }
                }

                var gg = g.Clone();
                gg.VertexWeight = www;

                yield return(gg);
            }
        }
Beispiel #4
0
        public static List <Graphs.Vector> GetLaplacianLayout(this Choosability.Graph g, List <Graphs.Vector> layout = null, object data = null)
        {
            var D = Matrix.Build.Diagonal(g.N, g.N, v => g.Degree(v));
            var A = Matrix.Build.Dense(g.N, g.N, (v, w) => g[v, w] ? 1 : 0);
            var L = D - A;

            var evd = L.Evd(MathNet.Numerics.LinearAlgebra.Symmetricity.Symmetric);
            var x   = evd.EigenVectors.Column(1);
            var y   = evd.EigenVectors.Column(2);

            return(GetEigenVectorLayout(x, y));
        }
        static IEnumerable <Choosability.Graph> EnumerateWeightings(Choosability.Graph g)
        {
            if (g.MaxDegree > 4)
            {
                yield break;
            }

            foreach (var weighting in g.Vertices.Select(v => Enumerable.Range(g.Degree(v), 2)).CartesianProduct())
            {
                var www = weighting.ToList();

                var gg = g.Clone();
                gg.VertexWeight = www;
                yield return(gg);
            }
        }
Beispiel #6
0
        public static void BuildTreePictures()
        {
            var root = @"C:\game trees\smalltree\fixable";

            Directory.CreateDirectory(root);

            //   var uiG = GraphsCore.CompactSerializer.Deserialize("webgraph:7p5lm!.4bH!!#8TV?g9C\\-lgI!AXXW)k[^-#;Z?F*sJ5a,6aYM-O65sh^B_'h`q79;LfjChZj,^!!*)@!!!'$'Z^@ja9NC\"!sTF[\">gYm\"T\\VE!!!");
            //  var uiG = GraphsCore.CompactSerializer.Deserialize("webgraph:7s+e3!3?/#!!#:+U^KF0PS%F+!AXX?+05o;#;\\Xf`!Jd9-mM7W`P)m27JKt(6hiE-#!f!b-mM`?paS`-&1>N4<IG2S!<<-#a8c2A!>NTW'Z^Ila9)SZa98IB!.Zm;#6Y^]#ZM?A<\"KBC!<C1@!!");
            var uiG      = GraphsCore.CompactSerializer.Deserialize("webgraph:7qM`$!.4bH!!!R&a9[/.`!KrS!Aa_K%n$+I!*C1-pbPd:TFX<n1&s-S7JJ\\_\"eHt>8?!.J7JQ4#6hiD:#64`)!<=YO!!!'6/-5ne/-I40\"U#Ji#\"0\"-!!!\"L\"p\"]T!<<");
            var potSize  = uiG.Vertices.Max(v => int.Parse(v.Label));
            var g        = new Choosability.Graph(uiG.GetEdgeWeights());
            var template = new Template(g.Vertices.Select(v => potSize + g.Degree(v) - uiG.Vertices[v].Label.TryParseInt().Value).ToList());

            GraphViz.DrawGraph(g, root + @"\G.pdf", true);

            var mind = new Choosability.FixerBreaker.KnowledgeEngine.Slim.Super.SuperSlimMind(g, proofFindingMode: true);

            mind.MaxPot = potSize;
            //  mind.OnlyConsiderNearlyColorableBoards = true;
            //  mind.MissingEdgeIndex = 0;

            int j   = 0;
            var win = mind.Analyze(template);

            if (win)
            {
                foreach (var board in mind.PlayableBoards)
                {
                    var tree = mind.BuildGameTree(board, win);
                    GraphViz.DrawTree(tree, root + @"\" + " depth " + tree.GetDepth() + " board " + j + ".png");
                    j++;
                }
            }
            else
            {
                foreach (var board in mind.BreakerWonBoards)
                {
                    var tree = mind.BuildGameTree(board, win);
                    GraphViz.DrawTree(tree, root + @"\" + " depth " + tree.GetDepth() + " board " + j + ".png");
                    j++;
                }
            }
        }
Beispiel #7
0
        public static List <Graphs.Vector> GetWalkMatrixLayout(this Choosability.Graph g, List <Graphs.Vector> layout = null, object data = null)
        {
            var D = Matrix.Build.Diagonal(g.N, g.N, v => g.Degree(v));
            var A = Matrix.Build.Dense(g.N, g.N, (v, w) => g[v, w] ? 1 : 0);
            var L = D.Inverse() * A;

            var evd = L.Evd(MathNet.Numerics.LinearAlgebra.Symmetricity.Symmetric);
            int xi  = 1;
            int yi  = 2;

            for (int i = 0; i < evd.EigenValues.Count - 1; i++)
            {
                if (evd.EigenValues[i].Real <= 1 && evd.EigenValues[i + 1].Real >= 1)
                {
                    xi = i;
                    yi = i + 1;
                    break;
                }
            }
            var x = evd.EigenVectors.Column(xi);
            var y = evd.EigenVectors.Column(yi);

            return(GetEigenVectorLayout(x, y));
        }