def greedy_color(G):
    results = {}

    #init with none color
    for v in V(G):
        results[v] = None

    for v in V(G):

        neighbor_colors = []
        for n in neighbors(G, v):
            if results[n] != None:
                neighbor_colors.append(results[n])

        color = 0
        flag = False
        while not flag:
            if color not in neighbor_colors:
                flag = True
            else:
                color += 1

        results[v] = color

    return results
Esempio n. 2
0
def distance_array(G, v):
    """ Returns the distance array
    Parameters
    ---------
    G:          Unweight Graph
    v:          vertex in G
   
    Returns
    -------
    N
       Returns the distance array 
    """
    N = [[v]]
    Obs = [v]
    i = 1
    while set(Obs) != set(V(G)):
        print(f'Iteration {i} = {N}')
        temp_neighbors = []
        for x in N[-1]:
            for y in neighbors(G, x):
                if y not in Obs:
                    temp_neighbors.append(y)
                    Obs.append(y)
        N.append(temp_neighbors)
        return N
Esempio n. 3
0
def is_independent(G, S):
    for s in S:
        A = list(neighbors(G, s))
        for a in A:
            if a in S:
                return False
    return True
def is_dominating(G, S):
    S_complement = list(set(V(G)) - set(S))
    for v in S_complement:
        N = neighbors(G, v)
        if list(set(N) & set(S)) == []:
            return False
    return True
Esempio n. 5
0
def is_clique(G,s):
    for v in s:
        L = list(s)
        L.remove(v)
        for w in L:
            if w not in list(neighbors(G,v)):
                return False
    return True
Esempio n. 6
0
def is_independent_spes(G, S, v):
    for s in S:
        A = list(neighbors(G, s))
        for a in A:
            if a in S:
                return False
            if v not in S:
                return False

    return True
Esempio n. 7
0
def get_min_edge(G, T):
    min_cost = 100000000
    min_edge = None
    for v in V(T):
        candidates = neighbors(G, v)
        for c in candidates:
            if G[v][c]['weight'] < min_cost and c not in V(T):
                min_cost = G[v][c]['weight']
                min_edge = (v, c)

    return min_edge
def distance_array(G,v):
    N=[[v]]
    Obs = [v]
    while set(Obs) != set(V(G)):
        temp_neighbors = []
        for x in N[-1]:
            for y in neighbors(G,x):
                if y not in Obs:
                    temp_neighbors.append(y)
                    Obs.append(y)    
        N.append(temp_neighbors)
    return N
def distance_list(G, v):
    D = [[v]]
    observed = [v]
    while set(observed) != set(v(G)):
        temp_collection = []
        for w in D[-1]:
            N = neighbors(G, w)
            for x in N:
                if x not in observed:
                    observed.append(x)
                    temp_collection.append
            D.append(temp_collection)
        return D
def greedy_coloring(G):
    colors = {v: None for v in V(G)}
    colors[V(G)[0]] = 1
    for v in V(G):
        if colors[v] == None:
            N = neighbors(G, v)
            bad_colors = [colors[w] for w in N]
            j = 1
            while colors[v] == None:
                if j not in bad_colors:
                    colors[v] = 1
                else:
                    j += 1
    return colors
Esempio n. 11
0
def degree(G, v):
    """
    Returns the length of neighbors of a given point
    
    Parameters
    ----------
    G :     Networkx graph
            Undirected graph
    v :     Vertex
           
    Returns
    -------
     :   integer
     Returns length of neighbors of a vertex
    """
    return len(neighbors(G, v))
Esempio n. 12
0
def is_independent(G,S):
    """Returns true if 

    Parameters
    ----------
    G : int
    The graph containing the vertices and edges of graph G
    S : set
 
    Returns
    -------
    Bool
        Returns true if the 
    """     
    for v in S:
        if list(set(S) & set(neighbors(G, v))) != []:
            return False
        return True
Esempio n. 13
0
def is_matching(G,s):
    
    for i in s:
        if len(s[i]) != 2:
            return print("Not every part of the set is an edge.")
        else:
            if s[i][0] not in list(neighbors(G,s[i][1])):
                return print("One or more of your pairs of vertices are not edges.")
    
    L = []
    for sublist in s:
        for item in sublist: 
            L.append(item)
    M = list(set(L))
    M.sort()
    L.sort()
    if L == M:
        return True
    else:
        return False
Esempio n. 14
0
def is_clique(G,S): #set of vertices where every pair in the set forms an edge
    """Returns True if every two distinct vertices are adjacent

    Parameters
    ----------

    G:
        A Graph containg vertices and edges contained in Graph G
    
    S: 
        A constant 
    
    Returns 
    -------

    Bool
        Returns True if every two distinct vertices are adjacent 
     
    """    
    for v in S:
        if list(set(S)&set(neighbors(G,v))) != []:  #[] <-- empty list
            return False
    
    return True
Esempio n. 15
0
def is_independent(G, S):
    for v in S:
        if list(set(S) & set(neighbors(G, v))) != []:
            return False
    return True
def degree(G, v):
    return len(neighbors(G,v))
def is_clique(G, S):
    for i in range(len(S)):
        N = neighbors(G, S[i])
        for j in range(i + 1, len(S)):
            if S[1 + j] not in N:
                return False
Esempio n. 18
0
def is_clique(G, S):
    for v in S:
        if list(set(S) & set(neighbors(G, v))) != []:
            return True
    return False