public bool GraphCycleDetect(IGraph <V, E> graph)
        {
            var search        = new BreadthFirstSearch <V, E>();
            var vertexVisitor = new DummyVertexVisitor <V>();
            var edgeVisitor   = new GraphCycleEdgeVisitor <V, E>(search);

            search.Search(graph, vertexVisitor, edgeVisitor);

            return(edgeVisitor.HasCycle);
        }
示例#2
0
        public bool TwoColor(IGraph <V, E> graph)
        {
            var search        = new BreadthFirstSearch <V, E>();
            var vertexVisitor = new DummyVertexVisitor <V>();
            var edgeVisitor   = new BipartiteEdgeVisitor <V, E>(graph);

            foreach (var vertex in graph.Vertices)
            {
                if (!search.IsVisited(vertex))
                {
                    edgeVisitor.SetColor(vertex, BipartiteEdgeVisitor <V, E> .Color.White);
                    search.Search(graph, vertex, vertexVisitor, edgeVisitor);
                }
            }

            return(edgeVisitor.IsBipartite);
        }
示例#3
0
        public int FindPartitions(IGraph <V, E> graph)
        {
            int partitions    = 0;
            var search        = new BreadthFirstSearch <V, E>();
            var vertexVisitor = new DummyVertexVisitor <V>();
            var edgeVisitor   = new DummyEdgeVisitor <V, E>();

            foreach (var vertex in graph.Vertices)
            {
                if (!search.IsVisited(vertex))
                {
                    partitions++;
                    search.Search(graph, vertex, vertexVisitor, edgeVisitor);
                }
            }

            return(partitions);
        }