1
Function Variables for Constraint Programming Brahim Hnich Computer Science Division, Department of Information Science, Uppsala University, Sweden Email:
[email protected] We introduce function variables to constraint programs (CP), variables whose values are one of (exponentially many) possible functions between two sets. Such variables are useful for modelling problems from domains such as configuration, planning, scheduling, etc. We show that a function variable can be mapped into different representations in terms of integer and set variables, and illustrate how to map constraints stated on a function variable into constraints on integer and set variables. As a result, a constraint model expressed using function variables allows for the generation of alternate CP models. Furthermore, we present an extensive theoretical comparison of models of problems involving injective functions supported by asymptotic and empirical studies. Finally, we present and evaluate a practical modelling tool that is based on a high-level language that supports function variables. The tool helps users explore different alternate CP models starting from a function model that is easy to develop, understand, and maintain. Keywords: Constraint satisfaction, constraint programming, high-level modelling, abstraction, reformulation, function variables.
1. Introduction The effective modelling of combinatorial (optimization) problems (COPs) as constraint programs is both difficult, even for application domain experts, and time-consuming. For many applications, the conceptual gap between the informal problem description and the constraint program is still large. Moreover, many of these problems are computationally intractable (NPhard) [1]. Effective modelling often requires trying alternate models and selecting a model that efficiently solves the problem, especially as there are many different ways to model these problems as a constraint program. Finally, there is a lack of support for modAI Communications 0 () 0 ISSN 0921-7126 / $8.00 , IOS Press
elling in current CP toolkits, which makes it difficult for CP to be accessible to a wider range of users than researchers working in this field and domain experts from industry. This thesis addresses the lack of support for modelling COPs as constraint programs. In particular, the thesis is focused on the tasks of alternate model generation and model selection, as well as on proposing an architecture for a high-level modelling tool that assists modelers with these two tasks.
2. Model abstraction We focus on the class of problems that can be expressed as function problems. A function problem is one where — at the problem description level of abstraction — the objective is to find one or more functions from a given set into another given set such that some constraints are satisfied. For instance, the coloring of the countries of a map such that any two neighbor countries have different colors is equivalent to finding a total function from the set of countries into the set of colors that satisfies the neighboring constraints. As a second example, scheduling jobs according to precedence constraints is equivalent to finding a bijective function from the set of jobs into the set of their positions such that the precedence constraints are satisfied. Our modelling language has proper constructs to allow the statement of function problems as shown in Figure 1. These constructs support the declaration of function variables. A function variable is a decision variable that takes a value from the set of all possible functions from a given set (source set) into another given set (target set). For example, in the map coloring problem, we can declare the function variable coloring : countries −→ colors to capture our desired objective. We also allow function operations and properties to be used to state the problem constraints. Each property is a constraint that restricts further the set of all possible values of a function variable to the
2
Brahim Hnich / Function Variables for Constraint Programming
F : V 7→ W F : V −→ W F (i) hi, ji ∈ F domain(F ) range(F ) F −1 (j) surjective(F ) injective(F ) bijective(F )
F is a partial function from V into W F is a total function from V into W function application membership the domain set of F the range set of F the inverse image of j under F F is surjective F is injective F is both injective and surjective
Fig. 1. Function declarations, function operations and properties
one where all its elements satisfy this extra property. For instance, we can state the following constraint: ∀hc1 , c2 i ∈ N · coloring(c1 ) 6= coloring(c2 ) to ensure that neighboring countries get assigned different colors, where N is the set of neighboring pairs of countries. We refer to models expressed using function variables as function models. A function model is at a higher level of abstraction than current CP models, and there is a closer correspondence between the elements of the function model and the elements of the problem description. This allows modelers to reason about problems at a suitable level of abstraction. 3. Alternate model generation Starting with a function model that is easier to develop and maintain, we propose ways of automatically generating alternate CP models. The automatic generation exploits different representations of a function variable in terms of integer and set variables, employs different constraint formulations, adds implied constraints, and combines different representations in certain ways, which results in combined models. For instance, the coloring function variable can be represented by a vector of finite domain variables, one for each element of the domain of coloring, or a set variable can be used for each element of the range of coloring. Each finite domain variable represents a country and its value is the color assigned to it, while each set variable represents a color and its value is the subset of countries it colors. Note that the constraints of the problems are translated differently depending on the choice of representation for the function variables. 4. Model selection The translation of a function model into a constraint program may result in more than one CP model. To
deal with this, we propose methods that compare these alternate models. We employ a theoretical approach — using the constraint measure proposed by Walsh [2] — that compares different models with respect to the amount of pruning achieved using different consistency techniques as well as different search algorithms. To illustrate this theoretical approach, we apply it to models of injection problems, i.e., function problems where the function to be found must be injective. We enhance the theoretical results with an asymptotic analysis of the time required to enforce the different consistency levels on the different models and empirically study three different injection problems. As a result, we can a-priori discard possible models of injection problems because we know that they will be worse than others.
5. Summary of contributions The main result of this thesis is a methodology for modelling function problems as constraint programs. First, we introduce an abstract layer composed of function variables and function operations and constraints to model function problems at a suitable level of abstraction. Second, we show how to automate the generation of alternate CP models starting from a function model. Third, with many alternate CP models at hand, we propose an analysis of the task of model selection, as well as a theoretical comparison of different models of injection problems supported by an asymptotic analysis and an empirical study. Finally, a practical modelling tool that is built based on a high-level language that allows function variables is presented and evaluated. The tool helps users explore different alternate CP models starting from a function model that is easier to develop, understand, and maintain.
Acknowledgements I wish to thank my advisors Andreas Hamfelt and Toby Walsh for their valuable guidance and support.
References [1] A.K. Mackworth. Consistency in networks of relations. Artificial Intelligence, 8(1):99–118, 1977. [2] T. Walsh. Permutation Problems and Channelling Constraints. In Proc. of the IJCAI’01 Workshop on Modelling and Solving Problems with Constraints. 2001.