Generalized Generate_Graph() function