Exploring alternative restoration techniques in constraint programming

74 230 0
Exploring alternative restoration techniques in constraint programming

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

... Prolog, Constraint Logic Programming (CLP) [15] In fact, most of today’s constraint programming systems are constraint logic programming sys16 Algorithm Trailing-based State Restoration Input:... search efforts, making it is possible to solve some hard problems 1.2 Constraint Programming in a Nutshell Constraint programming includes two phases: modeling and solving The modeling step is to... Chapter Constraint Programming Constraint programming systems provide the facilities to model and solve CSPs In this chapter, we briefly explain the techniques and terms that are referred to in constraint

Exploring Alternative Restoration Techniques in Constraint Programming Yong LIN (Bachelor of Engineering, Sichuan University) A THESIS SUBMITTED FOR THE DEGREE OF MASTER OF SCIENCE DEPARTMENT OF COMPUTER SCIENCE NATIONAL UNIVERSITY OF SINGAPORE 2014 Declaration I hereby declare that this thesis is my original work and it has been written by me in its entirety. I have duly acknowledged all the sources of information that have been involved in the thesis. This thesis has not been submitted for any degree in any university previously. Yong LIN 31 March 2014 ii Acknowledgements Foremost, I express my sincerest gratitude to my supervisor, Prof. Martin Henz, who has supported me throughout my study and research at National University of Singapore, for his advice, patience, enthusiasm and knowledge. I attribute the level of this thesis to his encouragement and guidance and it would not have been completed or written without him. One simply could not wish for a better or friendlier supervisor. I would like to thank the members of my thesis committee, Prof. Roland Yap and Prof. Joxan Jaffar, for their insightful comments and enlightening questions. My thanks also goes to Prof. Christian Schulte and Dr. Guido Tack for their advice on developing our techniques. I thank Srikumar Karaikudi Subramanian for initial discussions, and I thank my fellow friends for their encouragements. Meanwhile, I acknowledge the support of the School of Computing and the university for my study and research. Last but not the least, I offer my deepest appreciation to my family and relatives: LIN Xuefu, Zou Fangzhen, LIN Shiguo, LI Guangju, LIN Shiqiong, DING Daping, LIN Shibin and SHAO Fanfan, for supporting me throughout my life. iii Table of Contents 1 2 3 Introduction 2 1.1 Constraint Satisfaction Problem . . . . . . . . . . . . . . . . . . 3 1.2 Constraint Programming in a Nutshell . . . . . . . . . . . . . . . 4 1.3 The Thesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Constraint Programming 9 2.1 Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.2 Constraint-based Search . . . . . . . . . . . . . . . . . . . . . . 10 2.3 Restoration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Existing Restoration Techniques 3.1 15 Trailing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 iv 4 5 6 3.2 Copying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 3.3 Recomputation . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Recollection 22 4.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 4.2 Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 4.3 The Record Method . . . . . . . . . . . . . . . . . . . . . . . . . 24 4.4 The Restore Method . . . . . . . . . . . . . . . . . . . . . . . . 25 4.5 Variations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Programming Restoration Granularity 29 5.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 5.2 Restoration Granularities . . . . . . . . . . . . . . . . . . . . . . 31 5.3 Programmable Restoration . . . . . . . . . . . . . . . . . . . . . 32 Implementation 6.1 34 The Gecode System . . . . . . . . . . . . . . . . . . . . . . . . . 34 6.1.1 Computation Space . . . . . . . . . . . . . . . . . . . . . 35 v 6.2 6.3 7 6.1.2 Search Engine . . . . . . . . . . . . . . . . . . . . . . . 36 6.1.3 Class Edge . . . . . . . . . . . . . . . . . . . . . . . . . 37 Implementing Recollection . . . . . . . . . . . . . . . . . . . . . 38 6.2.1 Variable Access . . . . . . . . . . . . . . . . . . . . . . . 38 6.2.2 Variable Change Detection . . . . . . . . . . . . . . . . . 41 6.2.3 Memory Management . . . . . . . . . . . . . . . . . . . 42 6.2.4 Indexed Collection . . . . . . . . . . . . . . . . . . . . . 43 6.2.5 Variable Reconstruction . . . . . . . . . . . . . . . . . . 44 Programming Restoration Granularity . . . . . . . . . . . . . . . 46 6.3.1 A Prototype . . . . . . . . . . . . . . . . . . . . . . . . . 46 6.3.2 Program as an Aspect . . . . . . . . . . . . . . . . . . . . 48 Evaluation 50 7.1 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 7.2 Recomputation and Recollection . . . . . . . . . . . . . . . . . . 52 7.3 Copying and Recollection . . . . . . . . . . . . . . . . . . . . . . 54 7.4 Programming Restoration Granularity . . . . . . . . . . . . . . . 55 vi 8 Conclusion 57 vii Summary Constraint programming is a powerful tool for solving combinatorial optimization problems in many practical applications, and constraint programming systems provide the facilities to support this tool. In such a constraint programming system, search defines the strategies to explore solutions and restoration recovers a previously visited state to continue when search encounters an inconsistency. Hence, a state-of-the-art state restoration technique is essential for an efficient constraint programming system. In this thesis, we first investigate recollection as an alternative restoration technique; its main idea is to maintain the variables that were affected by constraint propagation to reason fix points for conducting restoration. Compared with the existing technique of copying, recollection exhibits a finer granularity; compared with recomputation, it avoids re-running the propagator filtering algorithms; and compared with the bottom-up restoration technique of trailing, recollection proceeds in a top-down manner and thus is suitable for systems that restore state in this manner. We implemented recollection within the Gecode system in several alternatives, which are configurable through compile time flags. Our experimental evaluation reveals that recollection is able to improve runtime against recomputation on integer problems with deep search trees and intensive propagation, at the expense of moderate memory investment. An extended comparison with copying reveals that it saves both runtime and memory for some large problems with deep search trees, and previous cross-system comparison allows us to extrapolate these results to trailing-based systems. viii Subsequently, we explore programming restoration granularity, which aims at providing strategies and facilities to enhance the customization of restoration in a constraint programming system. We initially implemented a prototype by integrating coarse-grained copying, finer-grained recollection and constraint-based recomputation, and this prototype uses the first search failure as a trigger to adjust the restoration technique. To assist the switch between restoration code segments, we explicitly employ a signal in the prototype. This approach however couples tightly with a specific program and is not quite extensible when users intend to customize. To facilitate systematic programming, we propose to program the stored restoration information as an aspect, an abstraction developed in the aspect-oriented programming paradigm. Its significance is modularizing the implementation of restoration techniques and potentially providing more options to build search engines that run a wide spectrum of search algorithms while enhancing the extensibility of the constraint programming system. ix List of Tables 5.1 Search Tree Statistics of Problem Search Trees . . . . . . . . . . 30 7.1 Benchmark Problem Search Trees Characteristics . . . . . . . . . 51 7.2 Comparison of Recomputation and Recollection . . . . . . . . . . 52 7.3 Sport and Knight run over a range of copying distances . . . . . . 53 7.4 Comparison with other restoration techniques . . . . . . . . . . . 55 7.5 Programming Restoration Granularity Evaluation . . . . . . . . . 55 x List of Figures 1.1 A Sudoku Puzzle and its Solution . . . . . . . . . . . . . . . . . 4 1.2 Gecode Script for Modeling Sudoku Puzzle . . . . . . . . . . . . 6 2.1 A Computation State Search Tree . . . . . . . . . . . . . . . . . 11 4.1 Visualization of Trailing and Recollection . . . . . . . . . . . . . 24 6.1 Introduced Virtual Methods for Class Brancher . . . . . . . . . . 39 6.2 Variable Accessing via Extra Branchers . . . . . . . . . . . . . . 40 6.3 Memory Management for Recollection . . . . . . . . . . . . . . . 42 6.4 Index-based Domain Query . . . . . . . . . . . . . . . . . . . . . 43 6.5 Integer Variable Implementation . . . . . . . . . . . . . . . . . . 44 6.6 Programming Restoration Granularity Prototype . . . . . . . . . . 47 1 Chapter 1 Introduction Combinatorial optimization problems are ubiquitous in many application domains, including scheduling, timetabling, computational biology and software verification, to name a few. These problems are generally computationally NP-hard and their solving requires considerable expertise in optimization and software engineering. The constraint satisfaction approach to combinatorial optimization emerged from artificial intelligence (such as [22] and [20]) and programming language research (such as [35] and [7]). In such an approach, solving a combinatorial problem is to specify a set of constraints to represent the solutions, and a search procedure indicates the means to explore them. Constraint programming (CP) aims at simplifying this approach by providing rich alternatives to specify constraint and search strategies, while being efficient in performance. In this chapter, we first define the constraint satisfaction problem in Section 1.1; in subsequent Section 1.2, constraint programming is briefly introduced with a 2 specific example, Sudoku and Section 1.3 specifies the main contents and organization of this thesis. 1.1 Constraint Satisfaction Problem A Constraint Satisfaction Problem (CSP) is defined by a set of variables and constraints. The variables describe the objects that the problem deals with, and each variable has a non-empty domain to specify the set of value candidates it can take. Each constraint imposes on a subset of variables to specify the allowable combinations of values for the variables. In common applications, the variables of a problem are restricted to a finite set of integers1 , and a variable is fixed when it contains a singleton domain. For a CSP, an assignment is fixing a subset of its variables and the assignment is consistent if it violates none of constraints. The process of solving a CSP is fixing its variables to consistent values, and a solution to a CSP is a consistent assignment to all variables. For an optimization CSP, it also requires the solution to maximize or minimize a cost function. Search is a complete method for solving a CSP, which guarantees that solutions can be found provided they exist. The brute-force search is such a complete approach: each possible value combination of all variables is enumerated to verify whether it is a solution to the problem. However, for such an approach, the number of possible value combinations is generally too large to enumerate all in a reasonable runtime consumption. Fortunately, the constraint programming community has developed techniques to reduce the search space: constraints are activated to 1 We restrict our discussion to such finite domain integer CSPs. 3 eliminate inconsistent values from variable domains to reach consistency, which propagates the implications to other constraints to trigger the domain shrinking of more variables. This technique can significantly reduce the amount of search efforts, making it is possible to solve some hard problems. 1.2 Constraint Programming in a Nutshell Constraint programming includes two phases: modeling and solving. The modeling step is to abstract a problem as a CSP and present it as a script, using the language/predicates provided by a constraint programming system (CPS); the solving phrase is to search for the solution(s) in the system. In this section, we employ the Sudoku problem as an example to briefly go though these two steps. 2 1 9 2 2 3 4 9 2 1 7 3 6 4 2 3 9 4 7 5 6 5 6 7 8 9 1 8 6 3 4 b d c 6 1 7 8 6 9 a 5 8 8 e f 9 g h i 3 7 8 5 9 6 1 4 2 2 6 5 8 1 4 7 3 9 9 1 4 7 3 2 5 6 8 2 1 7 8 5 4 6 3 9 3 8 6 9 7 1 5 4 2 4 5 9 6 2 3 8 7 1 7 8 5 4 6 3 9 2 1 4 2 3 1 9 7 6 5 8 1 9 6 2 8 5 3 4 7 a d g b c e f h i Figure 1.1: A Sudoku Puzzle and its Solution The Sudoku problem is a puzzle to fill a 9 by 9 matrix with values from one to nine, with the objective that values appear in each row, column and major 3 by 3 4 block are pair-wise distinct. Usually, the matrix is partially pre-filled with values to ensure a unique solution. Figure 1.1 depicts a Sudoku puzzle setting (left) and its solution (right). Modeling To model a Sudoku puzzle, we can declare each matrix entry as an integer variable, taking initial values from the integer set {1. . .9}. To enforce the rule that variables in each row, column and major block must take pair-wise distinct values, a common all-different constraint [25] can be utilized. As for problem decomposition (will explain in solving phrase), a typical strategy is first fail [13], a heuristic to take the variable with the smallest domain and then try to assign/remove one of its left values. To search for the first solution, it usually employs depth first exploration. Describing the main idea to model the Sodoku problem, it is then straightforward to write up a model script in a constraint programming system. Figure 1.2 illustrates the script for modeling Sudoku in the Gecode system [33], an open source constraint programming library developed in C++. In Gecode, a model always inherits from the class space and implements the model in its constructor. Additionally, the model must implement a copy constructor and a copy function to clone fix point computation spaces. This is because Gecode is a system that bases on copying with recomputation for state restoration. Solving The constraint programming systems solve a CSP through inference and search. The inference removes the values that cannot appear in solution from variable domains through reasoning. Let take the entry in row 1, column i ( E1i ) 5 class Sudoku : public Space { public: IntVarArray entries; /* variables for matri*/ Sudoku(const int instance[9][9]) : entries(this, 9*9, 1, 9) { Matrix m(entries, 9, 9); for (int i = 0; i < 9; i++) { distinct( this, m.row(i) ); /* constraints for rows */ distinct( this, m.col(i) ); /* constraints for columns*/ } for( int I = 0; i < 9; i +=3 ) for( int j = 0; j < 9; j += 3 ) distinct( this, m.slice( i, i+3, j, j + 3 ) ); /*constraints for major blocks*/ for( int i = 0; i < 9; i++ ) for( int j = 0; j < 9; j++ ) if( int v = instance[i][j] ) rel( this, m(i, j), IRT_EQ, v ); /* prefilled entries*/ /* Decomposition Heuristic : first fail */ Branch( this, entries, INT_VAR_SIZE_MIN, INT_VAR_SPLIT_MIN ) } Sudoku(bool share, Sudoku & s): Space(share, s) { Entries.update(this, share, s.entries); /* Constructor for cloning*/ } Virtual Space * copy(bool share) { return new Sudoku(share, *this) ; /* copying during cloning */ } }; int main(int argc, char * argv[]) { int instance[9][9] = { /* prefilled values */ } Sudoku * root = new Sudoku(instance); Sudoku * solution = DFS( root ); /* pass problem space to search engine*/ std:cout entries [...]... Warren’s abstract instruction set [37] and was implemented in Logic Programming (LP) Prolog Subsequently, Jaffar introduced constraint into logic programming and laid the foundation for a successor of Prolog, Constraint Logic Programming (CLP) [15] In fact, most of today’s constraint programming systems are constraint logic programming sys16 Algorithm 2 Trailing-based State Restoration Input: State S,... CSPs In this chapter, we briefly explain the techniques and terms that are referred to in constraint programming and its systems 2.1 Basics A constraint programming system implements variables and constraints for modeling CSPs, and it provides facilities to solve the modeled problem For a CSP in a constraint programming system, the conjunction of its variables form a store to map their domains; each constraint. .. efforts, making it is possible to solve some hard problems 1.2 Constraint Programming in a Nutshell Constraint programming includes two phases: modeling and solving The modeling step is to abstract a problem as a CSP and present it as a script, using the language/predicates provided by a constraint programming system (CPS); the solving phrase is to search for the solution(s) in the system In this section,... domain {4, 8} and then try the other alternative (remove 8 from E1i domain) This task is fulfilled by state restoration (restoration for short) in a constraint programming system Intuitively, the restoration can be accomplished by memorizing the whole puzzle setting or undoing the performed reasoning effects etc Actually, various state restoration 7 techniques have been developed for building constraint. .. programming (CP) aims at simplifying this approach by providing rich alternatives to specify constraint and search strategies, while being efficient in performance In this chapter, we first define the constraint satisfaction problem in Section 1.1; in subsequent Section 1.2, constraint programming is briefly introduced with a 2 specific example, Sudoku and Section 1.3 specifies the main contents and organization... provided by state restoration (restoration for short) in a constraint programming system For restoration, one key step is to decide the state to restore since an intelligent decision is able to skip the subtrees where solutions cannot exist, and this is essential for a constraint programming system to solve problems efficiently Intelligent backtracking has been intensively investigated, and prominent algorithms... enumerate all in a reasonable runtime consumption Fortunately, the constraint programming community has developed techniques to reduce the search space: constraints are activated to 1 We restrict our discussion to such finite domain integer CSPs 3 eliminate inconsistent values from variable domains to reach consistency, which propagates the implications to other constraints to trigger the domain shrinking of... state restoration techniques are reviewed in Chapter 3; Chapter 4 and Chapter 5 respectively presents the idea of recollection and programming restoration granularity; Chapter 6 intensively explains the implementation issues of our developed techniques and empirical evaluation is placed in Chapter 7; lastly, Chapter 8 concludes this thesis 8 Chapter 2 Constraint Programming Constraint programming systems... first exploration Describing the main idea to model the Sodoku problem, it is then straightforward to write up a model script in a constraint programming system Figure 1.2 illustrates the script for modeling Sudoku in the Gecode system [33], an open source constraint programming library developed in C++ In Gecode, a model always inherits from the class space and implements the model in its constructor Additionally,... software engineering The constraint satisfaction approach to combinatorial optimization emerged from artificial intelligence (such as [22] and [20]) and programming language research (such as [35] and [7]) In such an approach, solving a combinatorial problem is to specify a set of constraints to represent the solutions, and a search procedure indicates the means to explore them Constraint programming (CP)

Ngày đăng: 30/09/2015, 10:11

Mục lục

  • Introduction

    • Constraint Satisfaction Problem

    • Constraint Programming in a Nutshell

    • The Thesis

    • Constraint Programming

      • Basics

      • Constraint-based Search

      • Restoration

      • Existing Restoration Techniques

        • Trailing

        • Copying

        • Recomputation

        • Recollection

          • Motivation

          • Characteristics

          • The Record Method

          • The Restore Method

          • Variations

          • Programming Restoration Granularity

            • Motivation

            • Restoration Granularities

            • Programmable Restoration

            • Implementation

              • The Gecode System

                • Computation Space

                • Search Engine

                • Class Edge

Tài liệu cùng người dùng

Tài liệu liên quan