An Experimental Comparison of Constraint Logic Programming and Answer Set Programming

Total Page:16

File Type:pdf, Size:1020Kb

An Experimental Comparison of Constraint Logic Programming and Answer Set Programming An Experimental Comparison of Constraint Logic Programming and Answer Set Programming Agostino Dovier Andrea Formisano Enrico Pontelli Universita` di Udine, Universita` di Perugia New Mexico State University Dip. di Matematica e Informatica Dip. di Matematica e Informatica Dept. of Computer Science [email protected] [email protected] [email protected] Abstract are encoded as atomic formulae and relationships as pro- gram rules. It is well-known (Marek & Truszczynski 1991; Answer Set Programming (ASP) and Constraint Logic Baral 2003) that, given a propositional normal logic pro- Programming over finite domains (CLP(FD)) are two gram P , deciding whether P admits an answer set (Gel- declarative programming paradigms that have been ex- fond & Lifschitz 1988) is a NP-complete problem. As a tensively used to encode applications involving search, optimization, and reasoning (e.g., commonsense rea- consequence, any NP-complete problem can be encoded soning and planning). This paper presents experimen- as a propositional normal logic program under answer set tal comparisons between the declarative encodings of semantics. Answer-set solvers are programs designed to various computationally hard problems in both frame- compute the answer sets of normal logic programs. Some works. The objective is to investigate how the solvers solvers provide also syntactic extensions to facilitate pro- in the two domains respond to different problems, high- gram development—e.g., limited forms of aggregation (Si- lighting strengths and weaknesses of their implementa- mons 2000)—and classes of optimization statements, used tions, and suggesting criteria for choosing one approach to select answer sets that maximize or minimize an objec- over the other. Ultimately, the work in this paper is ex- tive function dependent on the content of the answer set. pected to lay the foundations for transfer of technology between the two domains, e.g., suggesting ways to use 1 An alternative framework, frequently adopted to handle CLP(FD) in the execution of ASP. NP-complete, combinatorial, and optimization problems, is CLP(FD) (Jaffar & Maher 1994; Marriott & Stuckey 1998). In this context, a finite domain of objects (typically integers) Introduction is associated to each variable in the problem specification, The objective of this work is to experimentally compare and the problem-derived relationships between such vari- the use of two distinct logic-based paradigms, tradition- ables are encoded as constraints (e.g., s = t, s<t). This ally recognized as excellent tools to tackle computation- type of framework supports the natural and declarative en- ally hard problems and to encode AI applications (such as coding of search strategies and NP-complete problems. In- planning, scheduling, and optimization problems). The two deed, a rich literature has been developed presenting appli- paradigms considered are Answer Set Programming (ASP) cations of CLP(FD) to a variety of search and optimization (Baral 2003) and Constraint Logic Programming over Finite problems (Marriott & Stuckey 1998), and several efficient Domains (CLP(FD)) (Marriott & Stuckey 1998). The moti- implementations have been developed. vation for this investigation, originally described in (Dovier, Formisano, & Pontelli 2005), arises from the successful use In this paper, we summarize the outcome of a study aimed of both paradigms in dealing with various classes of com- at comparing these two declarative approaches in solving binatorial problems, and the need to better understand their combinatorial problems. The study has been originally pre- respective strengths and weaknesses. Ultimately, we hope sented in (Dovier, Formisano, & Pontelli 2005). We ad- this work will indicate methods for integration and coopera- dress a set of computationally hard problems—in particu- tion between the two paradigms. lar, we mainly consider decision problems known to be NP- complete. We formalize each problem, both in CLP(FD) ASP is a paradigm deriving from logic programming and in ASP, by taking advantage of the specific features under answer set semantics, where problem components available in each logical framework, and attempting to en- code the various problems in the most declarative way possi- Copyright c 2007, Association for the Advancement of Artificial ble. In particular, we adopt a constraint-and-generate strat- Intelligence (www.aaai.org). All rights reserved. 1This study has been originally presented in ICLP 2005 egy (Marriott & Stuckey 1998) for the construction of the (Dovier, Formisano, & Pontelli 2005). This research is par- CLP(FD) programs, while in ASP we exploit the natural tially supported by MIUR projects PRIN05-015491 and FIRB03- generate-and-test approach (Baral 2003). Whenever possi- RBNE03B8KK, and by NSF grants CNS-0220590, CNS-0454066, ble, we make use of encodings of these problems that have and HRD-0420407. been presented and widely accepted in the literature. 1622 Overview of the Computational Models V is a denumerable collection of variables, and Π is a finite Constraint Logic Programming is a programming paradigm set of predicate symbols. The set of terms is F∪V, and an that is particularly well suited for encoding combinatorial atom is a formula of the type p(t1,...,tk), where p ∈ Π and optimization problems. CLP naturally merges two declar- t1,...,tk are terms. An ASP program is a finite collection ative paradigms: constraint satisfaction and logic program- of rules, where rules are of the form ming. Let Σ be a logic language signature Σ=F, V, Π ∪ h :− a1,...,am,notb1,...,notbn h, a ,...,a ,b ,...,b ΠC , where F is a finite set of function and constant sym- where 1 m 1 n are atoms. Each program is bols, V is a denumerable collection of variables, and Π∪ΠC viewed as a syntactic sugar representing the set of ground F is a finite set of predicate symbols (with Π and ΠC dis- instances of its rules (computed using the constants in ). joint). A constraint is a first-order formula over F, V, ΠC . A special type of rules are the so called constraints—rules Typically, constraints are conjunctions of literals, e.g., 0 < with an empty head; in this case, the head of the rule is im- X, X < 3,X + Y =4. Following the traditional logic pro- plicitly assumed to be false. gramming notation, a comma indicates a conjunction, capi- Given a ground program P , the answer set semantics tal letters denote variables, and the symbol :− denotes the characterizes the semantics of P in terms of a collection implication ←. CLP lets a programmer use different classes of minimal models (called answer sets). A set of ground atoms M is an answer set if M is the unique minimal model of constraints and domains to encode problems. For com- M binatorial problems, it is common to use finite domain con- of the program P , containing the rules h :− a1,...,ak straints, namely arithmetic constraints between arithmetic such that h :− a1,...,ak,notb1,...,notbh is in P and expressions, where each variable is associated to a finite do- {b1,...,bh}∩M = ∅. In ASP, each problem is mod- main of possible values. In this case the interpretation of eled as a collection of rules, in such a way that the solu- variables, expressions, and constraints is over Z. tions to the problem correspond one-to-one to the answer A CLP program over Σ is a finite set of rules of the form sets of the program. An ASP Solver is a program that com- 1 1 m m putes all the answer sets of a given ASP program. A solver p(s1,...,sn):− C, q1(t ,...,t ),...,qm(t ,...,t ) 1 n1 1 nm can be seen as a theorem prover, or model builder, enhanced i with several built-in heuristics to guide the exploration of where C is a constraint, si and t are (F, V)-terms, and j the search space. Most ASP solvers rely on variations of p, q1,...,qm are predicate symbols of Π. Observe that a CLP program without constraints is a Prolog program. the DPLL procedure (Davis, Logemann, & Loveland 1962). CLP programs are commonly developed using a Such solvers are often equipped with a front-end that trans- constrain-and-generate technique, where an initial deter- forms a collection of non-propositional normal logic pro- ministic phase imposes a number of constraints, and a non- gramming clauses (with limited use of function symbols) to finite deterministic phase generates/explores the solution space. In a set of ground instances of such clauses. the constraint phase, in particular, a finite domain of val- ues is assigned to each variable. For instance, the constraint The Experimental Framework domain([A,B,C],1,5) assigns the set of admissible val- The experimental studies, originally reported in (Dovier, ues {1,2,3,4,5} to the variables A, B, and C. The built-in Formisano, & Pontelli 2005), have been conducted us- predicate labeling implements the non-deterministic gen- ing both CLP(FD) implementations and ASP solvers. erate phase through some form of search space exploration. The CLP(FD) programs have been designed for SICStus Each time a variable is assigned a value, a deterministic Prolog—and adapted to run also on GNU-Prolog, B-Prolog, propagation stage is executed, removing from the domains and ECLiPSe. The ASP programs have been designed to of the other variables those values that are incompatible with be processed by lparse, the grounding preprocessor used the assignments already performed. Various options, affect- by both the SMODELS and the CMODELS systems. The ing, for instance, the variable selection criteria, the ordering CMODELS system makes use of a SAT solver to compute of the attempted values, etc., can be used to guide the search. answer sets—in our experiments we mainly used mChaff The main structure of a program using this programming (Moskewicz et al. 2001) and Simo (Giunchiglia, Lierler, style is the following: & Maratea 2006).
Recommended publications
  • Answer Set Programming: a Tour from the Basics to Advanced Development Tools and Industrial Applications
    Answer Set Programming: A tour from the basics to advanced development tools and industrial applications Nicola Leone and Francesco Ricca Department of Mathematics and Computer Science, University of Calabria, Italy leone,ricca @mat.unical.it { } Abstract. Answer Set Programming (ASP) is a powerful rule-based language for knowledge representation and reasoning that has been developed in the field of logic programming and nonmonotonic reasoning. After more than twenty years from the introduction of ASP, the theoretical properties of the language are well understood and the solving technology has become mature for practical appli- cations. In this paper, we first present the basics of the ASP language, and we then concentrate on its usage for knowledge representation and reasoning in real- world contexts. In particular, we report on the development of some industry-level applications with the ASP system DLV, and we illustrate two advanced develop- ment tools for ASP, namely ASPIDE and JDLV, which speed-up and simplify the implementation of applications. 1 Introduction Answer Set Programming (ASP) [11, 19, 30] is a powerful rule-based language for knowledge representation and reasoning that has been developed in the field of logic programming and nonmonotonic reasoning. ASP features disjunction in rule heads, non monotonic negation in rule bodies [30], aggregate atoms [16] for concise mod- eling of complex combinatorial problems, and weak constraints [12] for the declarative encoding of optimization problems. Computational problems, even of high complexity [19], can be solved in ASP by specifying a logic program, i.e., a set of logic rules, such that its answer sets correspond to solutions, and then, using an answer set solver to find such solutions [38, 34].
    [Show full text]
  • The Design and Implementation of Object-Constraint Programming
    Felgentreff, The Design and Implementation of Object-Constraint Programming The Design and Implementation of Object-Constraint Programming von Tim Felgentreff Dissertation zur Erlangung des akademischen Grades des Doktor der Naturwissenschaften (Doctor rerum naturalium) vorgelegt der Mathematisch-Naturwissenschaftlichen Fakultät der Universität Potsdam. Betreuer Prof. Dr. Robert Hirschfeld Fachgebiet Software-Architekturen Hasso-Plattner-Institut Universität Potsdam 21. April 2017 Erklärung Hiermit erkläre ich an Eides statt, dass ich die vorliegende Dissertation selbst angefertigt und nur die im Literaturverzeichnis aufgeführten Quellen und Hilfsmittel verwendet habe. Diese Dissertation oder Teile davon wurden nicht als Prüfungsarbeit für eine staatliche oder andere wissenschaftliche Prüfung eingereicht. Ich versichere weiterhin, dass ich diese Arbeit oder eine andere Abhandlung nicht bei einer anderen Fakultät oder einer anderen Universität eingereicht habe. Potsdam, den 21. April 2017 Tim Felgentreff v Abstract Constraints allow developers to specify properties of systems and have those properties be main- tained automatically. This results in compact declarations to describe interactive applications avoid- ing scattered code to check and imperatively re-satisfy invariants in response to user input that perturbs the system. Constraints thus provide flexibility and expressiveness for solving complex problems and maintaining a desired system state. Despite these advantages, constraint program- ming is not yet widespread, with imperative programming still being the norm. There is a long history of research on constraint programming as well as its integration with general purpose programming languages, especially from the imperative paradigm. However, this integration typically does not unify the constructs for encapsulation and abstraction from both paradigms and often leads to a parallel world of constraint code fragments and abstractions inter- mingled with the general purpose code.
    [Show full text]
  • Complexity Results for Probabilistic Answer Set Programming
    International Journal of Approximate Reasoning 118 (2020) 133–154 Contents lists available at ScienceDirect International Journal of Approximate Reasoning www.elsevier.com/locate/ijar Complexity results for probabilistic answer set programming ∗ Denis Deratani Mauá a, , Fabio Gagliardi Cozman b a Institute of Mathematics and Statistics, Universidade de São Paulo, Brazil b Escola Politécnica, Universidade de São Paulo, Brazil a r t i c l e i n f o a b s t r a c t Article history: We analyze the computational complexity of probabilistic logic programming with Received 16 May 2019 constraints, disjunctive heads, and aggregates such as sum and max. We consider Received in revised form 25 October 2019 propositional programs and relational programs with bounded-arity predicates, and look Accepted 9 December 2019 at cautious reasoning (i.e., computing the smallest probability of an atom over all Available online 16 December 2019 probability models), cautious explanation (i.e., finding an interpretation that maximizes the Keywords: lower probability of evidence) and cautious maximum-a-posteriori (i.e., finding a partial Probabilistic logic programming interpretation for a set of atoms that maximizes their lower probability conditional on Answer set programming evidence) under Lukasiewicz’s credal semantics. Computational complexity © 2019 Elsevier Inc. All rights reserved. 1. Introduction Probabilities and logic programming have been combined in a variety of ways [1–8]. A particularly interesting and power- ful combination is offered by probabilistic answer set programming, which exploits the powerful knowledge representation and problem solving toolset of answer set programming [9]. Available surveys describe probabilistic logic programming in detail and go over many promising applications [10–13].
    [Show full text]
  • Constraint Satisfaction with Preferences Ph.D
    MASARYK UNIVERSITY BRNO FACULTY OF INFORMATICS } Û¡¢£¤¥¦§¨ª«¬­Æ !"#°±²³´µ·¸¹º»¼½¾¿45<ÝA| Constraint Satisfaction with Preferences Ph.D. Thesis Brno, January 2001 Hana Rudová ii Acknowledgements I would like to thank my supervisor, Ludˇek Matyska, for his continuous support, guidance, and encouragement. I am very grateful for his help and advice, which have allowed me to develop both as a person and as the avid student I am today. I want to thank to my husband and my family for their support, patience, and love during my PhD study and especially during writing of this thesis. This research was supported by the Universities Development Fund of the Czech Repub- lic under contracts # 0748/1998 and # 0407/1999. Declaration I declare that this thesis was composed by myself, and all presented results are my own, unless otherwise stated. Hana Rudová iii iv Contents 1 Introduction 1 1.1 Thesis Outline ..................................... 1 2 Constraint Satisfaction 3 2.1 Constraint Satisfaction Problem ........................... 3 2.2 Optimization Problem ................................ 4 2.3 Solution Methods ................................... 5 2.4 Constraint Programming ............................... 6 2.4.1 Global Constraints .............................. 7 3 Frameworks 11 3.1 Weighted Constraint Satisfaction .......................... 11 3.2 Probabilistic Constraint Satisfaction ........................ 12 3.2.1 Problem Definition .............................. 13 3.2.2 Problems’ Lattice ............................... 13 3.2.3 Solution
    [Show full text]
  • Answer Set Programming: a Primer?
    Answer Set Programming: A Primer? Thomas Eiter1, Giovambattista Ianni2, and Thomas Krennwallner1 1 Institut fur¨ Informationssysteme, Technische Universitat¨ Wien Favoritenstraße 9-11, A-1040 Vienna, Austria feiter,[email protected] 2 Dipartimento di Matematica, Universita´ della Calabria, I-87036 Rende (CS), Italy [email protected] Abstract. Answer Set Programming (ASP) is a declarative problem solving para- digm, rooted in Logic Programming and Nonmonotonic Reasoning, which has been gaining increasing attention during the last years. This article is a gentle introduction to the subject; it starts with motivation and follows the historical development of the challenge of defining a semantics for logic programs with negation. It looks into positive programs over stratified programs to arbitrary programs, and then proceeds to extensions with two kinds of negation (named weak and strong negation), and disjunction in rule heads. The second part then considers the ASP paradigm itself, and describes the basic idea. It shows some programming techniques and briefly overviews Answer Set solvers. The third part is devoted to ASP in the context of the Semantic Web, presenting some formalisms and mentioning some applications in this area. The article concludes with issues of current and future ASP research. 1 Introduction Over the the last years, Answer Set Programming (ASP) [1–5] has emerged as a declar- ative problem solving paradigm that has its roots in Logic Programming and Non- monotonic Reasoning. This particular way of programming, in a language which is sometimes called AnsProlog (or simply A-Prolog) [6, 7], is well-suited for modeling and (automatically) solving problems which involve common sense reasoning: it has been fruitfully applied to a range of applications (for more details, see Section 6).
    [Show full text]
  • Constraint Programming and Operations Research
    Noname manuscript No. (will be inserted by the editor) Constraint Programming and Operations Research J. N. Hooker and W.-J. van Hoeve November 2017 Abstract We present an overview of the integration of constraint program- ming (CP) and operations research (OR) to solve combinatorial optimization problems. We interpret CP and OR as relying on a common primal-dual solution approach that provides the basis for integration using four main strategies. The first strategy tightly interweaves propagation from CP and relaxation from OR in a single solver. The second applies OR techniques to domain filtering in CP. The third decomposes the problem into a portion solved by CP and a portion solved by OR, using CP-based column generation or logic-based Benders decomposition. The fourth uses relaxed decision diagrams developed for CP propagation to help solve dynamic programming models in OR. The paper cites a significant fraction of the literature on CP/OR integration and concludes with future perspectives. Keywords Constraint Programming, Operations Research, Hybrid Optimization 1 Introduction Constraint programming (CP) and operations research (OR) have the same overall goal. They strive to capture a real-world situation in a mathematical model and solve it efficiently. Both fields use constraints to build the model, often in conjunction with an objective function to evaluate solutions. It is therefore only natural that the two fields join forces to solve problems. J. N. Hooker Carnegie Mellon University, Pittsburgh, USA E-mail: [email protected] W.-J. van Hoeve Carnegie Mellon University, Pittsburgh, USA E-mail: [email protected] 2 J. N.
    [Show full text]
  • Chapter 1 GLOBAL CONSTRAINTS and FILTERING ALGORITHMS
    Chapter 1 GLOBAL CONSTRAINTS AND FILTERING ALGORITHMS Jean-Charles R´egin ILOG 1681, route des Dolines, Sophia Antipolis, 06560 Valbonne, France [email protected] Abstract Constraint programming (CP) is mainly based on filtering algorithms; their association with global constraints is one of the main strengths of CP. This chapter is an overview of these two techniques. Some of the most frequently used global constraints are presented. In addition, the filtering algorithms establishing arc consistency for two useful con- straints, the alldiff and the global cardinality constraints, are fully de- tailed. Filtering algorithms are also considered from a theoretical point of view: three different ways to design filtering algorithms are described and the quality of the filtering algorithms studied so far is discussed. A categorization is then proposed. Over-constrained problems are also mentioned and global soft constraints are introduced. Keywords: Global constraint, filtering algorithm, arc consistency, alldiff, global car- dinality constraint, over-constrained problems, global soft constraint, graph theory, matching. 1. Introduction A constraint network (CN) consists of a set of variables; domains of possible values associated with each of these variables; and a set of con- straints that link up the variables and define the set of combinations of values that are allowed. The search for an instantiation of all vari- ables that satisfies all the constraints is called a Constraint Satisfaction Problem (CSP), and such an instantiation is called a solution of a CSP. A lot of problems can be easily coded in terms of CSP. For instance, CSP has already been used to solve problems of scene analysis, place- 1 2 ment, resource allocation, crew scheduling, time tabling, scheduling, fre- quency allocation, car sequencing, and so on.
    [Show full text]
  • Answer Set Programming
    ANSWER SET PROGRAMMING Tran Cao Son Department of Computer Science New Mexico State University Las Cruces, NM 88011, USA [email protected] http://www.cs.nmsu.edu/~tson October 2005 Answer Set Programming. Acknowledgement This tutorial contains some materials from tutorials on answer set programming and on knowledge representation and logic programming from those provided by • Chitta Baral, available at www.public.asu.edu/~cbaral. • Michael Gelfond, available at www.cs.ttu.ued/~mgelfond. Tran Cao Son 1 Answer Set Programming. Introduction — Answer Set Programming Answer set programming is a new programming paradigm. It is introduced in the late 90’s and manages to attracts the intention of different groups of researchers thanks to its: • declarativeness: programs do not specify how answers are computed; • modularity: programs can be developed incrementally; • expressiveness: answer set programming can be used to solve problems in high 2 complexity classes (e.g. ΣP , Π2P , etc.) Answer set programming has been applied in several areas: reasoning about actions and changes, planning, configuration, wire routing, phylogenetic inference, semantic web, information integration, etc. Tran Cao Son 2 Answer Set Programming. Purpose • Introduce answer set programming • Provide you with some initial references, just in case • ...you get excited about answer set programming Tran Cao Son 3 Answer Set Programming. Outline • Foundation of answer set programming: logic programming with answer set semantics (syntax, semantics, early application). • Answer set programming: general ideas and examples • Application of answer set programming in – Knowledge representation – Constraint satisfaction problem – Combinatoric problems – Reasoning about action and change – Planning and diagnostic reasoning • Current issues Tran Cao Son 4 LOGIC PROGRAMMING AND ANSWER SET SEMANTICS Answer Set Programming.
    [Show full text]
  • A Meta-Programming Technique for Debugging Answer-Set Programs∗
    A Meta-Programming Technique for Debugging Answer-Set Programs∗ Martin Gebser1, Jorg¨ Puhrer¨ 2, Torsten Schaub1, and Hans Tompits2 1 Institut fur¨ Informatik, Universitat¨ Potsdam, Germany, {gebser,torsten}@cs.uni-potsdam.de 2 Institut fur¨ Informationssysteme 184/3, Technische Universitat¨ Wien, Austria, {puehrer,tompits}@kr.tuwien.ac.at Abstract applying such an approach to ASP results in some deci- sive drawbacks, undermining the declarativity of answer- Answer-set programming (ASP) is widely recognised as a vi- able tool for declarative problem solving. However, there is set semantics. In particular, establishing canonical tracing- currently a lack of tools for developing answer-set programs. based techniques for debugging answer-set programs re- In particular, providing tools for debugging answer-set pro- quires also a canonical procedure for answer-set computa- grams has recently been identified as a crucial prerequisite tion, and programmers would have to be familiar with the al- for a wider acceptance of ASP. In this paper, we introduce a gorithm. This would lead to a shift of perspectives in which meta-programming technique for debugging in ASP. The ba- an answer-set program is degraded from a declarative prob- sic question we address is why interpretations expected to be lem description to a set of parameters for a static solving answer sets are not answer sets of the program to debug. We algorithm. Therefore, we argue for declarative debugging thus deal with finding semantical errors of programs. The ex- strategies that are independent of answer-set computation. planations provided by our method are based on an intuitive Indeed, among the few approaches dealing with debug- scheme of errors that relies on a recent characterisation of the answer-set semantics.
    [Show full text]
  • Backtracking Search (Csps) ■Chapter 5 5.3 Is About Local Search Which Is a Very Useful Idea but We Won’T Cover It in Class
    CSC384: Intro to Artificial Intelligence Backtracking Search (CSPs) ■Chapter 5 5.3 is about local search which is a very useful idea but we won’t cover it in class. 1 Hojjat Ghaderi, University of Toronto Constraint Satisfaction Problems ● The search algorithms we discussed so far had no knowledge of the states representation (black box). ■ For each problem we had to design a new state representation (and embed in it the sub-routines we pass to the search algorithms). ● Instead we can have a general state representation that works well for many different problems. ● We can build then specialized search algorithms that operate efficiently on this general state representation. ● We call the class of problems that can be represented with this specialized representation CSPs---Constraint Satisfaction Problems. ● Techniques for solving CSPs find more practical applications in industry than most other areas of AI. 2 Hojjat Ghaderi, University of Toronto Constraint Satisfaction Problems ●The idea: represent states as a vector of feature values. We have ■ k-features (or variables) ■ Each feature takes a value. Domain of possible values for the variables: height = {short, average, tall}, weight = {light, average, heavy}. ●In CSPs, the problem is to search for a set of values for the features (variables) so that the values satisfy some conditions (constraints). ■ i.e., a goal state specified as conditions on the vector of feature values. 3 Hojjat Ghaderi, University of Toronto Constraint Satisfaction Problems ●Sudoku: ■ 81 variables, each representing the value of a cell. ■ Values: a fixed value for those cells that are already filled in, the values {1-9} for those cells that are empty.
    [Show full text]
  • Prolog Lecture 6
    Prolog lecture 6 ● Solving Sudoku puzzles ● Constraint Logic Programming ● Natural Language Processing Playing Sudoku 2 Make the problem easier 3 We can model this problem in Prolog using list permutations Each row must be a permutation of [1,2,3,4] Each column must be a permutation of [1,2,3,4] Each 2x2 box must be a permutation of [1,2,3,4] 4 Represent the board as a list of lists [[A,B,C,D], [E,F,G,H], [I,J,K,L], [M,N,O,P]] 5 The sudoku predicate is built from simultaneous perm constraints sudoku( [[X11,X12,X13,X14],[X21,X22,X23,X24], [X31,X32,X33,X34],[X41,X42,X43,X44]]) :- %rows perm([X11,X12,X13,X14],[1,2,3,4]), perm([X21,X22,X23,X24],[1,2,3,4]), perm([X31,X32,X33,X34],[1,2,3,4]), perm([X41,X42,X43,X44],[1,2,3,4]), %cols perm([X11,X21,X31,X41],[1,2,3,4]), perm([X12,X22,X32,X42],[1,2,3,4]), perm([X13,X23,X33,X43],[1,2,3,4]), perm([X14,X24,X34,X44],[1,2,3,4]), %boxes perm([X11,X12,X21,X22],[1,2,3,4]), perm([X13,X14,X23,X24],[1,2,3,4]), perm([X31,X32,X41,X42],[1,2,3,4]), perm([X33,X34,X43,X44],[1,2,3,4]). 6 Scale up in the obvious way to 3x3 7 Brute-force is impractically slow There are very many valid grids: 6670903752021072936960 ≈ 6.671 × 1021 Our current approach does not encode the interrelationships between the constraints For more information on Sudoku enumeration: http://www.afjarvis.staff.shef.ac.uk/sudoku/ 8 Prolog programs can be viewed as constraint satisfaction problems Prolog is limited to the single equality constraint: – two terms must unify We can generalise this to include other types of constraint Doing so leads
    [Show full text]
  • Integrating Answer Set Programming and Constraint Logic Programming
    Integrating Answer Set Programming and Constraint Logic Programming Veena S. Mellarkod and Michael Gelfond and Yuanlin Zhang {veena.s.mellarkod,mgelfond,yzhang}@cs.ttu.edu Texas Tech University Dedicated to Victor Marek on his 65th birthday as a specification for the sets of beliefs to be held by a ra- tional reasoner associated with Π. Such sets, called an- Abstract swer sets of Π, are represented by collections of ground literals. A rule (1) is viewed as a constraint which says We introduce a knowledge representation language that if literals lk+1, . , ln belong to an answer set A of AC(C) extending the syntax and semantics of ASP Π and none of the literals ln+1, . , lm belong to A then and CR-Prolog, give some examples of its use, and A must contain at least one of the literals l , . , l . To present an algorithm, ACsolver, for computing answer 1 k sets of AC(C) programs. The algorithm does not re- form answer sets of Π, the reasoner must satisfy Π’s quire full grounding of a program and combines “clas- rules together with the rationality principle which says: sical” ASP solving methods with constraint logic pro- “Believe nothing you are not forced to believe”. gramming techniques and CR-Prolog based abduction. The AC(C) based approach often allows to solve prob- Given a computational problem P , an ASP programmer lems which are impossible to solve by more traditional • Expresses information relevant to the problem in the ASP solving techniques. We belief that further inves- language of ASP; tigation of the language and development of more effi- cient and reliable solvers for its programs can help to • Reduces P to a query Q requesting computation of substantially expand the domain of applicability of the (parts of) answer sets of Π.
    [Show full text]