11. Información institucional 35
11.4. Miembros del Instituto de Matemáticas
Constraint programming is a successful technology for tackling a wide variety of combinatorial problems in disparate fields, such as scheduling, industrial design, and combinatorial mathe-matics [178]. To use constraint technology to solve a constraint satisfaction problem (CSP), its solutions must first be characterised, or modelled, by a set of constraints on a set of decision variables. To solve the problem, the constraint solver will attempt to assign values to each of
the variables such that the constraints are all satisfied. Often, in addition to constraints on the variables, the user can specify a function which the solver will seek to maximise in order to favour particular solutions from a set of many possible solutions. Figure 2.6 shows a classic verbal arithmetic puzzle which can be solved by a constraint solver [78].
S E N D
+ M O R E
M O N E Y
Figure 2.6: The “send more money” verbal arithmetic puzzle.
In this problem, the idea is to replace the letters with digits from 0 to 9 such that the addition is satisfied. Different values should be used for each letter and the first digits of each line should be non-zero. The puzzle can be modelled for solving by the Minion constraint solver [100] as shown in figure 2.7.
Figure 2.7: A Minion model for the “send more money” puzzle.
The Minion model defines each of the unique letters in the puzzle as a decision variables. They are defined as integers by the “DISCRETE” keyword and followed by the range of values they
2.4. Automated Reasoning Fields 27
are able to take, which is between 0 and 9 except for the non-zero starting letters. The range is also known as the variable’s domain. The first of the constraints states that the variables should all be given unique values. The weightedsum constraints enforce the addition, which is
1,000*S + 100*E + 10*N + D + 1,000*M + 100*O + 10*R + E = 10,000*M + 1,000*O + 100*N + 10*E + Y
The syntax of weightedsumgeq means that each of the elements of the first list is multiplied by the elements of the second list and summed, with the sum being constrained to be greater or equal to the third parameter. Note that the required constraint is that this sum is equal to zero, however, Minion syntax does not provide a simpler way of enforcing this. Figure 2.8 shows the solution to the “Send More Money” problem.
# Minion Version 0.6.0
Figure 2.8: Minion’s solution to the “send more money” problem.
In order to find a solution to a problem, constraint solvers use a combination of propagation and search. Propagation refers to considering how a particular constraint affects the domains
of the variables. Search is employed to consider possible assignments of values to the variables in turn. For example, figure 2.9 shows a simple constraint problem with two variables A and B, where B is constrained to be at least one greater than A.
DISCRETE A{1..5}
DISCRETE B{1..5}
sumgeq(A,1,B)
Figure 2.9: A simple constraint problem extract.
When the solver starts, it propagates the constraint by considering the domain of A. It knows, that B could never take the value of 1 and so removes this from the domain of B. Similarly, it removes the value 5 from the domain of A. By doing this it no longer has to consider these value assignments during search. The solver also propagates constraints during search. For example, if it is considering a value of 3 for A then, by propagating the constraint, it can remove the values 1-3 from the domain of B. Many constraint solvers exist. We have used Minion and the CLPFD constraint solver [41] that forms part of the SICStus Prolog distribution [165] in our projects. Other constraint solvers include Choco [119], Mistral [105], Abscon [135]
and the commercial ILOG Solver [111]. They all differ in terms of implementation and the syntax they use for declaring constraints. For example, figure 2.10 shows the earlier example constraint problem expressed in CLPFD syntax.
:- use module(library(clpfd)).
mm([S,E,N,D,M,O,R,Y], Type)
:-domain([S,E,N,D,M,O,R,Y], 0, 9), S #>0, M #>0,
all different([S,E,N,D,M,O,R,Y]), sum(S,E,N,D,M,O,R,Y),
labeling(Type, [S,E,N,D,M,O,R,Y]).
sum(S, E, N, D, M, O, R, Y) :-1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E
#= 10000*M + 1000*O + 100*N + 10*E + Y.
Figure 2.10: The “send more money” problem in CLPFD syntax.
2.4. Automated Reasoning Fields 29
Finite Algebraic Structures
One common problem domain for CSP solving is the mathematical area of finite algebraic structures. An algebraic structure is a set of elements together with one or more operators, which are closed. A closed operator is one whose result is also a member of the set of elements of the algebraic structure. Finite algebraic structures, or finite algebras, are distinct from infinite algebras in that they have a finite number of elements. They can be represented by a table which gives the result of the operator for each pair of elements. Figure 2.11 shows an example of a size 4 finite algebra. Here, the operator is shown as · and the result of n · m is given at the intersection of row n and column m, for example 2· 1 = 0 and 0 · 3 = 2.
Figure 2.11: A finite algebraic structure of size 4.
There are many families of finite algebras, which differ in the number of operators and the axioms to which they conform. For example, magmas are a finite algebra family having one closed operator and no axioms. We could, therefore, create a valid magma by placing the numbers 0 to 3 in any way we choose in the table of figure 2.11. Another family is quasigroups, which have the axiom ∀ a b ∃ c d (a · c = b ∧ d · a = b), which means that all elements must appear in each row and column, i.e., the table must be a Latin Square. There are several subtypes of quasigroup, each with additional axioms, e.g. QG3 quasigroups also satisfy the axiom ∀ a b (a · b) · (b · a) = a. Groups are another, more complex, family of single-operator algebras. The axioms of groups are associativity (∀ a b c (a · b) · c = a · (b · c)), identity (∃ e ∀ a (a · e = e · a = a)) and inverse (∀ a ∃ b (a · b = b · a = e)). The integers are an infinite group where the operator is addition. These algebraic structures form an interesting testbed for constraint solving. A constraint solver can be used to find an example of an algebraic structure by encoding the operator table as variables and posting constraints to represent the axioms.
For example, quasigroups can be found by considering a table of n2 variables with possible values of 0 to n− 1 and constraining the variables of each row and column to be all different.
In this document, we often use the shorthand algebra to refer to algebraic structures.