コード例 #1
0
        /// <summary>
        /// Tries to get faces of a planar embedding of a given graph.
        /// </summary>
        /// <param name="graph">Graph</param>
        /// <param name="faces">Faces of a planar embedding if planar, null otherwise</param>
        /// <returns>True if planar, false otherwise</returns>
        public bool TryGetPlanarFaces(IGraph <T> graph, out PlanarFaces <T> faces)
        {
            if (!IsPlanar(graph, out var embedding))
            {
                faces = null;
                return(false);
            }

            var planarFaceVisitor = new GetPlanarFacesVisitor <T>();

            PlanarFaceTraversal.Traverse(graph, embedding, planarFaceVisitor);

            faces = new PlanarFaces <T>(planarFaceVisitor.Faces);
            return(true);
        }
コード例 #2
0
        public void CompareWithBoost(string filename)
        {
            var path         = TestContext.CurrentContext.TestDirectory + "\\Resources\\" + filename;
            var boyerMyrvold = new BoyerMyrvold <int>();

            using (var reader = File.OpenText(path))
            {
                while (!reader.EndOfStream)
                {
                    var testData = LoadData(reader);
                    var graph    = ConstructGraph(testData);

                    if (boyerMyrvold.IsPlanar(graph, out var embedding))
                    {
                        Assert.That(testData.IsPlanar, Is.EqualTo(true));

                        foreach (var vertex in graph.Vertices)
                        {
                            var vertexEmbedding = embedding.GetEdgesAroundVertex(vertex);
                            Assert.That(vertexEmbedding, Is.EquivalentTo(testData.Embedding[vertex]));
                        }
                        var planarFaceVisitor = new GetPlanarFacesVisitor <int>();
                        PlanarFaceTraversal.Traverse(graph, embedding, planarFaceVisitor);

                        Assert.That(planarFaceVisitor.Faces.Count, Is.EqualTo(testData.Faces.Count));

                        for (var i = 0; i < planarFaceVisitor.Faces.Count; i++)
                        {
                            var face = planarFaceVisitor.Faces[i];
                            Assert.That(face, Is.EquivalentTo(testData.Faces[i]));
                        }
                    }
                    else
                    {
                        Assert.That(testData.IsPlanar, Is.EqualTo(false));
                    }
                }
            }
        }