Skip to content

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

@chenzhigang9521

Description

@chenzhigang9521

报错,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)}")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions