19.01.2015 Views

Constraint Logic Programming Using ECLiPSe

Constraint Logic Programming Using ECLiPSe

Constraint Logic Programming Using ECLiPSe

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

9<br />

The suspend library<br />

9.1 Introduction 155<br />

9.2 Solving CSPs and COPs using ECL i PS e 156<br />

9.3 Introducing the suspend library 157<br />

9.4 Core constraints 160<br />

9.5 User defined suspensions 167<br />

9.6 Generating CSPs 170<br />

9.7 <strong>Using</strong> the suspend library 175<br />

9.8 Summary 180<br />

9.9 Exercises 181<br />

9.1 Introduction<br />

I<br />

N THIS CHAPTER we introduce the first ECL i PS e library, called<br />

suspend. It allows us to implement constraints. This library lacks<br />

the important facility of constraint propagation (briefly mentioned in<br />

Chapter 6) and consequently is of little use for solving computationally<br />

intensive problems. On the other hand, it is used to implement all the<br />

other, more sophisticated, constraint solvers in ECL i PS e and is an excellent<br />

pedagogical tool for introducing constraints in the context of ECL i PS e .<br />

The suspend library still supports only passive constraints and as a result<br />

is only the first step towards realising constraint programming. It improves<br />

upon the computation model of Prolog by automatically preventing the occurrence<br />

of run-time errors for arithmetic constraints, by delaying them until<br />

all their variables are fully instantiated. This modified computation mechanism<br />

is provided for a larger class of constraints that also includes Boolean<br />

constraints. As we shall see, this leads to a more flexible programming style<br />

in the presence of constraints.<br />

In particular, using the suspend library we can easily generate CSPs and<br />

155

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!