微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

networkx.enumulate_all_cliques 忽略不包括的组合

如何解决networkx.enumulate_all_cliques 忽略不包括的组合

我在 spyder 中完成了以下代码

df = nx.from_pandas_adjacency(pd.read_excel(r"path/to/file.xlsx",sheet_name="Sheet4",index_col=0,usecols = "A:BR"))
df1=pd.DataFrame(list(nx.enumerate_all_cliques(nx.Graph(df))))

我有 69 个对象,其中 nx.enumerate_all_cliques 从 excel 文件中找到所有 47000 种可能的兼容组合。我在这个列表中有某些必须在一起的对象,我想忽略所有不包含在该可能组合中的all这些对象的所有组合。我可以列出必须放在一起的项目组,因为只有几个。

解决方法

您可以使用集合来确定您需要的所有节点是否都在给定的集团内。这是一个基于随机图的示例。

# Create a random graph.
graph = nx.erdos_renyi_graph(100,.2,seed=0)
# Define the nodes that must be within the clique.
required = {23,33}
# Iterate over all cliques and only keep the clique if it is a 
# subset of the required nodes.
cliques = [clique for clique in nx.enumerate_all_cliques(graph)
           if required.issubset(clique)]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。