greedy_coloring代码不起作用。请告诉我为什么

时间:2019-04-24 20:23:44

标签: python

我的项目只有一个文件,我无法弄清为什么它没有运行。是greedy_coloring.py

代码:

import networkx as nx

from functions.global_properties import *
from functions.local_properties import *

G = nx.read_edgelist('test_graphs/G1.txt')

def greedy_proper_coloring(G):
    colored_verticies = {v: None for v in V(G)}
    colored_verticies[V(G)[0]] = 1
    for v in V(G):
        if colored_verticies[v] == None:
            N = neigbors(G, v)
            avoid_colors = [colored_verticies[w] for w in N]
            i = 1
            while colored_verticies[v] == None:
                if i not in avoid_colors:
                    colored_verticies[v] = i
                else:
                    i += 1
    return colored_verticies

print(greedy_proper_coloring(G))

这是link to my project

1 个答案:

答案 0 :(得分:0)

第一期:您将功能作为软件包导入,因此,请在文件夹功能内创建一个空的__init__.py文件。

第二个问题:将test_graphs文件夹重命名为graph_library