예제 #1
0
        public void SimpleRectangle(bool directed)
        {
            string graphString = @"
strict graph { 
A -- B -- C -- D
E -- F -- G -- H
I -- J -- K -- L

A -- E -- I
B -- F -- J
C -- G -- K
D -- H -- L
}";

            if (directed)
            {
                graphString = graphString
                              .Replace("--", "->")
                              .Replace("graph", "digraph");
            }

            var reader = new StringReader(graphString);
            var g      = new DotReader(reader).Read();

            var generator = new GridGenerator(directed, 4, 3);
            var h         = generator.GenerateGraph();

            var isomorphism = new ColorIsomorphismFinder();

            Assert.True(isomorphism.AreIsomorphic(g, h));
        }
예제 #2
0
        public void SimpleSquare(bool directed)
        {
            var graphString = @"
strict graph { 
A -- B -- C -- D
E -- F -- G -- H
I -- J -- K -- L
M -- N -- O -- P

A -- E -- I -- M
B -- F -- J -- N
C -- G -- K -- O
D -- H -- L -- P
}";

            if (directed)
            {
                graphString = graphString
                              .Replace("--", "->")
                              .Replace("graph", "digraph");;
            }

            var reader = new StringReader(graphString);
            var g      = new DotReader(reader).Read();

            var generator = new GridGenerator(directed, 4, 4);
            var h         = generator.GenerateGraph();

            var isomorphism = new ColorIsomorphismFinder();

            Assert.True(isomorphism.AreIsomorphic(g, h));
        }
예제 #3
0
        public void CoarsestNotABijection()
        {
            var reader = new DotReader(new StringReader(@"
            strict graph {
                1 -- 2 -- 3 -- 4 -- 5 -- 6 -- 7
                3 -- 5
            }
            strict graph {
                1 -- 2 -- 3 -- 4 -- 5 -- 6 -- 7
                3 -- 5
            }"));
            var g      = reader.Read();
            var h      = reader.Read();

            var isomorphismFinder = new ColorIsomorphismFinder();

            var isomorphisms = isomorphismFinder.FindIsomorphisms(g, h).ToArray();

            Assert.Equal(2, isomorphisms.Length);

            var correctIsomorphisms = new[]
            {
                new Dictionary <Node, Node>
                {
                    [g.Nodes["1"]] = h.Nodes["1"],
                    [g.Nodes["2"]] = h.Nodes["2"],
                    [g.Nodes["3"]] = h.Nodes["3"],
                    [g.Nodes["4"]] = h.Nodes["4"],
                    [g.Nodes["5"]] = h.Nodes["5"],
                    [g.Nodes["6"]] = h.Nodes["6"],
                    [g.Nodes["7"]] = h.Nodes["7"],
                },
                new Dictionary <Node, Node>
                {
                    [g.Nodes["1"]] = h.Nodes["7"],
                    [g.Nodes["2"]] = h.Nodes["6"],
                    [g.Nodes["3"]] = h.Nodes["5"],
                    [g.Nodes["4"]] = h.Nodes["4"],
                    [g.Nodes["5"]] = h.Nodes["3"],
                    [g.Nodes["6"]] = h.Nodes["2"],
                    [g.Nodes["7"]] = h.Nodes["1"],
                },
            };

            Assert.All(isomorphisms, x => Assert.Contains(x, correctIsomorphisms));
        }