next up previous contents
Next: Why Logic Programming Up: ECLiPSe as a Modelling Previous: ECLiPSe as a Modelling

Overview of ECLiPSe as a Modelling Language

ECLiPSe is tailored for solving combinatorial problems. Such problems are characterised by a set of decisions which have to be made (where each decision has a set of alternative choices) and a set of constraints between the decisions (so a certain choice for one decision may preclude, or entail, certain choices for other decisions).

In ECLiPSe each decision is modelled by a variable, and each choice by a possible value for that variable. The constraints are modelled by relations between the variables. As an example consider the map colouring program, with four countries to colour.

:- lib(apply_macros).

coloured(Countries) :-
    Countries = [A,B,C,D],
    ne(A,B), ne(A,C), ne(A,D), ne(B,C), ne(B,D), ne(C,D).

A Generic Logic Program for Map Colouring  

This program was also used to illustrate constraint logic programming in [Wal97]. ECLiPSe is a constraint logic programming language, and it uses the same syntax as Prolog. Hopefully this syntax will already be familiar to many readers. At the same time, we also hope that any readers who have suffered from the limitations of Prolog will not conclude that ECLiPSe therefore suffers from the same limitations!

The problem involves four decisions, one for each country. These are modelled by the variables A, B, C and D. Countries is just a name for the list of four variables. Each decision variable, in this problem, has the same set of choices, modelled as possible values for the variables (red, green and blue). There are six constraints, each of which is modelled by the same relation (ne meaning not equal to).

The first command :- lib(apply_macros). loads an ECLiPSe library. Much of the functionality of ECLiPSe is held in different libraries, some of which will be introduced in the next section. The library apply_macros holds the definition of the applist predicate, which applies a predicate to each element of a list. applist(value,Countries) is equivalent to value(A), value(B), value(C), value(D).

next up previous contents
Next: Why Logic Programming Up: ECLiPSe as a Modelling Previous: ECLiPSe as a Modelling

Joachim Schimpf
Wed Sep 3 18:07:19 BST 1997