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); }
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); }
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); }