Improvement of the graph generation algorithm