I am using python + igraph 0.6 for the first time and have some basic questions.
First, I would like to make a random graph and then insert a clique into it somewhere.
from igraph import *
g = Graph.Erdos_Renyi(50,0.1)
h = Graph.Full(5)
How do I make a new graph g2 with h connected by two edges to the graph g?
Second, having done this I would like to find maximal cliques and show in a picture where they are. Call the combined graph g2.
mcliques = g2.maximal_cliques(4, 7)
How can I now plot the cliques we have just found either separately or in the graph g2?
Answer to your first question:
or even simpler:
Here we make use of the fact that the
+operator between two graphs creates a disjoint union of the two graphs, and sinceigraphalways uses a consecutive vertex ID range, we can simply know that vertices 0-49 ofg2will spangand vertices 50-54 will spanh.Regarding your second question, you did not specify what exactly you mean by plotting the cliques, but a possible solution is as follows:
See the documentation of
Graph.__plot__for more information about themark_groupsparameter; basically it is either a dictionary mapping colors to groups of vertices (vertex ids), or a list yielding pairs of vertex ids and colors. The vertex groups are then enclosed by a shaded area with the given color as background.