You can download this code by clicking the button below.
This code is now available for download.
This function is used to find all cliques of a specified size in a given graph. A clique is a set of vertices that are all mutually adjacent.
Technology Stack : graph-tool, graph_tool.topology.find
Code Type : Function
Code Difficulty : Intermediate
def find_cliques(graph, size):
"""
Find all cliques of a given size in a graph.
:param graph: graph_tool.Graph, the graph to find cliques in
:param size: int, the size of the cliques to find
:return: list of graph_tool.Graph, the found cliques
"""
from graph_tool.topology import find.cliques
from graph_tool import Graph
# Get all cliques of the specified size
all_cliques = find.cliques(graph, size)
# Convert the found cliques to graph_tool.Graph objects
cliques_graphs = [Graph(g) for g in all_cliques]
return cliques_graphs