Constraints for generating graphs with imposed and forbidden patterns: an application to molecular graphs


Although graphs are widely used to encode and solve various computational problems, little research exists on constrained graph construction. The current research was carried out to shed light on the problem of generating graphs, where the construction process is guided by various structural restrictions, like vertex degrees, proximity among vertices, and imposed and forbidden patterns. The main contribution of this paper is an encoding of the constrained graph generation problem in terms of a constraint satisfaction problem (CSP). This approach is motivated by the flurry of efficient solution algorithms available within the constraint programming (CP) framework. The obtained encoding has given rise to the CP-MolGen program, a new open source program dedicated to the generation of molecular graphs with imposed and forbidden fragments. Experimental results on several real-world molecular graph generation instances have shown the effectiveness and efficiency of the proposed program, especially the benefits of forbidding cyclic patterns as induced subgraphs.

This is a preview of subscription content, log in to check access.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7


  1. 1.

    1D, 13C, COSY, HMQC/HSQC, HMBC are a set of nuclear magnetic resonance spectroscopy (NMR) experimental methods which give information on correlations among atoms


  1. 1.

    Apt, K. (2007). Constraint Logic Programming Using ECLiPSe. Cambridge: Cambridge University Press.

    Google Scholar 

  2. 2.

    Barvinok, A., & Hartigan, J. (2012). The number of graphs and a random graph with a given degree sequence. Random Structures &, Algorithms, 42(3), 301–348.

    MathSciNet  Article  MATH  Google Scholar 

  3. 3.

    Bayati, M., Montanari, A., Saberi, A. (2009). Generating random graphs with large girth. In: Proceedings of the Twentieth Annual ACM-SIAM Symposium on Discrete Algorithms (pp. 566–575). Society for Industrial and Applied Mathematics.

  4. 4.

    Bistarelli, S., Montanari, U., Rossi, F., Schiex, T., Verfaillie, G., Fargier, H. (1999). Semiring-based CSPs and Valued CSPs: Frameworks, properties, and comparison. Constraints, 4(3), 199–240.

    MathSciNet  Article  MATH  Google Scholar 

  5. 5.

    Brown, K.N., Prosser, P., Beck, J.C., Wu, C.W. (2005). Exploring the use of constraint programming for enforcing connectivity during graph generation. In: 5Th Workshop on Modelling and Solving Problems with Constraints. ACM.

  6. 6.

    Corander, J., Janhunen, T., Rintanen, J., Nyman, H.J., Pensar, J. (2013). Learning chordal markov networks by constraint satisfaction, pp. 1349–1357. arXiv:1310.0927.

  7. 7.

    Dooms, G., Deville, Y., Dupont, P. (2005). Constrained metabolic network analysis: discovering pathways using CP(Graph). In: Workshop on Constraint Based Methods for Bioinformatics (pp. 29–35).

  8. 8.

    Dooms, G., Deville, Y., Dupont, P. (2005). CP(GRaph): Introducing a graph computation domain in constraint programming. In Proceedings of the 11th International Conference on Principles and Practice of Constraint Programming, CP05 (pp. 211–225). Berlin: Springer.

  9. 9.

    Elyashberg, M.E., Blinov, K.A., Williams, A.J., Molodtsov, S.G., Martin, G.E., Martirosian, E.R. (2004). Structure Elucidator: A versatile expert system for molecular structure elucidation from 1D and 2D NMR data and molecular fragments. Journal of Chemical Information and Computer Sciences, 44(3), 771–792.

    Article  Google Scholar 

  10. 10.

    Erdös, P. (1959). Graph theory and probability. Canadian Journal of Mathematics, 11, 34–38.

    MathSciNet  Article  Google Scholar 

  11. 11.

    Fages, J.G. (2014). On the use of graphs within constraint-programming. Constraints, 20, 498–499.

    Article  Google Scholar 

  12. 12.

    Frieze, A., & Karoński, M. (2016). Introduction to random graphs. Cambridge University Press.

  13. 13.

    G Tack, M.L., & Schulte, C. Gecode: generic constraint development environment. Accessed: 2019-05-02.

  14. 14.

    Garey, M.R., & Johnson, D.S. (1990). Computers and Intractability; A Guide to the Theory of NP-completeness. New York: W. H. Freeman & Co.

    Google Scholar 

  15. 15.

    Genio, C.I.D., Kim, H., Toroczkai, Z., Bassler, K.E. (2010). Efficient and exact sampling of simple graphs with given arbitrary degree sequence. PLoS ONE, 5 (4), e10012.

    Article  Google Scholar 

  16. 16.

    Genova, D., & Jonoska, N. (2012). Forbidding and enforcing on graphs. Theoretical Computer Science, 429, 108–117.

    MathSciNet  Article  MATH  Google Scholar 

  17. 17.

    Gent, I., Jefferson, C., Miguel, I. (2006). MINION: A fast, scalable, constraint solver. In: ECAI 2006: 17Th European Conference on Artificial Intelligence, Frontiers in Artificial Intelligence and Applications (pp. 98–102). IOS press.

  18. 18.

    Gent, I.P., Macintyre, E., Prosser, P., Smith, B.M., Walsh, T. (2001). Random constraint satisfaction: Flaws and structure. Constraints, 6(4), 345–372.

    MathSciNet  Article  MATH  Google Scholar 

  19. 19.

    van der Hofstad, R. (2016). Random graphs and complex networks cambridge university press.

  20. 20.

    IBM: IBM ILOG Solver V6.7. Accessed: 2019-05-02.

  21. 21.

    Jaspars, M. (1999). Computer assisted structure elucidation of natural products using two-dimensional NMR spectroscopy. Natural Product Reports, 16(2), 241–248.

    Article  Google Scholar 

  22. 22.

    Laburthe, F. (2000). CHOCO: Implementing A CP kernel. In: CP00 Post Conference Workshop on Techniques for Implementing Constraint Programming Systems (TRICS).

  23. 23.

    Lehmberg, O., Meusel, R., Bizer, C. (2014). Graph structure in the web: Aggregated by pay-level domain. In Proceedings of the 2014 ACM Conference on Web Science, WebSci’14. (pp. 119–128). New York: ACM.

  24. 24.

    Liebenau, A., & Wormald, N. (2017). Asymptotic enumeration of graphs by degree sequence, and the degree sequence of a random graph. arXiv:1702.08373.

  25. 25.

    MacKay, D.J.C. (2003). Information theory, inference and learning algorithms. Cambridge University Press.

  26. 26.

    Masui, H., & Hong, H. (2006). Spec2D: a structure elucidation system based on 1H NMR and h-H COSY spectra in organic chemistry. Journal of Chemical Information and Modeling, 46(2), 775–787.

    Article  Google Scholar 

  27. 27.

    Melançon, G., Dutour, I., Bousquet-Mélou, M. (2001). Random generation of directed acyclic graphs. In: Comb01, Euroconference on Combinatorics, Graph Theory and Applications, pp. 1–7. Spain.

  28. 28.

    Meringer, M., & Schymanski, E. (2013). Small molecule identification with MOLGEN and mass spectrometry. Metabolites, 3(2), 440–462.

    Article  Google Scholar 

  29. 29.

    Mihail, M., & Vishnoi, N.K. (2003). On generating graphs with prescribed vertex degrees for complex network modeling. In: 3Rd Workshop on Approximation and Randomization Algorithms in Communication NEtworks.

  30. 30.

    Milo, R., Kashtan, N., Itzkovitz, S., Newman, M.E., Alon, U. (2003). On the uniform generation of random graphs with prescribed degree sequences. arXiv:cond-mat/0312028.

  31. 31.

    Nuzillard, J.M., Naanaa, W., Pimont, S. (1995). Applying the constraint satisfaction problem paradigm to structure generation. Journal of Chemical Information and Modeling, 35(6), 1068–1073.

    Article  Google Scholar 

  32. 32.

    Nuzillard, J.M., & Plainchont, B. (2017). Tutorial for the structure elucidation of small molecules by means of the LSD software. Magnetic resonance in chemistry : MRC 56.

  33. 33.

    Omrani, M.A., & Naanaa, W. (2016). A constrained molecular graph generation with imposed and forbidden fragments. In: Proceedings of the 9th Hellenic Conference on Artificial Intelligence - SETN16. ACM Press.

  34. 34.

    Peironcely, J.E., Rojas-Chertó, M., Fichera, D., Reijmers, T., Coulier, L., Faulon, J.L., Hankemeier, T. (2012). OMG: Open Molecule generator. Journal of Cheminformatics, 4(1), 21.

    Article  Google Scholar 

  35. 35.

    Reinelt, G. (1994). The Traveling Salesman: Computational Solutions for TSP Applications. Berlin: Springer.

    Google Scholar 

  36. 36.

    Sarkar, D., Sarkar, U.K., Peng, G. (2007). Bandwidth requirement of links in a hierarchical caching network: a graph-based formulation, an algorithm and its performance evaluation. International Journal of Computers and Applications, 29(1), 70–78.

    Article  Google Scholar 

  37. 37.

    Steinbeck, C., Han, Y., Kuhn, S., Horlacher, O., Luttmann, E., Willighagen, E. (2003). The chemistry development kit (CDK): an open-source java library for chemo- and bioinformatics. Journal of Chemical Information and Computer Sciences, 43(2), 493–500.

    Article  Google Scholar 

  38. 38.

    Tsang, E. (2014). Foundations of constraint satisfaction. books on demand.

  39. 39.

    Williams, R. (2013). Faster all-pairs shortest paths via circuit complexity. CoRR arXiv:abs/1312.6680.

  40. 40.

    Zampelli, S., Deville, Y., Solnon, C. (2010). Solving subgraph isomorphism problems with constraint programming. Constraints, 15(3), 327–353.

    MathSciNet  Article  MATH  Google Scholar 

Download references

Author information



Corresponding author

Correspondence to Mohamed Amine Omrani.

Additional information

Publisher’s note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Rights and permissions

Reprints and Permissions

About this article

Verify currency and authenticity via CrossMark

Cite this article

Omrani, M.A., Naanaa, W. Constraints for generating graphs with imposed and forbidden patterns: an application to molecular graphs. Constraints 25, 1–22 (2020).

Download citation


  • Graph theory
  • Forbidden subgraph patterns
  • Constraint satisfaction problem
  • Constraint programming
  • Molecular generation