Пример #1
0
        public void GetPlanarFaces_OneCycleGraphs()
        {
            var       boyerMyrvold = new BoyerMyrvold <int>();
            const int minVertices  = 3;
            const int maxVertices  = 1000;

            for (int i = minVertices; i <= maxVertices; i++)
            {
                var graph = GetOneCycle(i);

                Assert.That(boyerMyrvold.TryGetPlanarFaces(graph, out var planarFaces), Is.EqualTo(true));
                Assert.That(planarFaces.Faces.Count, Is.EqualTo(2));
                Assert.That(planarFaces.Faces[0].Count, Is.EqualTo(i));
                Assert.That(planarFaces.Faces[1].Count, Is.EqualTo(i));
            }
        }
Пример #2
0
        /// <summary>
        /// Gets faces of a given graph.
        /// </summary>
        /// <remarks>
        /// Only distinct elements from each face are returned.
        /// </remarks>
        /// <param name="graph"></param>
        /// <returns></returns>
        public List <List <T> > GetPlanarFaces <T>(IGraph <T> graph)
        {
            if (graph.IsDirected)
            {
                throw new ArgumentException("The graph must not be directed", nameof(graph));
            }

            var boyerMyrvold = new BoyerMyrvold <T>();
            var isPlanar     = boyerMyrvold.TryGetPlanarFaces(TransformGraph(graph), out var faces);

            if (!isPlanar)
            {
                throw new InvalidOperationException("Graph is not planar");
            }

            var facesDistinct = new List <List <T> >();

            foreach (var faceRaw in faces.Faces)
            {
                facesDistinct.Add(faceRaw.Distinct().ToList());
            }

            return(facesDistinct);
        }