# A Tutorial on Hybrid Answer Set Solving with *clingo*

## Abstract

Answer Set Programming (ASP) has become an established paradigm for Knowledge Representation and Reasoning, in particular, when it comes to solving knowledge-intense combinatorial (optimization) problems. ASP’s unique pairing of a simple yet rich modeling language with highly performant solving technology has led to an increasing interest in ASP in academia as well as industry. To further boost this development and make ASP fit for real world applications it is indispensable to equip it with means for an easy integration into software environments and for adding complementary forms of reasoning.

In this tutorial, we describe how both issues are addressed in the ASP system *clingo*. At first, we outline features of *clingo*’s application programming interface (API) that are essential for multi-shot ASP solving, a technique for dealing with continuously changing logic programs. This is illustrated by realizing two exemplary reasoning modes, namely branch-and-bound-based optimization and incremental ASP solving. We then switch to the design of the API for integrating complementary forms of reasoning and detail this in an extensive case study dealing with the integration of difference constraints. We show how the syntax of these constraints is added to the modeling language and seamlessly merged into the grounding process. We then develop in detail a corresponding theory propagator for difference constraints and present how it is integrated into *clingo*’s solving process.

## Keywords

Logic Program Application Programming Interface Stable Model Integrity Constraint Satisfiability Modulo Theory## References

