Getting the clique number of a graph

A complete graph is a graph in which every pair of nodes is connected by a unique connection. A clique is a subgraph that is complete. This is equivalent to the general concept of cliques in which every person knows all the other people. The maximum clique is the clique with the most nodes. The clique number is the number of nodes in the maximum clique. Unfortunately finding the clique number takes a long time, so we will not use the complete Facebook SPAN data.

Getting ready

Install NetworkX with the instructions from the Introduction section.

How to do it...

The code is in the clique_number.py file in this book's code bundle:

  1. The imports are as follows:
    import networkx as nx
    import dautil as dl
  2. Load the Facebook SPAN data into a NetworkX graph:
    fb_file = dl.data.SPANFB().load()
    G = nx.read_edgelist(fb_file,
                         create_using=nx.Graph(),
                         nodetype=int)
  3. Determine the clique number for a subgraph:
    print('Graph Clique Number',
          nx.graph_clique_number(G.subgraph(list(range(2048)))))

We get the following result for the partial Facebook SPAN data:

Graph Clique Number 38

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset