예제 #1
0
def find_eliminating_set(G):
    '''
    a function to find a stable set that eliminates all triangles
    Parameters:
        G: the graph g to check (networkx)
    Returns:
        eliminating_set: the set of vertices (list)
    '''
    cycles = cycle_basis(G)
    for v in G.nodes():
        cycles += cycle_basis(G, root=v)
    triangles = []
    for cycle in cycles:
        if len(cycle) == 3 and qsort(cycle) not in triangles:
            triangles.append(qsort(cycle))
    elimintating_set = find_eliminating_set_aux(G, triangles, [])
    return elimintating_set
예제 #2
0
def triangle_free(G):
    '''
    a function that checks if a graph G is triangle free
    Parameters:
        G: the graph to check (networkx)
    Returns:
        condition: True triangle free, False otherwise (boolean)
    '''
    cycles = cycle_basis(G, root=0)

    condition = True
    i = 0
    while condition and i < len(cycles):
        if len(cycles[i]) ==3:
            condition = False
        i += 1 
    return condition