如何將二分圖轉換為無二分圖 (How to convert a bipartite graph into no bipartite)


問題描述

如何將二分圖轉換為無二分圖 (How to convert a bipartite graph into no bipartite)

我已經嘗試了很長時間沒有成功,所以我最好問問你。

首先,我正在研究 python 3networkx

我有一個二部圖作為圖像A,根據他們的'group'屬性(group=' R'和組='X')。此外,有些關係是可逆的,如 R4,而有些則不是(所以我想在這些情況下我們必須展開節點)。

我需要的是只留下R組的節點並消除X的節點,但保持它們之間的關係。也就是說,


參考解法

方法 1:

Go over nodes of the graph, if the node is green add an edge between all its neighbours (which will only be blue). At the end remove all the green nodes.

to_remove = []
for node in G.nodes(data = True):
    if node[1]["type"] == "Green": ## check if the node is green
        to_remove.append(node[0])
        ## go over all neighbours of the node and add an edge between them
        neighbours =  list(G.neighbors(node[0]))
        for i in range(0, len(neighbours)‑1):
            for j in range(i+1, len(neighbours)):
                G.add_edge(neighbours[i],neighbours[j])

## remove the green nodes
G.remove_nodes_from(to_remove)

(by Valtrizglhrsh)

參考文件

  1. How to convert a bipartite graph into no bipartite (CC BY‑SA 2.5/3.0/4.0)

#bipartite #graph #python-3.x #networkx






相關問題

如何找到圖的非完美二分匹配? (How can I find a non-perfect bipartite matching of a graph?)

如何使用 BFS 在無向二部圖中找到最短循環? (How can I find the shortest cycle in an undirected bipartite graph using BFS ?)

如何在有向圖中測試二分 (how to test for bipartite in directed graph)

檢查圖形是否是二分的 (check if the graph is bipartite or not)

二分圖中邊緣不同路徑的數量 (Number of edge distinct paths in bipartite graph)

對於來自兩個不同集合的項目的一對一分配,UI/UX 模式及其優缺點是什麼? (What are UI/UX patterns and their pros/cons for 1-to-1 assignments of items from two different sets?)

將多個函數應用於矩陣列表以返回數據框 (Apply multiple functions to list of matrices to return data frame)

如何將二分圖轉換為無二分圖 (How to convert a bipartite graph into no bipartite)

如何根據來自雙模網絡的匹配創建單模網絡(鄰接矩陣) (How to create a one-mode network (adjacency matrix) based on matches from two-mode network)

igraph 到達模型中屬性類型為“FALSE”的節點 (igraph reaching a node whose type of attribute in the model is "FALSE")

二分網絡igraph中的頂點屬性 (Vertex attributes in bipartite network igraph)

使用循環從 r 中的前一個列表創建一個新列表 (using loop to create a new list from previous list in r)







留言討論