MENTAL
 Main Menu
 Applications
 Computer Science
 Constraint Oriented Programming


Constraint Oriented Programming
 CONSTRAINT
ORIENTED
PROGRAMMING

"A world without constraints would be totally chaotic". "That something is predictable implies that a constraint exists." "Every law of nature is a constraint" (William Ross Ashby).

"Laws describe constraints; they do not create." "The universe is based on freedom. Laws, restrictions on freedom, are secondary" (Arthur M. Young).



Constraint Oriented System

In a constraint-oriented system, the user defines (by means of a specific language) the solution space of a problem, supplies the constraints that exist and specifies the type of solution sought. The system, automatically, by means of a search engine, tries to find the solution.

In theory, such a system approaches the ideal of automatic programming, since it uses purely declarative programming and frees the programmer from having to develop a search algorithm for each problem. But there are difficulties in practice: But the constraint paradigm also provides advantages:
Specification in MENTAL

With MENTAL no particular language is needed to specify a Constraint Oriented System. The language's own resources are sufficient.

A typical problem of Constraint-Oriented Programming consists of finding the values of a series of unknown variables that must satisfy a series of conditions (constraints) that must be satisfied at the same time. In the case that the conditional expression is very extensive, representations (potential substitutions) can be used to improve comprehension.


Example

A classic example is the "8 queens problem". Proposed by the chess player Max Bezzel in 1848, it involves finding a position on the chessboard with the following restrictions: 1) there are only 8 queens on the board, and 2) no queen can attack another queen.

One of the solutions to the
8 queens problem

There are 92 possible solutions, of which 12 are essentially distinct, since the rest are obtained by symmetries, rotations and translations.

This problem (which is NP-Complete) interested mathematicians like Gauss and Cantor, who generalized it to n queens on a board of n×n squares.

Numbering the rows from bottom-up, and the columns from left to right, and representing the positions of the queens by the sequence (i1 … i8), where ij is the column occupied by the queen of row j, the solution expression, together with the constraints, is as follows: One solution (the one indicated in the image) is: (2 4 5 8 3 1 7 5). Its generalization for n queens is: This problem has no solution for n=2 and n=3.

For n=4 has only one solution: (2 4 1 3).

The only solution to the
problem of the 4 queens

To improve understanding, we can use auxiliary expressions. For example: And the general expression would be:

Addenda

A little history
Bibliography