Download FaCiLe - La Recherche
Transcript
Chapter 1 Getting Started This first chapter introduces the overall framework of FaCiLe and gives a preliminary insight about its programming environment and functionalities. OCaml code using FaCiLe facilities (file csp.ml in the following example) must be compiled with the library of object byte code facile.cma when batch compiling with ocamlc: ocamlc -I +facile facile.cma csp.ml and with the library of object code facile.cmxa for native compilation with ocamlopt: ocamlopt -I +facile facile.cmxa csp.ml provided that the standard installation of FaCiLe (and previously of the OCaml system of course) has been performed (see p. vi) and that the facile.cm[x]a files have been successfully created in the OCaml standard library directory. For larger programs, a generic Makefile can be found in directory examples (see p. vii). It may however be convenient to use an OCaml custom toplevel to experiment toy examples or check small piece of serious (thus larger) code. A FaCiLe toplevel (i.e. in which facile.cma is pre-loaded) is easily built with the following command: ocamlmktop -o facile -I +facile facile.cma and invoked with: ./facile -I +facile The two following sections give a quick overview of the main basic concepts of FaCiLe with the help of two very simple examples which are explained step by step. 1.1 Basics We first give a slight taste of FaCiLe with the recurrent trivial problem of the Canadian flag: one has to repaint the Canadian flag (shown in figure 1.1) with its two original colors, red and white, so that two neighbouring areas don’t have the same color and the maple leaf is red of course. The CSP model is desperately straightforward: • one variable for each area l, c, r and m; • all variables have the same domain [0..1], 0 being red and 1, white; • one difference constraint for each adjacence l 6= c, c 6= r, m 6= c and the maple leaf is forced to be red m = 0. The following piece of code solves this problem: 3