Optimizing Answer Set Computation via Heuristic-Based Decomposition
Francesco Calimeri, Simona Perri, Jessica Zangari

TL;DR
This paper introduces a heuristic-based decomposition approach to automatically transform logic programs in Answer Set Programming, significantly improving the efficiency of answer set computation, especially during grounding, by integrating into the DLV system.
Contribution
It presents a novel heuristic-guided rewriting method for logic programs that enhances ASP system performance, particularly in grounding, and is adaptable to various systems and policies.
Findings
Improved ASP grounding efficiency with new heuristics.
Effective integration into DLV system's grounding process.
Significant performance gains demonstrated through experiments.
Abstract
Answer Set Programming (ASP) is a purely declarative formalism developed in the field of logic programming and nonmonotonic reasoning: computational problems are encoded by logic programs whose answer sets, corresponding to solutions, are computed by an ASP system. Different, semantically equivalent, programs can be defined for the same problem; however, performance of systems evaluating them might significantly vary. We propose an approach for automatically transforming an input logic program into an equivalent one that can be evaluated more efficiently. One can make use of existing tree-decomposition techniques for rewriting selected rules into a set of multiple ones; the idea is to guide and adaptively apply them on the basis of proper new heuristics, to obtain a smart rewriting algorithm to be integrated into an ASP system. The method is rather general: it can be adapted to any…
| Problem | -DLV | lpopt -DLV | -DLV | -DLV gap | ||||
| #grnd | time | #grnd | time | #grnd | time | absolute | % | |
| Abstract Dialectical Frameworks | 20 | 0,12 | 20 | 0,12 | 20 | 0,12 | 0,00 | 0% |
| Combined Configuration | 20 | 13,58 | 20 | 13,39 | 20 | 13,15 | 0,24 | 2% |
| Complex Optimization | 20 | 57,56 | 20 | 60,72 | 20 | 57,24 | 0,32 | 1% |
| Connected Still Life | 20 | 0,10 | 20 | 0,10 | 20 | 0,10 | 0,00 | 0% |
| Consistent Query Answering | 20 | 76,44 | 0 | US | 20 | 77,00 | -0,57 | -1% |
| Crossing Minimization | 20 | 0,10 | 20 | 0,10 | 20 | 0,10 | 0,00 | 0% |
| Graceful Graphs | 20 | 0,30 | 20 | 0,31 | 20 | 0,30 | 0,00 | 0% |
| Graph Coloring | 20 | 0,10 | 20 | 0,10 | 20 | 0,10 | 0,00 | 0% |
| Incremental Scheduling | 20 | 16,07 | 20 | 15,74 | 20 | 16,21 | -0,47 | -3% |
| Knight Tour With Holes | 20 | 1,83 | 20 | 5,98 | 20 | 1,84 | -0,01 | -1% |
| Labyrinth | 20 | 1,97 | 20 | 1,83 | 20 | 2,02 | -0,18 | -10% |
| Maximal Clique | 20 | 4,93 | 20 | 21,60 | 20 | 4,96 | -0,03 | -1% |
| MaxSAT | 20 | 3,85 | 20 | 8,87 | 20 | 3,86 | -0,01 | 0% |
| Minimal Diagnosis | 20 | 5,09 | 20 | 4,30 | 20 | 4,22 | 0,07 | 2% |
| Nomistery | 20 | 3,45 | 20 | 1,94 | 20 | 3,63 | -1,68 | -87% |
| Partner Units | 20 | 0,46 | 20 | 0,47 | 20 | 0,47 | 0,00 | 0% |
| Permutation Pattern Matching | 20 | 130,47 | 20 | 4,35 | 20 | 4,21 | 0,14 | 3% |
| Qualitative Spatial Reasoning | 20 | 5,44 | 20 | 5,50 | 20 | 5,44 | 0,00 | 0% |
| Reachability | 20 | 126,54 | 0 | US | 20 | 126,14 | 0,40 | 0% |
| Ricochet Robots | 20 | 0,36 | 20 | 0,39 | 20 | 0,39 | -0,03 | -9% |
| Sokoban | 20 | 1,21 | 20 | 1,23 | 20 | 1,22 | -0,01 | -1% |
| Stable Marriage | 20 | 118,55 | 20 | 125,78 | 20 | 119,53 | -0,99 | -1% |
| Steiner Tree | 20 | 29,00 | 20 | 28,92 | 20 | 29,11 | -0,19 | -1% |
| Strategic Companies | 20 | 0,19 | 0 | US | 20 | 0,20 | 0,00 | -1% |
| System Synthesis | 20 | 1,09 | 20 | 1,15 | 20 | 1,08 | 0,01 | 1% |
| Valves Location Problem | 20 | 2,52 | 20 | 2,53 | 20 | 2,54 | -0,02 | -1% |
| Video Streaming | 20 | 0,10 | 20 | 0,10 | 20 | 0,10 | 0,00 | 0% |
| Visit-all | 20 | 1,18 | 20 | 0,44 | 20 | 0,48 | -0,04 | -9% |
| Total Grounded Instances | 560/560 | 500/560 | 560/560 | |||||
| -DLV | lpopt -DLV | -DLV |
| 8 | 82 | 96 |
| -DLV | -DLV | -DLV gain | ||
|---|---|---|---|---|
| All problems | #solved instances | 1688 | 1787 | 6% |
| Average time | 22,26 | 15,39 | 31% | |
| # timeouts | 113 | 19 | 83% | |
| # memouts | 5 | 0 | 100% | |
| Affected problems | # solved instances | 392 | 491 | 25% |
| Average time | 40,10 | 10,28 | 74% | |
| # timeouts | 103 | 9 | 91% | |
| # memouts | 5 | 0 | 100% |
| Problem | -DLV clasp | lpopt -DLV clasp | -DLV clasp | -DLV wasp | lpopt -DLV wasp | -DLV wasp | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| #solved | time | #solved | time | #solved | time | #solved | time | #solved | time | #solved | time | |
| Abstract Dialectical Frameworks | 20 | 6.88 | 20 | 7.36 | 20 | 6.89 | 11 | 33.26 | 11 | 22.38 | 11 | 32.21 |
| Combined Configuration | 8 | 148.64 | 9 | 176.67 | 10 | 182.41 | 1 | 311.89 | 0 | TO | 0 | TO |
| Complex Optimization | 18 | 149.84 | 19 | 167.58 | 18 | 149.44 | 6 | 150.30 | 5 | 99.05 | 6 | 148.00 |
| Connected Still Life | 6 | 220.70 | 6 | 243.05 | 6 | 222.12 | 12 | 55.02 | 12 | 78.03 | 12 | 55.47 |
| Consistent Query Answering | 20 | 87.05 | 0 | US | 20 | 87.39 | 18 | 87.47 | 0 | US | 18 | 88.05 |
| Crossing Minimization | 7 | 53.02 | 6 | 64.23 | 7 | 56.79 | 19 | 3.50 | 19 | 2.40 | 19 | 5.58 |
| Graceful Graphs | 9 | 141.77 | 10 | 130.97 | 9 | 140.44 | 6 | 174.17 | 4 | 122.14 | 6 | 171.42 |
| Graph Coloring | 15 | 162.25 | 15 | 171.39 | 15 | 160.44 | 8 | 133.71 | 7 | 217.23 | 8 | 133.34 |
| Incremental Scheduling | 13 | 90.62 | 11 | 39.16 | 14 | 128.81 | 8 | 155.20 | 5 | 137.74 | 6 | 124.89 |
| Knight Tour With Holes | 11 | 55.76 | 10 | 26.90 | 11 | 56.04 | 10 | 35.50 | 8 | 63.97 | 10 | 35.67 |
| Labyrinth | 12 | 63.19 | 11 | 120.09 | 12 | 67.25 | 11 | 104.73 | 10 | 168.65 | 11 | 106.71 |
| Maximal Clique | 0 | TO | 0 | TO | 0 | TO | 9 | 353.03 | 9 | 353.63 | 9 | 352.56 |
| MaxSAT | 7 | 39.67 | 7 | 46.81 | 7 | 39.77 | 19 | 91.01 | 19 | 95.82 | 19 | 91.49 |
| Minimal Diagnosis | 20 | 8.90 | 20 | 8.46 | 20 | 8.32 | 20 | 30.77 | 20 | 29.38 | 20 | 25.95 |
| Nomystery | 8 | 138.64 | 9 | 103.16 | 7 | 203.32 | 8 | 37.32 | 9 | 33.34 | 7 | 167.59 |
| Partner Units | 14 | 19.81 | 14 | 20.29 | 14 | 20.26 | 5 | 116.99 | 10 | 168.07 | 10 | 168.24 |
| Permutation Pattern Matching | 11 | 164.63 | 17 | 152.47 | 20 | 15.62 | 20 | 182.53 | 10 | 279.70 | 20 | 23.36 |
| Qualitative Spatial Reasoning | 20 | 125.13 | 20 | 125.75 | 20 | 124.97 | 13 | 145.50 | 13 | 145.23 | 13 | 145.67 |
| Reachability | 20 | 137.55 | 0 | US | 20 | 137.53 | 6 | 138.40 | 0 | US | 6 | 139.17 |
| Ricochet Robots | 9 | 67.84 | 12 | 109.32 | 12 | 188.07 | 7 | 206.86 | 8 | 87.95 | 9 | 134.22 |
| Sokoban | 8 | 73.95 | 9 | 82.45 | 8 | 76.90 | 8 | 86.00 | 9 | 64.59 | 8 | 88.25 |
| Stable Marriage | 5 | 389.26 | 7 | 341.43 | 5 | 387.85 | 7 | 410.46 | 7 | 427.66 | 7 | 431.15 |
| Steiner Tree | 3 | 243.89 | 3 | 244.89 | 3 | 242.45 | 1 | 131.66 | 1 | 131.75 | 1 | 131.80 |
| Strategic Companies | 17 | 119.63 | 0 | US | 17 | 122.24 | 7 | 31.38 | 0 | US | 7 | 30.95 |
| System Synthesis | 0 | TO | 0 | TO | 0 | TO | 0 | TO | 0 | TO | 0 | TO |
| Valves Location Problem | 16 | 43.09 | 16 | 26.09 | 16 | 43.05 | 15 | 40.93 | 15 | 39.27 | 15 | 41.32 |
| Video Streaming | 13 | 61.84 | 10 | 75.70 | 13 | 61.63 | 9 | 9.15 | 0 | TO | 9 | 9.03 |
| Visit-all | 8 | 16.90 | 8 | 15.22 | 8 | 15.21 | 8 | 62.11 | 8 | 61.28 | 8 | 60.06 |
| Total Solved Instances | 318/560 | 269/560 | 332/560 | 272/560 | 219/560 | 275/560 | ||||||
| Problem | #inst. | -DLV | lpopt -DLV | -DLV | |||
| #grounded | time | #grounded | time | #grounded | time | ||
| Abstract Dialectical Frameworks | 30 | 30 | 0.13 | 30 | 0.13 | 30 | 0.13 |
| Bottle Filling Problem | 30 | 30 | 4.12 | 30 | 6.86 | 30 | 4.39 |
| Chemical Classification | 30 | 30 | 87.81 | 30 | 403.38 | 30 | 88.22 |
| Complex Optimization * | 29 | 29 | 36.28 | 29 | 38.39 | 29 | 36.07 |
| Connected Still Life * | 10 | 10 | 0.12 | 10 | 0.13 | 10 | 0.15 |
| Crossing Minimization * | 30 | 30 | 0.10 | 30 | 0.10 | 30 | 0.10 |
| Graceful Graphs | 30 | 30 | 0.37 | 30 | 0.39 | 30 | 0.37 |
| Graph Colouring * | 30 | 30 | 0.10 | 30 | 0.10 | 30 | 0.10 |
| Hanoi Tower | 30 | 30 | 0.22 | 30 | 0.23 | 30 | 0.30 |
| Incremental Scheduling * | 30 | 12 | 297.95 | 17 | 229.49 | 21 | 221.17 |
| Knight Tour with Holes * | 30 | 20 | 176.99 | 20 | 181.16 | 20 | 178.59 |
| Labyrinth | 30 | 30 | 1.49 | 30 | 1.40 | 30 | 1.51 |
| Maximal Clique * | 30 | 30 | 0.34 | 30 | 1.11 | 30 | 0.34 |
| Minimal Diagnosis * | 30 | 30 | 2.54 | 30 | 2.20 | 30 | 2.57 |
| Nomystery * | 30 | 30 | 34.91 | 21 | 100.14 | 30 | 35.28 |
| Permut. Pattern Matching * | 30 | 28 | 57.71 | 30 | 3.64 | 30 | 62.32 |
| Qualitative Spatial Reasoning * | 30 | 30 | 2.85 | 30 | 2.87 | 30 | 2.84 |
| Reachability | 30 | 30 | 101.93 | 0 | US | 30 | 102.04 |
| Ricochet Robots | 30 | 30 | 0.27 | 30 | 0.31 | 30 | 0.31 |
| Sokoban | 30 | 30 | 2.65 | 30 | 2.68 | 30 | 2.69 |
| Solitaire | 27 | 27 | 0.13 | 27 | 0.18 | 27 | 0.20 |
| Stable Marriage * | 30 | 30 | 28.35 | 30 | 2.65 | 30 | 2.46 |
| Strategic Companies | 30 | 30 | 0.19 | 0 | US | 30 | 0.19 |
| Valves Location | 30 | 30 | 3.97 | 30 | 3.98 | 30 | 3.93 |
| Visit-all * | 30 | 30 | 0.13 | 30 | 0.14 | 30 | 0.13 |
| Weighted-Sequence Problem * | 30 | 30 | 2.87 | 30 | 9.61 | 30 | 2.95 |
| Total Grounded Instances | 726/756 | 664/756 | 737/756 | ||||
| Problem | #inst. | -DLV | -DLV | ||||||
| #grounded | time | #grounded | time | #grounded | time | #grounded | time | ||
| Competition Instances | |||||||||
| Comp. Enc. | Comp. Enc. | Comp. Enc. | Comp. Enc. | ||||||
| Incr. Scheduling | 30 | 12 | 297.95 | 30 | 54.65 | 21 | 221.17 | 30 | 1.93 |
| Maximal Clique | 30 | 30 | 0.34 | 30 | 2.96 | 30 | 0.34 | 30 | 3.11 |
| Minimal Diagnosis | 30 | 30 | 2.54 | 30 | 1.76 | 30 | 2.57 | 30 | 1.76 |
| Nomystery | 30 | 30 | 34.91 | 30 | 47.24 | 30 | 35.28 | 30 | 47.11 |
| Perm. Pattern Match. | 30 | 28 | 57.71 | 30 | 0.27 | 30 | 62.32 | 30 | 0.27 |
| Stable Marriage | 30 | 30 | 28.35 | 30 | 3.16 | 30 | 2.46 | 30 | 2.86 |
| Competition Instances | |||||||||
| Comp. Enc. | Comp. Enc. | Comp. Enc. | Comp. Enc. | ||||||
| Incr. Scheduling | 20 | 11 | 336.77 | 20 | 16.07 | 19 | 211.61 | 20 | 16.21 |
| Maximal Clique | 20 | 20 | 6.63 | 20 | 4.93 | 20 | 6.58 | 20 | 4.96 |
| Minimal Diagnosis | 20 | 20 | 4.12 | 20 | 5.09 | 20 | 4.14 | 20 | 4.22 |
| Nomystery | 20 | 20 | 55.11 | 20 | 3.45 | 20 | 43.74 | 20 | 3.63 |
| Perm. Pattern Match. | 20 | 16 | 168.93 | 20 | 130.47 | 20 | 150.99 | 20 | 4.21 |
| Stable Marriage | 20 | 0 | TO | 20 | 118.55 | 20 | 172.68 | 20 | 119.53 |
| Problem | #inst. | -DLV | lpopt -DLV | -DLV | |||
| #grounded | time | #grounded | time | #grounded | time | ||
| Cutedge | 130 | 130 | 34.38 | 130 | 1.64 | 130 | 1.08 |
| Graph 5col | 180 | 180 | 0.12 | 180 | 0.14 | 180 | 0.12 |
| Ground Explosion 2 | 17 | 7 | 73.33 | 7 | 73.02 | 7 | 72.87 |
| Reach | 50 | 50 | 0.29 | 50 | 0.76 | 50 | 0.30 |
| TimeTabling | 27 | 27 | 85.57 | 27 | 63.67 | 27 | 57.67 |
| Total Solved Instances | 367/377 | 367/377 | 367/377 | ||||
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
[algorithm]labelformat=empty
Optimizing Answer Set Computation via Heuristic-Based Decomposition 111This work is the extended version of a paper originally appeared in the Proceedings of 20th Symposium on Practical Aspects of Declarative Languages (PADL 2018), January 8–9, 2018, Los Angeles, USA. Program chairs were Kevin Hamlen and Nicola Leone.
The paper presents new material that integrates and extends what has been reported in the original paper; in particular, it provides the reader with proper preliminaries (omitted in the original paper for space constraints), more detailed discussions on the proposed techniques and richer comparisons with related approaches, along with an extended number of examples. Furthermore, a more thorough experimental activity is presented, discussed in part in the main text and in part in the appendices, that covers also new domains that were unexplored in the original paper.
Francesco Calimeri
Simona Perri and Jessica Zangari
Department of Mathematics and Computer Science
University of Calabria
Rende
Italy
calimeri,perri,zangari@mat.unical.it
Abstract
Answer Set Programming (ASP) is a purely declarative formalism developed in the field of logic programming and nonmonotonic reasoning: computational problems are encoded by logic programs whose answer sets, corresponding to solutions, are computed by an ASP system. Different, semantically equivalent, programs can be defined for the same problem; however, performance of systems evaluating them might significantly vary. We propose an approach for automatically transforming an input logic program into an equivalent one that can be evaluated more efficiently. One can make use of existing tree-decomposition techniques for rewriting selected rules into a set of multiple ones; the idea is to guide and adaptively apply them on the basis of proper new heuristics, to obtain a smart rewriting algorithm to be integrated into an ASP system. The method is rather general: it can be adapted to any system and implement different preference policies. Furthermore, we define a set of new heuristics tailored at optimizing grounding, one of the main phases of the ASP computation; we use them in order to implement the approach into the ASP system DLV, in particular into its grounding subsystem -DLV, and carry out an extensive experimental activity for assessing the impact of the proposal.
keywords:
Answer Set Programming, Artificial Intelligence, ASP in practice
1 Introduction
Answer Set Programming (ASP) [Brewka et al. (2011), Gelfond and Lifschitz (1991)] is a declarative programming paradigm proposed in the area of non-monotonic reasoning and logic programming. With ASP, computational problems are encoded by logic programs whose answer sets, corresponding to solutions, are computed by an ASP system [Lifschitz (1999)].
The evaluation of ASP programs is “traditionally” split into two phases: grounding, that generates a propositional theory semantically equivalent to the input program, and solving, that applies propositional techniques for computing the intended semantics [Alviano et al. (2017), Gebser et al. (2015), Kaufmann et al. (2016), Leone et al. (2006)]; nevertheless, in the latest years several approaches that deviate from this schema have been proposed [Palù et al. (2009), Dao-Tran et al. (2012), Eiter et al. (2017), Lefèvre et al. (2017)].
Typically, the same computational problem can be encoded by means of many different ASP programs which are semantically equivalent; however, real ASP systems may perform very differently when evaluating each one of them. This behavior is due, in part, to specific aspects, that strictly depend on the ASP system employed, and, in part, to general “intrinsic” aspects, depending on the program at hand which could feature some characteristics that can make computation easier or harder. Thus, often, to have satisfying performance, expert knowledge is required in order to select the best encoding. This issue, in a certain sense, conflicts with the declarative nature of ASP that, ideally, should free the users from the burden of the computational aspects. For this reason, ASP systems tend to be endowed with proper pre-processing means aiming at making performance less encoding-dependent; intuitively, this is crucial for fostering and easing the usage of ASP in practice.
A proposal in this direction is lpopt [Bichler et al. (2016a)], a pre-processing tool for ASP systems that rewrites rules in input programs by means of tree-decomposition algorithms. The rationale comes from the fact that, when programs contain rules featuring long bodies, ASP systems performance might benefit from a careful split of such rules into multiple, smaller ones. However, it is worth noting that, while in some cases such decomposition is convenient, in other cases keeping the original rule is preferable; hence, a black-box decomposition, like the one of lpopt, makes it difficult to predict whether it will lead to benefits or disadvantages.
Inspired by the idea implemented in lpopt of rewriting ASP programs by means of tree-decomposition, we propose here a method that aims at taking full advantage from rewriting, still avoiding performance drawbacks by estimating its effects in advance. It analyzes each input rule before the evaluation, and estimates whether it is convenient to decompose it into an equivalent set of smaller rules, or not; if more than one decomposition is possible, the most promising is selected. The method is general and defined so that all choices are made according to proper criteria and heuristics that can be customized: it can be tailored to different phases of the ASP computation, and it is not tied to a specific system. Furthermore, we define new heuristics and criteria relying on data and statistics dynamically computed during the instantiation with the aim of optimizing the performances of -DLV [Calimeri et al. (2017b)], a recently released deductive database system that currently serves also as the grounding subsystem of DLV [Alviano et al. (2017)]. In addition, we present here an actual implementation into -DLV and perform an extensive experimental activity in order to asses the effects of our technique on ASP program optimization.
The remainder of the paper is structured as follows. In Section 2 we recall ASP basics along with some other preliminary notions; in Section 3 we introduce an abstract heuristic-guided decomposition algorithm for ASP programs in its general form, while in Section 4 we describe how we adapt it in order to foster an actual implementation into the -DLV grounder, along with custom heuristics for guiding the process. Section 5 presents the results of an extensive experimental activity aimed at assessing the impact of the proposed method, and effectiveness of the proposed heuristics on grounding performance; we also shed a light on the impact on solvers. Our conclusions are drawn in Section 6. Some additional experiments, that have been omitted from the main text for the sake of readability, are reported and discussed in appendices.
2 Preliminaries
In this section we provide the reader with some preliminaries; in particular, we first briefly introduce Answer Set Programming and then recall how hypergraphs can be used in order to represent ASP rules along with tree-decomposition strategies for rewriting them.
2.1 Answer Set Programming
A significant amount of work has been carried out on extending the basic language of ASP, and the community recently agreed on a standard input language for ASP systems: [Calimeri et al. (2013)], the official language of the ASP Competition series [Calimeri et al. (2016), Gebser et al. (2016)]. For the sake of simplicity, we focus next on the basic aspects of the language; for a complete reference to the standard, and further details about advanced ASP features, we refer the reader to [Calimeri et al. (2013)] and the vast literature.
A term is either a simple term or a functional term. A simple term is either a constant or a variable. If are terms and is a function symbol of arity , then is a functional term. If are terms and is a predicate symbol of arity , then is an atom. A literal is of the form or , where is an atom; in the former case is positive, otherwise negative. A rule is of the form where , ; and are atoms. We define = (the head of ) and (the body of ), where (the positive body) and = (the negative body). If then is a (strong) constraint; if and then is a fact. A rule is safe if each variable of has an occurrence in 222We remark that this definition of safety is specific for the syntax considered herein. For a complete definition we refer the reader to [Calimeri et al. (2013)].. For a rule , we denote as , and the set of variables occurring in , and , respectively. An ASP program is a finite set of safe rules. A program (a rule, a literal) is ground if it contains no variables. A predicate is defined by a rule if it occurs in . A predicate defined only by facts is an EDB predicate, the remaining are IDB predicates. The set of all facts in is denoted by Facts(); the set of instances of all EDB predicates in is denoted by EDB().
Given a program , the Herbrand universe of , denoted by , consists of all ground terms that can be built combining constants and function symbols appearing in . The Herbrand base of , denoted by , is the set of all ground atoms obtainable from the atoms of by replacing variables with elements from . A substitution for a rule is a mapping from the set of variables of to the set of ground terms. A ground instance of a rule is obtained applying a substitution to . The full instantiation Ground() of is defined as the set of all ground instances of its rules over . An interpretation for is a subset of . A positive literal (resp., a negative literal ) is true w.r.t. if (resp., ); it is false otherwise. Given a ground rule , we say that is satisfied w.r.t. if some atom appearing in is true w.r.t. or some literal appearing in is false w.r.t. . Given a program , we say that is a model of , iff all rules in Ground() are satisfied w.r.t. . A model is minimal if there is no model for such that . The Gelfond-Lifschitz reduct [Gelfond and Lifschitz (1991)] of , w.r.t. an interpretation , is the positive ground program obtained from Ground() by: deleting all rules having a negative literal false w.r.t. ; deleting all negative literals from the remaining rules. is an answer set for a program iff is a minimal model for . The set of all answer sets for is denoted by .
2.2 ASP Computation
The high expressiveness of ASP comes at the price of a high computational cost in the worst case [Eiter et al. (1997), Leone et al. (2006)], which makes the implementation of efficient ASP systems a difficult task. Thanks to the effort by a scientific community that grew over time, there are nowadays a number of systems that support ASP and its variants [Simons et al. (2002), Ward and Schlipf (2004), Janhunen et al. (2006), Giunchiglia et al. (2006), Gebser et al. (2012), Alviano et al. (2015), Leone et al. (2006), Gebser et al. (2014), Palù et al. (2009), Lefèvre et al. (2017), Dao-Tran et al. (2012), Weinzierl (2017)].
The well-established, mainstream approach for the evaluation of ASP programs [Kaufmann et al. (2016)] relies on two phases, usually referred to as instantiation or grounding, and solving or answer sets search, respectively. Given a (non-ground) ASP program , grounding consists of producing a propositional theory semantically equivalent to , i.e. such that does not contain any variable but has the same answer sets as . Given that, in the worst case, the solving stage may take up to exponential time in the size of [Ben-Eliyahu and Dechter (1994), Ben-Eliyahu-Zohary and Palopoli (1997)], modern ASP systems employ intelligent grounding procedures so that is significantly smaller than the full instantiation Ground(). Once the program has been computed, solving takes place, taking as input and computing its answer sets by means of propositional algorithms. The majority of current ASP implementations follows this two-phase computation, either by explicitly relying on stand-alone grounders [Syrjänen (2001), Faber et al. (2012), Gebser et al. (2011)] and solvers [Simons et al. (2002), Ward and Schlipf (2004), Janhunen et al. (2006), Giunchiglia et al. (2006), Gebser et al. (2012), Alviano et al. (2015)], or integrating the modules into monolithic systems [Gebser et al. (2014), Leone et al. (2006), Alviano et al. (2017)]. Notably, given that both phases are, in general, computationally expensive [Eiter et al. (1997), Dantsin et al. (2001)], efficient ASP implementations depend on proper optimization of both.
Alternative solutions [Palù et al. (2009), Lefèvre et al. (2017), Dao-Tran et al. (2012), Weinzierl (2017)] adopt a lazy grounding technique, in which grounding and solving steps are interleaved, and rules are grounded on-demand during solving. These systems try to overcome the so called grounding bottleneck, that occurs on problems for which the instantiation is inherently so huge that its actual materialization is not suitable in practice. For this reason, this approach looks promising; however, current implementations do not match, in the general case, performance of the more “traditional” systems, that proved instead to be reliable and well-performing in a wider range of scenarios.
Notably, the herein presented technique, introduced in Section 3, is general enough to be adopted with both approaches, by defining suitable heuristics and properly customizing its integration.
2.3 Tree-Decompositions for Rewriting ASP Rules
Hypergraphs are useful for describing the structure of many computational problems; furthermore, it is possible to decompose them into different parts, so that the solution(s) of problems can be obtained by a polynomial divide-and-conquer algorithm that properly exploits this division [Gottlob et al. (2001), Gottlob et al. (2005)]. Such ideas can guide a rewriting of an ASP program: indeed, a logic rule can be represented as a hypergraph [Morak and Woltran (2012)], and hence properly decomposed.
Discussing in detail how tree decompositions can be computed and rewritings induced is out of the scope of this paper; indeed, our main goal is to find a way for correctly identifying in advance in which cases their application pays off in terms of efficiency, while dealing with ASP rules. However, in order to ease the reading, in the following, we briefly recall an intuitive description of some crucial notions for the ASP context; for further details we refer the reader to [Bichler et al. (2016a)] and the existing literature.
A (undirected) hypergraph is a generalization of a (undirected) graph in which an edge can join two or more vertices. An ASP rule can be represented as a hypergraph by adding a hyperedge for each literal containing the variables appearing in . A tree decomposition of a hypergraph (see [Robertson and Seymour (1986), Gottlob et al. (2016)]) is a tuple (, ), where = is a tree and is a function associating a set of vertices to each vertex of the decomposition tree , such that for each there is a node such that , and for each the set is connected in . Intuitively, a tree decomposition of is a tree such that each vertex is associated to a bag, i.e., a set of nodes of , and such that each hyperedge of is covered by some bag, and for each node of all vertices of whose bag contains it induce a connected subtree of .
A tree decomposition can be used in order to produce a set of rules that rewrites ; such set is called rule decomposition, and denoted by . In particular, contains a (newly generated) rule for each vertex of , on the basis of the included variables. Roughly, each literal in the body of , such that the set of variables in is contained in , is added to the body of the rule generated for . Eventually, some optional rules may be added to in order to guarantee safety. Note that, since different choices for handling safety can be performed, the way in which a tree decomposition is converted into a rule decomposition might be not unique. Moreover, interestingly, in general, more than one decomposition is possible for each rule.
The following running example, which we will refer to throughout the paper, illustrates this mechanism.
Example 1
Let us consider the rule:
[TABLE]
from the encoding of the problem Nomystery from the ASP Competition (see Section 5), where, for the sake of readability, predicates and variables have been renamed. Figure 1 depicts the conversion of into the hypergraph , along with two possible decompositions: and , that induce two different rewritings. According to , can be rewritten into the set of rules :
[TABLE]
In particular, the rule features the same head of and as body the literals needed in order to cover the node of containing the variables ; features as head the fresh predicate that links it to and collects in its body a set of literals covering the variables appearing in the other node of ; eventually, is needed to ensure safety of : the atom is added in the body of and to the head of , whose body features a set of literals coming from and covers (note that in this case the set is unique). Note that, a different rewriting could be obtained by differently handling safety of ; for instance, one could avoid to introduce and, instead, add the literals , and to the body of .
Similarly, according to , can be rewritten into as follows:
[TABLE]
3 A Heuristic-guided Decomposition Algorithm
In the previous section we recalled how tree decomposition of hypergraphs can be used in order to guide rewritings of ASP rules. Interestingly, the lpopt [Bichler et al. (2016a)] preprocessor is a proposal in this direction, that rewrites an ASP program before it is fed to an ASP system.
As previously noted, for each rule, several different rule decompositions might exist. However, when fed to a real ASP system, different yet equivalent rewritings require, in general, significantly different evaluation times. Thus, proper means for reasonably and effectively choose the “best” rewriting are crucial; furthermore, it might be the case that, whatever the choice, sticking to the original, unrewritten rule, is still preferable. Hence, a black-box approach, such as the one of lpopt, makes it difficult to effectively take advantage from the decomposition rewritings; this is clearly noticeable by looking at experiments, as discussed in Section 5.
In this section we introduce a smart decomposition algorithm that aims at addressing the above issues; it is designed to be integrated into an ASP system, and uses information available during the computation to predict, according to proper criteria, whether decomposing will pay off or not; moreover, it chooses the most promising decomposition, among the several possible ones. In the following, we first describe the method in its general form, that can be easily adapted to different real systems; a complete actual implementation, specialized for the DLV system, is presented later on.
The abstract algorithm SmartDecomposition is shown in Figure 2; we indicate as tree decomposition an actual tree decomposition of a hypergraph, while with rule decomposition we denote the conversion of a tree decomposition into a set of ASP rules. Given a (non-ground) input rule , the algorithm first heuristically computes, by means of the Estimate function, a value that estimates how much the presence of in the program impacts on the whole computation; then, the function GenerateRuleDecompositons computes a set of possible rule decompositions , from which ChooseBestDecomposition selects the best ; hence, function EstimateDecomposition computes the value that estimates the impact of having in place of in the input program. Eventually, function DecompositionIsPreferable is in charge of comparing and and deciding if decomposing is convenient. We remark that functions Estimate, ChooseBestDecomposition, EstimateDecomposition and DecompositionIsPreferable are left unimplemented, as they are completely customizable; they must be implemented by defining proper criteria that take into account features and information within the specific evaluation procedure, and the actual ASP system the algorithm is being integrated into.
Figure 2 reports also the implementation of function GenerateRuleDecompositons. Here, ToHypergraph converts a input rule into a hypergraph , which is iteratively analysed in order to produce possible tree decompositions, by means of the function GenerateTreeDecompositions. Also these stages can be customized in an actual implementation, according to different criteria and the features of the system at hand; for space reasons, we refrain from going into details that are not relevant for the description of the approach. The function ToRules, given a tree decomposition and a rule , converts into a rule decomposition for . In particular, for each node in , it adds a new logic rule to , possibly along with some additional auxiliary rules needed for ensuring safety. The process is, again, customizable, and should be defined according to the function ToHypergraph.
The general definition of the algorithm provided so far is independent from any actual implementation, and its behaviour can significantly change depending on the customization choices, as discussed above. However, in order to give an intuition on how it works, we make use of our running example for illustrating a plausible execution.
Example 2
Given rule of Example 1, let us imagine that function GenerateRuleDecompositions computes the tree decompositions and and then, by means of ToRules, the set of rule decompositions consisting of and is generated. Note that and are added for ensuring safety of rules and , respectively. Next step consists of the choice between and for the best promising decomposition, according to the actual criteria of choice. Supposing that it is , DecompositionIsPreferable compares the estimated impacts and , in order to decide if keeping or substituting it with .
4 Integrating the SmartDecomposition Algorithm into a Real System: the DLV Case
In this section we illustrate how the general SmartDecomposition algorithm of Section 3 can be customized in order to be integrated into an actual ASP implementation. Interestingly, such customization can be tailored with different purposes, for both the two-phase-based and the lazy-grounding-based systems, for optimizing solving or instantiation performance, according to different criteria (times, size, structure, etc.). In this work, we focus on the widespread DLV system [Alviano et al. (2017), Leone et al. (2006)], which complies to the two-phase strategy, with the explicit aim of optimizing performance of its grounding subsystem -DLV [Calimeri et al. (2017b)]. A detailed description of the -DLV computation is out of the scope of this work (the interested reader is referred to [Calimeri et al. (2017b)]); however, for the sake of readability, we briefly recall the basics of its machinery.
Given an ASP program :
is parsed, and the extensional database (EDB) is built. 2. 2.
Each rule in is analyzed, and possibly rewritten according to different strategies for optimization purposes; the result constitutes the intensional database (IDB). 3. 3.
Dependencies among IDB rules and predicates are examined; such dependencies induce the splitting of into modules, and a suitable processing ordering is computed so that an incremental evaluation is possible according to the definitions in [Faber et al. (2012)]. 4. 4.
The program is grounded one module at a time by means of a proper adaptation of a semi-naïve schema [Faber et al. (2012), Ullman (1988)] that evaluates each rule in a module according to a rule instantiation procedure that in turn produces its ground instances. Rules within a module can be recursive or not. While for the former ones the procedure might be iteratively invoked, for the not recursive rules a single call of the rule instantiation procedure is enough to produce all their ground instances. 5. 5.
The collection of the ground rules generated from all IDB rules compose, along with , the resulting ground program .
The core of the -DLV computation is the rule instantiation process mentioned in the step 4 of the sketch above, which constitutes one of the more computationally heavy tasks. Basically, when grounding a rule of , instead of replacing with every possible constant appearing in , the rule instantiation iteratively substitutes the variables in each body literal with constants appearing in the corresponding predicate extension. A predicate extension of a predicate is the set of all ground atoms having as predicate. More in detail, given a rule and the set of extensions of its body predicates, the rule instantiation produces ground instances of by iterating on positive body literals333Because of the safety condition, in order to generate a completely ground instance of , it is enough to have a substitution for the variables occurring in the positive literals. and looking for all possible valid substitutions. Intuitively, this phase resembles the evaluation of relational joins on the positive body literals, where predicate extensions can be seen as tables whose tuples consist of the ground instances. Once a valid substitution is found for all variables in , it is applied to in order to obtain a totally ground rule, i.e. a ground instance of , say . This possibly leads to the generation of new ground atoms occurring in the head of ; such new ground atoms are added to the corresponding predicate extensions. It is worth noting that, the set of all predicate extensions is built dynamically starting from ground atoms appearing in and then, adding each new ground atom coming from heads of produced ground rules; the chosen evaluation order plays a key role in this respect as it ensures that when evaluating a rule the extensions of all body predicates needed for instantiating have been fully generated.
Besides the basic schema herein sketched, -DLV employs smart optimizations techniques, geared towards the efficient production of a ground program that is considerably smaller, still preserving the semantics. Roughly, when a rule is going to be instantiated, -DLV firstly performs a pre-processing that might lead some adjustments over the rule to different extents, and after that the actual rule instantiation takes place, a post-processing refines the output. Some optimizations, such as, for instance, join-ordering strategies, operate in the pre-processing phase; some explicitly take place during the actual instantiation process, such as non-chronological backtracking; some operate across the two phases, such as indexing techniques for a quick instances retrieval; others take place in the post-processing step, such as the simplification that removes ground rules and literals in the bodies that do not contribute to the semantics.
The SmartDecomposition algorithm implementation herein described works in the pre-processing phase.
We provide next some details on how we defined the functions that have been left unimplemented in the general description of Section 3 (Estimate, ChooseBestDecomposition, EstimateDecomposition and DecompositionIsPreferable), along with the proposed heuristics, and discuss further implementation issues.
4.1 The Estimate Function
The function Estimate (Figure 3) heuristically measures the cost of instantiating a rule before it is actually grounded. To this aim, we propose a heuristics inspired by the ones introduced in the database field [Ullman (1988)] and adopted in [Leone et al. (2001)] to estimate the size of a join operation. In particular, it relies on statistics over body predicates, such as size of extensions and argument selectivities; we readapted it in order to estimate the cost of grounding a rule as the total number of operations needed in order to perform the task, rather than estimate the size of the join of its body literals. Let be an atom; we denote with the set of variables occurring in , while represents the number of different tuples for in the ground extension of . Moreover, for each variable , we denote by the selectivity of in , i.e., the number of distinct values in the field corresponding to over the ground extension of . Given a rule , let be the ordered list of atoms appearing in , for . Initially, the cost of grounding , denoted by , is set to , then the following formula is iteratively applied up to the last atom in the body in order to obtain the total estimation cost for . More in detail, let us suppose that we estimated the cost of joining the atoms for , and consequently we want to estimate the cost of joining the next atom ; if we denote by the relation obtained by joining all atoms in , then:
[TABLE]
where is the maximum selectivity of computed among the atoms in containing as variable, and is the set of the indexing arguments of . We note that, at each step, once the atom has been considered, , representing the selectivity of in the virtual relation obtained at step , has to be estimated in order to be used at next steps:
[TABLE]
Intuitively, the formula tries to determine the cost of grounding , by estimating the total number of operations to be performed. In particular, the first factor is intended to estimate how many instances for have to be considered, while the second factor represents the reduction in the search space implied by . To obtain a realistic estimate, the presence of indexing techniques, used in -DLV to reduce the number of such operations [Calimeri et al. (2017b)], has been taken into account.
Example 3
Let us consider the rule:
[TABLE]
of Example 1, and let us assume that we are dealing with an instance that contains the facts444According to syntax, the term stands for all values from to .:
[TABLE]
The Estimate function first estimates, by means of Formula (1), the cost of computing the joins . In this case, denoting by , , and so on, we have that , and it is estimated as:
[TABLE]
Then, the formula is used again in order to estimate the cost of the join between and , and so on up to the last join . At each step, size and variable selectivities for each are known, while such data for the intermediate relations are estimated. The size of is estimated as , and selectivities of all variables appearing in (i.e., ,, and ) are estimated, according to Formula (2), as:
* (indeed, )*
- -
* (indeed, )*
- -
* (indeed, ).*
The process is similarly iterated until the end of the body, from left to right.
4.2 The EstimateDecomposition Function
The EstimateDecomposition function is illustrated in Figure 3: after some pre-processing steps, it computes the cost of a given decomposition as the sum of the cost of each rule in it. Let be a rule and be a rule decomposition for . In order to estimate the cost of grounding , one must estimate the cost of grounding all rules in . For each the estimate is performed by means of Formula (1). Nevertheless, it is worth noting that each , in addition to predicates originally appearing in , denoted as known predicates, may contain some fresh predicates, generated during the decomposition. Concerning known predicates, thanks to the rule instantiation ordering followed by -DLV, as already pointed out in Section 4, extensions size and selectivity needed for computing the formula are directly available: hence, there is no need for estimations. On the contrary, for fresh predicates, that have been “locally” introduced and do not appear in any of the rules in the original input program, such data is not available, and must be estimated. To this aim, the dependencies among the rules in are analyzed, and an ordering that guarantees a correct instantiation is determined. Such dependencies come out from the definitions in [Faber et al. (2012)]: rules depending only on known predicates can be grounded first, while rules depending also on new predicates can be grounded only once the rules that define them have been instantiated. Assuming that for the set a correct instantiation order is represented by , for each in this ordered list, if for , and if is a fresh predicate, we estimate: the size of the ground extension of , denoted , by means of a formula conceived for estimating the size of a join relation, based on criteria that are well-established in the database field and reported in [Leone et al. (2001)]; the selectivity of each argument as . Therefore, the procedure PreProcess invoked in EstimateDecomposition (see Figure 3) amounts to preprocess the rules in according to a valid grounding order to obtain the extension sizes and the argument selectivities for involved fresh predicates, based on the above mentioned formula. Once estimates for fresh predicates are available, the actual estimate of grounding can be performed.
Example 4
*Let us consider again the rule of our running Example 1 and its decomposition : *
[TABLE]
In order to compute we first need to determine a correct evaluation order of the rules in ; the only valid one is . Indeed, has only known predicates in its body, thus can be evaluated first; the body of contains, besides to known predicates, , whose estimates will be available just after the evaluation of ; eventually, depends also on , whose estimates will be available right after the evaluation of . Once the estimates for the fresh predicates and are obtained, they are used for computing , and with Formula (1), and then for obtaining = .
4.3 The ChooseBestDecomposition and DecompositionIsPreferable Functions
The function ChooseBestDecomposition estimates the costs of all decompositions of a rule by means of EstimateDecomposition, and returns the one with the smallest estimated cost; let us denote it by . The function DecompositionIsPreferable is then in charge of deciding whether will substitute , by relying on and , that are the estimated costs associated to and , respectively. More in detail, it computes the ratio . Intuitively, when the ratio , decomposing is convenient; nevertheless, it is worth remembering that the costs are estimated, and, in particular, as discussed in Section 4.2, the estimate of the cost of a decomposition requires to estimate also the extension of some additional predicates introduced by the rewriting, thus possibly making the estimate less accurate. This leads sometimes to cases in which the decomposition is preferable even when . One can try to improve the estimations, in the first place; however, an error margin will always be present. For this reason, in order to reduce the impact of such issue, we decided to experimentally test the effects of the choices under several values of the ratio, and found that decomposition is preferable when , that has also been set as a default threshold in our implementation; of course, the user can play with this at will. We plan to further improve the choice of the threshold by taking advantage from automatic and more advanced methods, such as machine learning guided techniques.
Example 5
Let us consider again our running Example 1. At the final step, three possible alternatives are evaluated: leave the rule as it is (i.e. is not decomposed), choose or choose . Since the nature of the heuristics we implemented into -DLV have the aim of optimizing the grounding process, estimations tightly depend on the instance at hand; hence, choices will possibly vary from instance to instance.
Let us assume that the current instance contains the same facts reported in Example 3. Then, the costs of instantiating or are computed according to what discussed in Section 4.2: without reporting all intermediate calculations, we have , while . In this case, the best decomposition is obviously , and it is compared with the option of grounding as non-decomposed. Again, without reporting all intermediate calculations, we have that the cost of grounding amounts to ; hence, the ratio is computed as , and, given that it is greater than , we prefer to substitute the original rule with the decomposition (see discussion above).
Interestingly, with a different input instance, things might change. For instance, if the set of input facts for changed to , the decomposition would be preferred.
4.4 Fine-Tuning and Further Implementation Issues
In order to implement the SmartDecomposition algorithm, one might rely on lpopt in order to obtain a rule decomposition for each rule in the program; in particular, this would lead to a straightforward implementation of ToHypergraph and ToRules, the functions that convert a rule into a hypergraph and a tree decomposition into a rule decomposition, respectively. Nevertheless, in order to better take advantage from the features of -DLV and do not interfere with its existing optimizations, we designed ad-hoc versions for such functions.
For instance, -DLV supports the whole language, which contains advanced constructs like aggregates, choice rules and queries; our implementation, even if resembling the one of lpopt, introduces custom extensions explicitly tailored to -DLV optimizations, and some updates in the way the aforementioned linguistic extensions are handled. It is worth noting that, when dealing with rules containing aggregate literals or choice atoms [Calimeri et al. (2013)], -DLV rewrites them: briefly, each conjunction of literals in aggregate and/or choice elements is replaced by a fresh atom, and an auxiliary rule is added to preserve semantics; this ensures more efficiency and transparency with respect to -DLV grounding machinery and its native optimization techniques. As a result, the SmartDecomposition algorithm, that takes place after such rewritings, does not need to explicitly take care of internal conjunctions of aggregates or choice constructs; on the contrary, lpopt possibly decomposes also such internal conjunctions.
Differently from lpopt, -DLV explicitly handles queries, and employs the magic sets rewriting technique [Alviano et al. (2012)] to boost query answering; in our approach, SmartDecomposition is applied after the magic rewriting has occurred, so that decompositions is applied also to resulting magic rules. In addition, given that -DLV performs other rewritings on the input rules for optimization purposes, the function ToRules is in charge of performing such already existing rewriting tasks also on the rules resulting from the decompositions.
Another relevant issue is related to the safety of the rules generated in a decomposition. Indeed, due to the abstract nature of SmartDecomposition, we cannot assume that they are safe, since this depends on the schemas selected for converting a rule into a hypergraph, and a tree decomposition into a set of rules. Hence, the ToRules function must properly take this into account, as briefly noted in Section 3. In particular, our implementation, given a rule and an associated tree decomposition , after a rule corresponding to a node in has been generated, checks its safety. If is unsafe, and is the set of unsafe variables in , an atom over a fresh predicate , that contains the variables in as terms, is added to and a new rule is generated, having as head; a set of literals binding the variables in is extracted from and added to . Interestingly, the choice of the literals to be inserted in is in general not unique, as different combinations of literals might bind the same set of variables; for instance, one might even directly add to without generating ; however, this might introduce further variables in , and alter the original join operations in it. For this reason, in our implementation we decided to still add , and while choosing a possible binding, for each variable we try to keep the number of literals taken from small, also preferring to pick positive literals with small ground extensions.
More in detail, given a variable , we look for a “standard” positive literal that binds and features as terms only variables, constants or functional terms: the rationale behind such choice is that no additional literals will be needed to guarantee the safety of itself. If more than one such literals exists, we select the one with the smallest extension size; if no one is available, we pick up the first suitable literal according to the following predefined priority order: classical literals featuring other kind of terms (such as arithmetic terms), built-in atoms and aggregate literals, respectively. Intuitively, for such literals, additional ones from may in turn be needed to ensure their safety. Interestingly, the choice of saviour literals is more careful than what it would be obtained by using lpopt as a black box, as in this case the choice could not rely on information that are available only from within the instantiation process.
The current implementation of function GenerateTreeDecompositions, which, given a hypergraph , is in charge of returning a set of tree decompositions , relies on the open-source C++ library htd [Abseher et al. (2017)]555https://github.com/mabseher/htd, an efficient and flexible library for computing customized tree and hypertree decompositions; in our implementation, we used the most recent version available at the time of writing. The library features several methods for computing tree decompositions according to different heuristics described in literature; we took advantage from this, and our implementation allows the user to deviate from the default method via a command-line option. Interestingly, the htd library features also a fitness mechanism for “ranking” decompositions according to a user-provided fitness function. In our setting, we made use of such mechanism in order to associate a cost estimation relying on Formula (1) (see Section 4.1) to a computed decomposition; hence, in the decomposition selection phase, -DLV generates a number of tree decompositions and selects the best one as the one the lowest instantiation cost, according to our criteria. This constitutes another important difference w.r.t. the approach of lpopt, that instead, makes use of the same generation tool in order to obtain just one decomposition per each rule with no evaluation at all. Obviously, handling the fitness mechanism can imply some overhead w.r.t. the choice of computing only one, unevaluated, decomposition. For this reason, in our approach decompositions are requested and evaluated one at a time and, in order to limit the impact of such phase on performance, -DLV by default stops the generation of additional tree decompositions after consecutive generations that do not show improvements in the fitness values, and never looks for more than a total of generations. These limits have been set by experimentally observing that the consecutive decompositions generated by htd present no performance improvements with higher values; however, they can be customized by means of command-line options. The selected decomposition is then compared against the original rule in order to check whether it is convenient to actually decompose or not, as described in Section 4.1.
An additional expedient to limit overheads consists in disabling the fitness mechanism in case of rules featuring very long bodies; indeed, computing multiple decompositions may be particularly costly for such rules (see Section 5). Therefore, we set a limit to body length so that, when it is exceeded, the fitness mechanism is automatically disabled and just one decomposition is generated and checked against the original rule. Again, we set a default value experimentally; by default, the limit is set to literals per body, but it can be changed by means of a command-line option. In this respect, a possible improvement of our technique, which will be subject of future work, consists in properly generating a unique, presumably “good” enough, decomposition, thus preventing the expensive production of multiple ones.
5 Experimental Evaluation
We carried out a thorough experimental activity aimed at assessing the impact of SmartDecomposition on the grounding performance of -DLV, analyzing the effectiveness of the proposed heuristics, and also at having a first glance on the effect of the produced instantiation over state-of-the-art ASP solvers. For the sake of readability, we discuss next only a significant subset of the experiments that have been carried out; additional experiments are illustrated in appendices.
5.1 Benchmarks and Results
All the experiments reported in this section and in the following have been performed on a NUMA machine equipped with two 2.8 GHz AMD Opteron 6320 and 128 GiB of main memory, running Linux Ubuntu 14.04.4 (kernel ver. 3.19.0-25). Binaries have been generated by the GNU C++ compiler 5.4.0. We allotted 15 GiB and 600 seconds to each system per each single run, as memory and time limits. Three versions of -DLV have been compared: -DLV without any decomposition, lpopt (version 2.2) combined in pipeline with -DLV (i.e., a black-box usage of lpopt), -DLV, i.e. -DLV empowered with the herein introduced version of SmartDecomposition.
As for benchmarks, we first considered the whole ASP Competition suite [Gebser et al. (2015)], the latest available at the time of writing; for each problem, the average time over the selected instances of the official Competition runs is reported; in order to produce replicable results, the random seed used by lpopt for heuristics has been set to [math] for system .
Results are reported in Table 1, showing number of grounded instances within the allotted time along with the average time spent. The symbol US in the table indicates that a configuration does not support the syntax of the encoding for corresponding domain; in particular, this happens in case of domains featuring queries, as system is not able to process them because of the lack of support for queries from lpopt.
Results of the “blind usage” of lpopt (system ) are conflicting: for instance, in some cases it enjoys a great gain w.r.t. the version of -DLV without decomposition, in particular while dealing with the Permutation Pattern Matching problem, yet showing great losses in other cases, such as Knight Tour With Holes, where instantiating rules resulting from the decomposition requires more time w.r.t. the input ones. On the other hand, from Table 1 it is easy to see that the SmartDecomposition algorithm allows -DLV to always match or overcome -DLV performances, still enjoying relevant improvements when decomposition is actually convenient (up to % in case of Permutation Pattern Matching), and avoiding negative effects of the black-box decomposition mechanism, as in the case of Knight Tour With Holes. In addition, we note also that the -DLV is able to limit the overhead w.r.t. -DLV: indeed, it is negligible even in cases where decomposition does not pay; the same does not hold for the system which suffers from the useless additional invocation of lpopt in all cases when the input program cannot be decomposed (see, e.g., Maximal Clique).
As a remark, what we expected here is that, while dealing with such benchmarks whose encodings coming from the ASP competition are already highly optimized, -DLV performed similarly to -DLV (with no decompositions) in all cases where decomposition is not convenient, and similarly to system otherwise. In order to assess this, we computed absolute and relative differences in term of times between -DLV and the best performing among the other two configurations, for each benchmark; data are reported in the two rightmost columns of Table 1. As it can be observed, apart from negligible fluctuations and with the only relevant exception consisting of Nomystery, our expectations have been met: absolute differences are close to zero, meaning that -DLV behaviour is systematically comparable with the best one among the other two. The special case of Nomystery is discussed later in this section.
An additional view of the general picture coming from this set of benchmarks is given by the plot in Figure 4, built over the same data of Table 1 except for the three domains featuring queries, that, as already mentioned, are unsupported by system . The plot allows us to appreciate the advantage granted by the decomposition rewriting, as both systems and clearly outperform system , and to note that the performance reached thanks to the SmartDecomposition algorithm are consistently better than what achieved via the unconditional use of decomposition.
Furthermore, we considered an additional set of benchmarks that have been already used in [Bichler et al. (2016b)] in order to test the efficiency of ASP-solvers paired with lpopt over challenging programs. In particular, in [Bichler et al. (2016b)], some publicly available QBF instances have been ported to ASP, according to a conversion strategy that produces programs featuring a complex structure and very long rules. This test-suite includes ASP programs, each one corresponding to a different 2-QBF instance. The results are depicted in Figure 5: the number of grounded instances is on the x-axis while running times (in seconds) are on the y-axis; the total number of successfully grounded instances per each tested configuration is reported in Table 2. First of all, we note that while dealing with these problems applying a decomposition on decomposable rules is always a good choice; indeed, when no decomposition is performed the number of grounded instances is significantly smaller and running times are higher w.r.t. configurations adopting decomposition techniques. Moreover, the heuristics guiding SmartDecomposition in -DLV work properly, estimating the decompositions as convenient, and -DLV automatically disables, internally, the fitness mechanism because the body size of rules is higher than the fixed limit, thus reducing the risk of high overheads (cf. Section 4.4). In general, lpopt |$$\cal I-DLV and -DLV enjoy similar performance, and -DLV behaves as the best performing version. Although both versions decompose the same rules, -DLV benefits from a tight integration of the decomposition mechanism into the evaluation process that allows to better interact with the other optimization strategies of -DLV and possibly lead to different choices in decompositions. Finally, on the technical side, we note that, lpopt and -DLV rely on different versions of the htd library versions.
In summary, results of experiments clearly show the effectiveness of the herein proposed approach. Some further considerations can be done about implementation and integration into a system like -DLV. Besides merely technical aspects, it is worth remembering that, as already mentioned, -DLV is packed with a large number of optimizations; this means that a rewriting-based technique such as the SmartDecomposition algorithm might have non-trivial interactions with them. Our experiments show that, in general, these interactions lead to performance gains, as it is clear while looking, for instance, at the QBF problem; nevertheless, a few isolated cases go towards different outcomes. In particular, looking at Table 1, we find that Nomystery and, even if to a smaller extent, Labyrinth, apparently benefit more from the black-box usage than from the heuristic-guided one. However, this is not the case: we investigated, and found that the reason is not related to the choices made according to the heuristics, but rather to the mentioned interaction with other internal rewritings performed by -DLV before the decomposition stage (for more details, we refer the reader to [Calimeri et al. (2017b)]); a more detailed study of such interaction will be subject of future works.
5.2 On the Effectiveness of the Heuristics
In order to better understand the actual effects on grounding performance of the SmartDecomposition algorithm as guided by the proposed heuristics, we computed some relevant statistics starting from the data obtained from experiments over all domains considered in our experimental activities, thus including, besides those described in Section 5.1, those described in Appendices; we aggregate them over specific set of instances, as described next, and report the results in a table comparing the behaviours of -DLV and -DLV. In particular, Table 3 shows two sets of data: the first refers to the whole collection of problem domains, while the second to the subset of “affected domains”, i.e., problems where significant differences on performance are reported, either positive or negative666A problem domain is here considered as “affected” if either the number of instances grounded by the two systems differ, or, in case the number is the same, difference in average grounding times between the two systems is either above or below .. The first two columns report performance of the two system configurations, respectively, while the third reports the percentage gain achieved by -DLV thanks to the SmartDecomposition algorithm.
It is easy to see that the positive impact of the technique on grounding performance, on the overall (i.e., over all problems), is significant: a hundred of additional grounded instances (%), more than % of timeouts avoided, and no more instances remain unsolved because of the excessive amount of required memory. The impact is even more evident if we consider that average times are computed only over the set of instances that are solved by both -DLV and -DLV; still, the performance gain turns out to be over %.
When we focus on the set of affected problems, the benefits of the proposed techniques are even more evident; we just note here as the gain in average grounding times, still computed only over the set of instances that are grounded by both systems, is almost %.
5.3 Impact of -DLV SD on ASP Solvers
We proved above how a smart decomposition strategy significantly improves performance of a grounder like -DLV; interestingly, such improvements on the instantiation process are relevant from many perspectives. First of all, as already mentioned in the introduction, a grounder like -DLV is actually a full-fledged deductive database system, that can profitably employed in many real-world domains for non-trivially querying knowledge bases of various nature, ranging from traditional relational to ontology-based ones. In these contexts, typically, programs to be evaluated turn out to be normal and stratified, and thus, completely solvable by a proper grounder. In all such cases, given that solving phase is not needed, each improvement on the grounding side trivially implies improvements on the whole ASP computation. In addition, the proposed technique can be of great help in all those cases where, given the nature of standard ASP evaluation strategy, the ground program can be so huge that it constitutes a bottleneck. The SmartDecomposition algorithm can be useful for mitigating this issue, allowing to actually instantiate programs that cannot be grounded without: let us think, for instance, of the 2-QBF domain discussed in Section 5.1. Furthermore, even if the proposed technique aims at improving grounding, it has a positive impact also on solving times, thus allowing to improve performance of the whole computational process. To evaluate such impact we performed an additional experimental analysis; in particular, we combined the same three versions of -DLV used in Section 5.1 with the two mainstream ASP solvers clasp [Gebser et al. (2015)] (version 5.2.1) and wasp [Alviano et al. (2015)] (version 2.1), and tested the resulting configurations over the ASP Competition benchmarks.
[FIGURE:]
Average times and number of solved instances within the allotted time are reported in Table 4, where time outs and cases of unsupported syntax are denoted by TO and US, respectively. First of all, we observe that both solvers, when coupled with -DLV, show, in general, improved performance and solve a larger number of instances, w.r.t. the configurations with -DLV; on the contrary, the “blind usage” of lpopt leads, in general, to a loss of performance for both solvers: in spite of the gain in some cases, the total number of solved instances within the suite is significantly lower. A different perspective of the results is provided by Figure 6, showing solved instances over time (in seconds), where the benefits of the proposed techniques are very clear for both tested solvers.
Improvements on the overall ASP computation observable when -DLV is used are not only caused by improvements on grounding times; indeed, there are also cases in which solving times get better even if there is no evident gain in grounding times. This is due to the fact that the rewriting causes changes in the “form” and the size of the generated instantiation, thus often inducing positive effects on the solving side. Furthermore, it can be observed that on a same domain the effects of the decomposition on the two solvers are different: in some cases, benefits enjoyed by a solver are not reported for the other one (see, for instance, Incremental Scheduling). This suggests that the heuristics guiding the smart decomposition herein proposed, that already shows a general positive impact on both mainstream solvers, could be further fine-tuned once a specific solver to be coupled to -DLV is chosen, by taking into account also its specific characteristics.
6 Conclusion
We introduced SmartDecomposition, a novel technique for automatically optimizing ASP programs by means of decomposition-guided rewritings. The algorithm is designed to be adapted to different ASP implementations; furthermore, it can be customized with heuristics of choice for discerning among possible decompositions for each input rule, and determining whether applying the selected decomposition appears to be actually a “smart” choice.
In addition, we embedded a version of SmartDecomposition in the ASP system DLV, and in particular in its grounding module -DLV. We introduced heuristics criteria for selecting decompositions that consider not only the non-ground structure of the program at hand, but also the instance it is coupled to. We experimentally tested our approach, and results are very promising: the proposed technique improves grounding performance, and highlights a positive impact, in general, also on the solving side. This is confirmed also by the results of the 7th ASP Competition [Gebser et al. (2017)]: here the winner was a system combining the version of -DLV implementing the preliminary decomposition rewriting described in [Calimeri et al. (2017a)] with an automatic solver selector [Fuscà et al. (2017)], that inductively chooses the best solver depending on some inherent features of the instantiation produced.
The -DLV system incorporating the technique herein described can be downloaded from https://github.com/DeMaCS-UNICAL/I-DLV/wiki, where a user guide is also reported addressing, among others, the options related to the techniques described in the present work.
As future work, we plan to investigate on further strategies for generating decompositions, starting from a more fine-grained analysis along existing ones. For instance, we note that current decompositions tend to split up a rule as much as possible, and in some cases this might require fresh predicates featuring significantly large extensions that could have a noticeable impact on performance; hence, given a set of bags composing a tree decomposition, one could check whether collapsing some bags produces some benefits with this respect. In addition, we also plan to take advantage from automatic and more advanced methods, such as machine learning mechanisms, in order to better tailor decomposition criteria and threshold values to the scenario at hand. Furthermore, we want to design a version of SmartDecomposition specifically geared towards solvers, with the aim of further automatically optimizing the whole ASP computational process. A starting point to this direction can be the recent work of [Bliem et al. (2017)], where it emerged that the performance of modern solvers are highly influenced by the tree-width of the input program; thus, this represents a starting point to explore the potential of our technique on the solving step.
Acknowledgements
This work has been partially supported by the Italian region Calabria under project “DLV Large Scale” (CUP J28C17000220006) POR Calabria FESR 2014–2020 and by both the European Union and the Italian Ministry of Economic Development under the project EU H2020 PON I&C 2014–2020 “Smarter Solutions in the Big Data World – S2BDW” (CUP B28I17000250008).
Appendix A Experiments on Automatic Optimization
In Section 5 we discussed the results of tests over the benchmark suite from the ASP Competition. It is worth noting that many domains have been included in several subsequent editions of the ASP Competition series; over the years, the participant teams have iteratively fine-tuned the encodings with the aim of maximizing performance of competing ASP systems. This led, in the case of Competition, to a bunch of programs that are already optimized for ASP computation, thus limiting the room for further improvements.
On the one hand, such considerations strengthen the positive results reported in Section 5; on the other hand, one might wonder about what is the impact of the SmartDecomposition algorithm when dealing with less refined encodings. We find such inquiry of interest, as it should be in the spirit of the declarative nature of ASP to allow developers to concentrate on knowledge representation rather than on low-level performance issues, that also lead, in some cases, to the production of encodings rather involved and less “human readable”. This is why, in addition to the experiments reported in Section 5, we tested our approach also on benchmarks coming from older editions of the ASP Competition series. In particular, we considered the Competition, as it is the farthest in time in which encodings comply to the input language standard.
In this set of experiments we measured grounding times of the same three versions of -DLV already taken into account in Section 5, within the same experimental environment (hardware, software, memory and time limits). Table 5 shows the results; problem names reported in italic denotes domains which are in common between the and the Competition, while those marked with a ’’ symbol feature more optimized encodings in the . As expected, in this scenario the positive impact of SmartDecomposition is even more evident: -DLV grounds a larger number of instances in a significant smaller average time. Intuitively, the less an encoding is fine-tuned, the highest are likely to be the benefits stemming from a careful automatic rewriting of input rules.
Furthermore, for all problems in common between the two ASP competitions herein considered, we tested the systems over the programs obtained by coupling the encodings featured by the with the instances featured by the , and vice-versa. This should provide us with further information about a the impact of both “manual” optimizations and the ones coming from our automatic method. Intuitively, an encoding may be optimized in different ways, and not necessarily by means of a syntactic modification of rules; for instance, one can push additional information about the domain at hand into the encoding, possibly with constraints, in order to reduce the search space. The results are reported in Table 6. It is clear that, as one can expect, the best combination is given by -DLV fed with optimized encoding coming from Competition. However, some interesting considerations can be made: indeed, in several cases (for instance, Permutation Pattern Marching, both over instances from the , and, even more, over instances from the , that appear to be harder), the smart decomposition guarantees similar or better performance improvements in grounding times that are obtained by the manual tuning.
Appendix B Additional Experiments
We report next the results of an additional experimental evaluation over a further set of benchmark. We take into account problem domains that have been already used for assessing performance of ASP systems in other works; in particular, we considered the domains Cutedge, Graph 5col, Ground Explosion 2, Reach [Weinzierl (2017)] and TimeTabling [Perri et al. (2007), Calimeri et al. (2008), Perri et al. (2013)].
Table 7 reports grounding times of the same three versions of -DLV already taken into account in Section 5, within the same experimental environment (hardware, software, memory and time limits). We first note that, regarding Reach, even if the problem domain is the same as Reachability of Section 5, both encoding and instances are different, as they are taken from [Weinzierl (2017)], and do not feature queries. In this case, where decomposition is not applicable because of the rule structure, results show that the use of SmartDecomposition, as previously noted, allows us to avoid the overhead due to the invocation of lpopt. On the overall, again, one can observe the positive impact of SmartDecomposition over grounding times, that allows significant performance improvements in case of Cutedge and TimeTabling, where -DLV times are % and % lower, respectively, w.r.t. -DLV.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1Abseher et al . (2017) Abseher, M. , Musliu, N. , and Woltran, S. 2017. htd - A free, open-source framework for (customized) tree decompositions and beyond. In Integration of AI and OR Techniques in Constraint Programming - 14th International Conference, CPAIOR 2017, Padua, Italy, June 5-8, 2017, Proceedings , D. Salvagnin and M. Lombardi, Eds. Lecture Notes in Computer Science, vol. 10335. Springer, 376–386.
- 2Alviano et al . (2017) Alviano, M. , Calimeri, F. , Dodaro, C. , Fuscà, D. , Leone, N. , Perri, S. , Ricca, F. , Veltri, P. , and Zangari, J. 2017. The ASP system DLV 2. In Logic Programming and Nonmonotonic Reasoning - 14th International Conference, LPNMR 2017, Espoo, Finland, July 3-6, 2017, Proceedings , M. Balduccini and T. Janhunen, Eds. Lecture Notes in Computer Science, vol. 10377. Springer, 215–221.
- 3Alviano et al . (2015) Alviano, M. , Dodaro, C. , Leone, N. , and Ricca, F. 2015. Advances in WASP. In Logic Programming and Nonmonotonic Reasoning - 13th International Conference, LPNMR 2015, Lexington, KY, USA, September 27-30, 2015. Proceedings , F. Calimeri, G. Ianni, and M. Truszczynski, Eds. Lecture Notes in Computer Science, vol. 9345. Springer, 40–54.
- 4Alviano et al . (2012) Alviano, M. , Faber, W. , Greco, G. , and Leone, N. 2012. Magic sets for disjunctive datalog programs. Artificial Intelligence 187 , 156–192.
- 5Ben-Eliyahu and Dechter (1994) Ben-Eliyahu, R. and Dechter, R. 1994. Propositional semantics for disjunctive logic programs. Ann. Math. Artif. Intell. 12, 1-2, 53–87.
- 6Ben-Eliyahu-Zohary and Palopoli (1997) Ben-Eliyahu-Zohary, R. and Palopoli, L. 1997. Reasoning with minimal models: Efficient algorithms and applications. Artif. Intell. 96, 2, 421–449.
- 7Bichler et al . (2016 a) Bichler, M. , Morak, M. , and Woltran, S. 2016 a. lpopt: A rule optimization tool for answer set programming. In Logic-Based Program Synthesis and Transformation - 26th International Symposium, LOPSTR 2016, Edinburgh, UK, September 6-8, 2016, Revised Selected Papers , M. V. Hermenegildo and P. López-García, Eds. Lecture Notes in Computer Science, vol. 10184. Springer, 114–130.
- 8Bichler et al . (2016 b) Bichler, M. , Morak, M. , and Woltran, S. 2016 b. The power of non-ground rules in answer set programming. Theory and Practice of Logic Programming 16, 5-6, 552–569.
