1 answer

I am pretty sure there is no random generation of graphs forbidding some structure in Sage. So, what is possible is to use a rejection algorithm : pick random graphs of a given size with equal probability until you found one that forbids the given structure. For example, you can do:

Of course this method can take a long time for big size if the set of admissible graphs is small compared to the set of all graphs.

Note that G.subgraph_search(C) searches for a copy of C in G. If you want to avoid only C as an induced subgraph of G, you should replace G.subgraph_search(C) by G.subgraph_search(C, induced=True). Of course it does not matter for the special case where C is $C_3$.

Comments

@tmonteil Thank you so much for your suggestions. It is really helpful. The function you mentioned above G.subgraph_search() together with function minor() found by following @dazedANDconfused 's instruction are exactly what I need in my research. Thank you guys for your patient explanations.