0

I have the following code all done in 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))))

I have 69 objects where nx.enumerate_all_cliques finds all 47000 possible compatible combinations from the excel file. I have certain objects in this list that must be together and I want to ignore all combinations that do not contain all those objects somewhere in that possible combination. I am fine with listing out the groups of items that must be together as there are only a few.

Frodnar
  • 2,129
  • 2
  • 6
  • 20
mewspoon
  • 37
  • 8
  • Since [`enumerate_all_cliques`](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.clique.enumerate_all_cliques.html) has no other parameters aside from the graph, you're left with either editing the generated `nx.Graph(df)` object or changing the data. Can you provide sample data or even the whole dataset? Can you provide more detail about the objects that "must be together?" At the moment, there isn't enough detail in this question to answer it. – Frodnar Apr 05 '21 at 13:37

1 Answers1

0

You can use sets to determine whether all your required nodes are within a given clique. Here is an example based on a random graph.

# 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)]
Till Hoffmann
  • 9,479
  • 6
  • 46
  • 64