This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Trivially perfect graphs are the graphs that do not have a P4 path graph or a C4 cycle graph as induced subgraphs. | |
# Reference: Brandstädt, Le & Spinrad (1999), theorem 6.6.1, p. 99; Golumbic (1978), theorem 2. Wolk (1962) and Wolk (1965) proved this for comparability graphs of rooted forests. | |
# Error: By mistake used DiGraphs here instead of undirected. | |
# returns true if C4 is present | |
def checkC4(graph): | |
for vertex in graph: | |
if(graph.degree(vertex) != 2): | |
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function to find all minimal separators of a graph | |
def find_minimal_separators(G): | |
separators = [] | |
visited_separators = {} | |
# Initial iteration | |
for v in G.vertices(): | |
N_v = set(G.neighbors(v)) | |
S = N_v.union({v}) | |
G_S = G.copy() |