- 1.Balduccini, M., Lierler, Y.: Constraint answer set solver EZCSP and why integration schemas matter. CoRR, abs/1702.04047 (2017)Google Scholar
- 2.Banbara, M., Gebser, M., Inoue, K., Ostrowski, M., Peano, A., Schaub, T., Soh, T., Tamura, N., Weise, M.:
*aspartame*: solving constraint satisfaction problems with answer set programming. In: Calimeri, F., Ianni, G., Truszczynski, M. (eds.) LPNMR 2015. LNCS (LNAI), vol. 9345, pp. 112–126. Springer, Cham (2015). doi: 10.1007/978-3-319-23264-5_10 CrossRefGoogle Scholar - 3.Banbara, M., Kaufmann, B., Ostrowski, M., Schaub, T.: Clingcon: the next generation. Theory and Practice of Logic Programming (2017, To appear)Google Scholar
- 4.Baral, C.: Knowledge Representation, Reasoning and Declarative Problem Solving. Cambridge University Press, New York (2003)CrossRefMATHGoogle Scholar
- 5.Barrett, C., Sebastiani, R., Seshia, S., Tinelli, C.: Satisfiability modulo theories. In: Biere et al. [7], Chap. 26, pp. 825–885Google Scholar
- 6.Bartholomew, M., Lee, J.: System aspmt2smt: computing ASPMT theories by SMT solvers. In: Fermé, E., Leite, J. (eds.) JELIA 2014. LNCS (LNAI), vol. 8761, pp. 529–542. Springer, Cham (2014). doi: 10.1007/978-3-319-11558-0_37 Google Scholar
- 7.Biere, A., Heule, M., van Maaren, H., Walsh, T. (eds.) Handbook of Satisfiability. Frontiers in Artificial Intelligence and Applications, vol. 185. IOS Press (2009)Google Scholar
- 8.Cabalar, P., Kaminski, R., Ostrowski, M., Schaub, T.: An ASP semantics for default reasoning with constraints. In: Kambhampati, R. (ed.) Proceedings of the Twenty-Fifth International Joint Conference on Artificial Intelligence (IJCAI 2016), pp. 1015–1021. IJCAI/AAAI Press (2016)Google Scholar
- 9.Carro, M., King, A. (eds.): Technical Communications of the Thirty-second International Conference on Logic Programming (ICLP 2016). Open Access Series in Informatics (OASIcs), vol. 52 (2016)Google Scholar
- 10.Cotton, S., Maler, O.: Fast and flexible difference constraint propagation for DPLL(T). In: Biere, A., Gomes, C.P. (eds.) SAT 2006. LNCS, vol. 4121, pp. 170–183. Springer, Heidelberg (2006). doi: 10.1007/11814948_19 CrossRefGoogle Scholar
- 11.Crawford, J., Baker, A.: Experimental results on the application of satisfiability algorithms to scheduling problems. In: Hayes-Roth, B., Korf, R. (eds.) Proceedings of the Twelfth National Conference on Artificial Intelligence (AAAI 1994), pp. 1092–1097. AAAI Press (1994)Google Scholar
- 12.Dodaro, C., Ricca, F., Schüler, P.: External propagators in wasp: preliminary report. In: Proceedings of the Twenty-Third International Workshop on Experimental Evaluation of Algorithms for Solving Problems with Combinatorial Explosion (RCRA 2016), vol. 1745, pp. 1–9. CEUR Workshop Proceedings (2016)Google Scholar
- 13.Drescher, C., Walsh, T.: A translational approach to constraint answer set solving. Theory Pract. Logic Program.
**10**(4–6), 465–480 (2010)MathSciNetCrossRefMATHGoogle Scholar - 14.Eiter, T., Ianni, G., Krennwallner, T.: Answer set programming: a primer. In: Tessaris, S., Franconi, E., Eiter, T., Gutierrez, C., Handschuh, S., Rousset, M.-C., Schmidt, R.A. (eds.) Reasoning Web 2009. LNCS, vol. 5689, pp. 40–110. Springer, Heidelberg (2009). doi: 10.1007/978-3-642-03754-2_2 CrossRefGoogle Scholar
- 15.Gebser, M., Grote, T., Kaminski, R., Schaub, T.: Reactive answer set programming. In: Delgrande, J.P., Faber, W. (eds.) LPNMR 2011. LNCS (LNAI), vol. 6645, pp. 54–66. Springer, Heidelberg (2011). doi: 10.1007/978-3-642-20895-9_7 CrossRefGoogle Scholar
- 16.Gebser, M., Kaminski, R., Kaufmann, B., Lindauer, M., Ostrowski, M., Romero, J., Schaub, T., Thiele, S.: Potassco User Guide, 2nd edn. University of Potsdam (2015)Google Scholar
- 17.Gebser, M., Kaminski, R., Kaufmann, B., Ostrowski, M., Schaub, T., Thiele, S.: Engineering an incremental ASP solver. In: Garcia de la Banda, M., Pontelli, E. (eds.) ICLP 2008. LNCS, vol. 5366, pp. 190–205. Springer, Heidelberg (2008). doi: 10.1007/978-3-540-89982-2_23 CrossRefGoogle Scholar
- 18.Gebser, M., Kaminski, R., Kaufmann, B., Ostrowski, M., Schaub, T., Wanko, P.: Theory solving made easy with clingo 5. In: Carro and King [9], pp. 2:1–2:15Google Scholar
- 19.Gebser, M., Kaminski, R., Kaufmann, B., Schaub, T.: Answer Set Solving in Practice, Synthesis Lectures on Artificial Intelligence and Machine Learning. Morgan and Claypool Publishers (2012)Google Scholar
- 20.Gebser, M., Kaminski, R., Kaufmann, B., Schaub, T.: Clingo = ASP + control: Preliminary report. In: Leuschel, M., Schrijvers, T. (eds.) Technical Communications of the Thirtieth International Conference on Logic Programming (ICLP 2014). Theory and Practice of Logic Programming, arXiv:1405.3694v1, Online Supplement (2014). http://arxiv.org/abs/1405.3694v1
- 21.Gebser, M., Kaminski, R., Obermeier, P., Schaub, T.: Ricochet robots reloaded: a case-study in multi-shot ASP solving. In: Eiter, T., Strass, H., Truszczyński, M., Woltran, S. (eds.) Advances in Knowledge Representation, Logic Programming, and Abstract Argumentation. LNCS (LNAI), vol. 9060, pp. 17–32. Springer, Cham (2015). doi: 10.1007/978-3-319-14726-0_2 CrossRefGoogle Scholar
- 22.Gebser, M., Kaufmann, B., Schaub, T.: Conflict-driven answer set solving: from theory to practice. Artif. Intell.
**187–188**, 52–89 (2012)MathSciNetCrossRefMATHGoogle Scholar - 23.Gelfond, M., Kahl, Y.: Knowledge Representation, Reasoning, and the Design of Intelligent Agents: The Answer-Set Programming Approach. Cambridge University Press (2014)Google Scholar
- 24.Gelfond, M., Lifschitz, V.: The stable model semantics for logic programming. In: Kowalski, R., Bowen, K. (eds.) Proceedings of the Fifth International Conference and Symposium of Logic Programming (ICLP 1988), pp. 1070–1080. MIT Press (1988)Google Scholar
- 25.Gelfond, M., Lifschitz, V.: Classical negation in logic programs and disjunctive databases. New Gener. Comput.
**9**, 365–385 (1991)CrossRefMATHGoogle Scholar - 26.Janhunen, T., Kaminski, R., Ostrowski, M., Schaub, T., Schellhorn, S., Wanko, P.: Clingo goes linear constraints over reals and integers: A preliminary study (2017, In preparation)Google Scholar
- 27.Janhunen, T., Liu, G., Niemelä, I.: Tight integration of non-ground answer set programming and satisfiability modulo theories. In: Cabalar, P., Mitchell, D., Pearce, D., Ternovska, E. (eds.) Proceedings of the First Workshop on Grounding and Transformation for Theories with Variables (GTTV 2011), pp. 1–13 (2011)Google Scholar
- 28.Li, C., Manyà, F.: MaxSAT. In: Biere et al. [7], Chap. 19, pp. 613–631Google Scholar
- 29.Lierler, Y., Susman, B.: SMT-based constraint answer set solver EZSMT (system description). In: Carro and King [9], pp. 1:1–1:15Google Scholar
- 30.Lifschitz, V.: Introduction to answer set programming. Unpublished draft (2004)Google Scholar
- 31.Liu, G., Janhunen, T., Niemelä, I.: Answer set programming via mixed integer programming. In: Brewka, G., Eiter, T., McIlraith, S. (eds.) Proceedings of the Thirteenth International Conference on Principles of Knowledge Representation and Reasoning (KR 2012), pp. 32–42. AAAI Press (2012)Google Scholar
- 32.Marques-Silva, J., Lynce, I., Malik, S.: Conflict-driven clause learning SAT solvers. In: Biere et al. [7], Chap. 4, pp. 131–153Google Scholar
- 33.Mellarkod, V., Gelfond, M., Zhang, Y.: Integrating answer set programming and constraint logic programming. Ann. Math. Artif. Intell.
**53**(1–4), 251–287 (2008)MathSciNetCrossRefMATHGoogle Scholar - 34.Nieuwenhuis, R., Oliveras, A., Tinelli, C.: Solving SAT and SAT modulo theories: from an abstract Davis-Putnam-Logemann-Loveland procedure to DPLL(T). J. ACM
**53**(6), 937–977 (2006)MathSciNetCrossRefMATHGoogle Scholar - 35.Oikarinen, E., Janhunen, T.: Modular equivalence for normal logic programs. In: Brewka, G., Coradeschi, S., Perini, A., Traverso, P. (eds.) Proceedings of the Seventeenth European Conference on Artificial Intelligence (ECAI 2006), pp. 412–416. IOS Press (2006)Google Scholar
- 36.Redl, C.: The dlvhex system for knowledge representation: recent advances (system description). Theory Pract. Logic Program.
**16**(5–6), 866–883 (2016)MathSciNetCrossRefGoogle Scholar - 37.Roussel, O., Manquinho, V.: Pseudo-Boolean and cardinality constraints. In: Biere et al. [7], Chap. 22, pp. 695–733Google Scholar
- 38.Simons, P., Niemel, I., Soininen, T.: Extending and implementing the stable model semantics. Artif. Intell.
**138**(1–2), 181–234 (2002)MathSciNetCrossRefMATHGoogle Scholar - 39.Syrjänen, T.: Lparse 1.0 user’s manual (2001)Google Scholar
- 40.Tamura, N., Taga, A., Kitagawa, S., Banbara, M.: Compiling finite linear CSP into SAT. Constraints
**14**(2), 254–272 (2009)MathSciNetCrossRefMATHGoogle Scholar