igraph / python-igraph

Python interface for igraph
GNU General Public License v2.0
1.31k stars 249 forks source link

我是用25w左右的数据,创建graph,然后使用largest_independent_vertex_sets,获取最大独立集 #802

Closed chenzhigang9521 closed 1 week ago

chenzhigang9521 commented 2 weeks ago

报错,segmentation fault,下面是代码,错误出现max_independent_set = G.largest_independent_vertex_sets()[0],直接报错了

unique_vertices = set()
edges = []
map_data: dict[str, str] = {}
filename = 'graph_data.txt'
 # 使用 igraph 创建无向图
G = ig.Graph()
with open(filename, "rb") as f:
    for line in f:
        # 使用 .strip() 可以去掉每行末尾的换行符和其他空白字符
        content = line.strip()
        json_data = json.loads(content)
        if json_data["uuid_1"] not in map_data:
            map_data[json_data["uuid_1"]] = json_data["origin_uuid_1"]
        if json_data["uuid_2"] not in map_data:
            map_data[json_data["uuid_2"]] = json_data["origin_uuid_2"]
        unique_vertices.add(json_data["uuid_1"])
        unique_vertices.add(json_data["uuid_2"])
        edges.append((json_data["uuid_1"], json_data["uuid_2"]))
        if len(edges) < 1000:
            continue
        G.add_vertices(list(unique_vertices))
        G.add_edges(edges)
        unique_vertices.clear()
        edges.clear()

if len(edges) > 0:
    G.add_vertices(list(unique_vertices))
    G.add_edges(edges)
    unique_vertices.clear()
    edges.clear()

# 获取最大独立集
max_independent_set = G.largest_independent_vertex_sets()[0]
print(f"max_independent_set len: {len(max_independent_set)}")
szhorvat commented 2 weeks ago

Please fill out the bug template in full.

What is missing: (1) a minimal reproducible example, see https://stackoverflow.com/help/minimal-reproducible-example (2) information about your system (OS, igraph version, where you got igraph)

If at all possible, write reports in English (ask for help from a friend, if necessary), since no one on the igraph team reads Chinese.

szhorvat commented 2 weeks ago

We need a complete example that reproduces the issue to be able to do something about this. Can you provide it?