• Aucun résultat trouvé

Languages and Model Transformation in Constraint Programming

N/A
N/A
Protected

Academic year: 2021

Partager "Languages and Model Transformation in Constraint Programming"

Copied!
177
0
0

Texte intégral

(1)

HAL Id: tel-00483262

https://tel.archives-ouvertes.fr/tel-00483262

Submitted on 13 May 2010

HAL is a multi-disciplinary open access

archive for the deposit and dissemination of

sci-entific research documents, whether they are

pub-lished or not. The documents may come from

teaching and research institutions in France or

abroad, or from public or private research centers.

L’archive ouverte pluridisciplinaire HAL, est

destinée au dépôt et à la diffusion de documents

scientifiques de niveau recherche, publiés ou non,

émanant des établissements d’enseignement et de

recherche français ou étrangers, des laboratoires

publics ou privés.

Programming

Ricardo Soto

To cite this version:

Ricardo Soto. Languages and Model Transformation in Constraint Programming. Other [cs.OH].

Université de Nantes, 2009. English. �tel-00483262�

(2)

Année 

É

COLE

D

OCTORALE STIM

« S

CIENCES ET

T

ECHNOLOGIES DE L

’I

NFORMATION ET DES

M

ATÉRIAUX

»

N

o

attribué par la bibliothèque

Langages et transformation de modèles en

programmation par contraintes

T

HÈSE DE

D

OCTORAT

Discipline : I

NFORMATIQUE

Présentée

et soutenue publiquement par

Ricardo S

OTO

le 25 juin 2009 à l’

UFR

Sciences & Techniques, Université de Nantes,

devant le jury ci-dessous

Président : Éri Monfroy,Professeur UTFSM,Chili

Rapporteurs : FrançoisFages, Dire teur deRe her he INRIARo quen ourt, Fran e

Mi helRueher, Professeur Universitéde Ni e,Fran e

Examinateurs: Arnaud Lallouet,Professeur Universitéde Caen,Fran e

Éri Monfroy,Professeur UTFSM,Chili

Directeur de thèse : Pr. Laurent G

RANVILLIERS

Laboratoire : L

ABORATOIRE D

’I

NFORMATIQUE DE

N

ANTES

A

TLANTIQUE

.

(3)
(4)

favet neptunus eunti

Languages and Model Transformation in Constraint

Programming

Ri ardo Soto

⊲⊳

(5)

ontraintes

xviii

+

154p.

This do ument was edited with these-LINA v. 2.7 L AT

E

X2e lass of the

As-so iation of Young Resear hers on Computer S ien e (L o

G I

N) from the

UniversityofNantes(availableat:http://login.i rin .s i en e s. uni v-na nt es .f r/). This LAT

E

X2e lass is under the re ommendations of the

Natio-nal Edu ation Ministry of Undergraduate and Graduate Studies

( ir ulairen o

05-094du



Mar h



) of the UniversityofNantes and the Do toralS hoolofTe hnologiesdel'InformationetdesMatériaux(ed-stim)

(6)

guages with e ient solving engines. It ombines methods from dierent domains su h as

arti ialintelligen e,mathemati al programming,andgraphtheory.Amain hallengeinthis

eld is to provide high-level languages for fa ilitating the problemmodeling phase. Another

important on ern isto design robustar hite tures tomaphigh-levelinput models to

dier-ent ande ient solving models.Handling these two on erns isremarkably hard sin emany

aspe ts have to be investigated,for instan e, the expressiveness and theabstra tion levelof

the language as well as the te hniques used to transform the high-level model into ea h of

the solver's languages. In this thesis, we proposea new perspe tive to fa ethose hallenges.

We introdu e a novel onstraint programming ar hite ture in whi h the problem is seen as

a set ofhigh-level onstrained obje tsdened througha newmodeling language. Themodel

transformationisperformedbyamodel-drivenpro essinwhi htheelementsoflanguagesare

dened as on eptsof amodelofmodels alledmetamodel. Thisnewar hite ture allowsone

to ta kle the modeling and the modeltransformation phases in a higher-level of abstra tion

and onsequently toredu e theinherent omplexitybehindthem.

Keywords: Constraint Programming, Constraint Modeling Languages,ModelTransformation

Résumé

La programmation par ontraintes est une te hnologie pour l'optimisation qui asso ie des

langages de modélisation ri hes ave des moteurs de résolution e a es. Elle ombine des

te hniquesde plusieurs domaines tels quel'intelligen e arti ielle, laprogrammation

mathé-matique et la théorie des graphes. Un dé majeur dans e domaine on erne la dénition

de langages de haut-niveau pour fa iliter la phase de modélisation des problèmes. Un autre

aspe t important est de on evoir des ar hite tures robustes pour transformer des modèles

de haut-niveau etobtenir desmodèles exé utablese a es, touten visant plusieursmoteurs

de résolution. Répondreà esdeuxpréo upations esttrèsdi ile, ardenombreux aspe ts

doivent êtrepris en ompte, omme parexemple, l'expressivité etleniveau d'abstra tiondu

langage ainsiqueleste hniquesutilisées pour traduirelemodèledehaut-niveau dans ha un

des langages de résolution. Dans ette thèse, nous proposons une nouvelle perspe tive pour

faire fa eà esdés.Nousintroduisonsune nouvellear hite ture pour laprogrammation par

ontraintes danslaquellele problèmeest déni ommeun ensembled'objets ontraints dans

un nouveau langage demodélisationhaut-niveau.La transformation desmodèlesest réalisée

àl'aidedel'ingénieriedesmodèles.Lesélémentsdeslangagessontalors onsidérés ommedes

on epts dénis dansunmodèlede modèles appelémétamodèle. Cettenouvelle ar hite ture

permetd'aborder lesphases de modélisation etde transformation de modèles en raisonnant

à un niveau d'abstra tion supérieuret, par onséquent, de réduirela omplexité inhérenteà

es deuxphases.

Mots- lés: Programmation par ontraintes, Langages de modélisation par ontraintes, T

rans-formation de modèles

a m Classi ation

Categories and Subje t Des riptors : D.3.2 [Programming Languages℄: Language

Classi ationsConstraint and logi languages; D.3.3 [Programming Languages℄:

(7)
(8)
(9)
(10)

Engi-Remerciements

J

e tiens tout d'abord à remer ier vivement mon dire teur de thèse Laurent Granvilliers

pour saqualité humaine, sadisponibilité etsonénergiedébordante toutau long demes

travaux de thèse de do torat. Pendant es trois années, j'ai eu le plaisir de rédiger plusieurs

arti les ave lui, de proter de sa rigueur s ientique et de son appré iation obje tive. Cela a

ainsiété trèsenri hissant aussibienpersonnellement queprofessionnellement.

Jesouhaiteaussiexprimertoutemagratitudeenverslesmembresdemonjury,enparti ulier

Éri Monfroy pour l'avoir présidé; Mi helRueher etFrançoisFages, rapporteurs, pour avoir lu

mon manus rit ave soin et fait des remarques pertinentes. Un grand mer i à Arnaud Lallouet

pour sesquestionsqui m'ontaidé àorientermes futurs travauxde re her he.

J'adresseaussimes sin ères remer iements auxmembres du département d'informatiquede

l'Université Ponti ale Catholiquede Valparaíso.Je remer ie parti ulièrement Broderi k

Craw-ford, Éri MonfroyetCarlosCastro quiont fortement ontribuéà mavenueen Fran e. Je tiens

aussià remer ierJaime Zavalapoursonaide pré ieuse danslapréparationde monséjour.

Jevoudraiségalementremer ierRaphaëlChenouardpournosé hangesfru tueux.Nos

ontri-butions sont naturellement présentées dans e manus rit. En plus d'être un ami, il m'a aidé et

soutenu sansrelâ he toutau longdema thèse.

Denombreusesautrespersonnesont ontribuéàfaire esannéesdethèseàNantesunepériode

agréable.Anthony,Eduardo,Jim,gra ias pour votreamitié,votredisponibilitéetvotresoutien.

Thomas etNi o,mer i pour votre aideetpour esinnombrables onversations fru tueuses. Les

membrespermanentsdel'équipeMEOduLINAontégalement toutemagratitude:Christophe,

Fred etAlex,mer i. CharlotteetLorrainemer i aussipour votre amitiéetvotre amabilité.

Jetiens aussiàremer iermesamispro hes:Stéphane, Angel,Wen e, Denisse,mer iàvous

pour tous es moments agréables qu'on a vé u en Fran e. Je remer ie aussi mes amis du Chili

qui m'ont toujours soutenu malgré la distan e : Alfredo, Negro, Pato et Andrés, je vous serre

dansmes bras.

J'adresse une pensée à ma famille, Papa, Maman, Xime et Vero, mer i pour votre énorme

soutienet eslongues onversationstéléphoniques.Jeremer ieaussimesbeaux-parentspourleur

soutienetleurs nombreuses visitesqui ont rendunotre séjouren Fran e en oreplus plaisant.

Enn, omment ne pasremer ier mafemme sans qui rienn'aurait été possible.Tu sais que

ton appuiin onditionnel, tesen ouragements etton amourontétélemoteur pour menerà bien

estroisduresannéesdethèse.Tous esmomentsdi ilesqu'onavé u ensembleetlafor eque

t'aeu pour yfairefa e, tusais 'estadmirable.Stefanie,en ore unefoisjeteremer ie,jet'aime

(11)
(12)

Table of Contents

List of Tables xiii

List of Figures xv

Body of the Dissertation

1 Introdu tion 1

1.1 Fromthe Rootsof CPto ModernAr hite tures . . . 2

1.2 Motivations &Contributions . . . 3

1.3 Outline . . . 6

Part I  State-of-the-art 2 Solving Te hniques 9 2.1 Constraint Satisfa tionProblems . . . 9

2.2 SolvingCSPs . . . 9

2.2.1 Basi Sear hAlgorithms . . . 10

2.2.2 Filtering te hniques . . . 11

2.2.3 Solving Algorithms . . . 12

2.2.4 Solving numeri al CSPs . . . 14

2.2.5 Variable andValueOrdering Heuristi s . . . 18

2.3 Summary . . . 18

3 Languages and Systems 19 3.1 Constraint Logi Programming . . . 19

3.2 Libraries . . . 21

3.3 Modeling Languages . . . 23

3.4 Programming Languages . . . 28

3.5 Mathemati alProgramming . . . 29

3.6 Obje t-orientedlanguages . . . 31

3.7 Comparing s-COMMAwith relatedapproa hes . . . 34

3.8 Summary . . . 35

Part II  The s-COMMA platform 4 Modeling Language & Graphi al Artifa ts 39 4.1 ATour ofthe s-COMMA language . . . 39

4.1.1 The SEND+MORE=MONEY Problem . . . 39

(13)

4.1.3 TheStable MarriageProblem . . . 44

4.1.4 TheSo ial Golfers Problem . . . 46

4.1.5 TheProdu tion Problem . . . 48

4.1.6 TheEngine Problem . . . 49

4.2 Modeling Features . . . 51 4.2.1 Constants . . . 51 4.2.2 Variableassignments . . . 52 4.2.3 Classes . . . 53 4.2.4 Attributes . . . 54 4.2.5 Constraint Zones . . . 56

4.2.6 Heuristi Orderings &Consisten yTe hniques . . . 60

4.2.7 Extensibility . . . 63

4.3 The s-COMMAGUI . . . 67

4.4 Summary . . . 71

5 Mapping Models to Solvers 73 5.1 From s-COMMA GUIto s-COMMA . . . 74

5.2 From s-COMMA toFlats-COMMA . . . 77

5.2.1 Parsing . . . 77

5.2.2 Semanti Che king . . . 83

5.2.3 Refa toringPhase . . . 87

5.3 From Flats-COMMA tosolvers. . . 92

5.3.1 Hand-WrittenTranslators . . . 92

5.3.2 Model-Driven Translators . . . 98

5.3.3 Dis ussion. . . 107

5.4 Summary . . . 109

Part III  The Transformation Framework for CP 6 Overview 113 6.1 The Model-DrivenTransformationFramework. . . 113

6.2 A Motivating Example . . . 114

6.3 Summary . . . 117

7 From Sour e to Target 119 7.1 From sour e to pivot . . . 119

7.2 Pivot refa toring . . . 122

7.2.1 Refa toringphase . . . 122

7.3 From pivot to target . . . 127

7.4 Transformation pro ess . . . 129

7.4.1 Sele ting the refa toringsteps. . . 129

7.5 Experiments. . . 130

7.6 Summary . . . 131

(14)

8.2 Transformation framework forCP languages. . . 134

8.3 Futureresear hdire tions . . . 134

Appendixes

A Grammars 139

A.1 s-COMMAGrammar. . . 139

A.2 Flats-COMMAGrammar . . . 142

Bibliography 145

(15)
(16)

List of Tables

Body of the Dissertation

Part I  State-of-the-art

3.1 Comparing s-COMMA with ve approa hes. The meaning of ea h row is as follows.

Obje t-Orientation: the language provides obje t-oriented apabilities. GUI: the

system oers a graphi al interfa e. Solver-Independen e: thear hite ture is able

to perform the problem resolution through dierent solvers. Mapping tool: the

system provides a framework to add new solvers to the platform. Extensibility:

the language an be extended for instan e to support new global onstraints or

fun tions. Solving Options: the denitionof heuristi sorderings and onsisten y

levels of onstraintsareallowed. . . 34

Part II  The s-COMMA platform

4.1 Binary and unary operators. Higher pre eden e means lower priority.

T

represents

integer,real,or booleantypes.

N

representsinteger or real types. . . 57

5.1 Translation times (se onds). . . 108

5.2 Solvingtimes (se onds)and modelsizes(numberof tokens). . . 109

Part III  The Transformation Framework for CP

7.1 Times of omplete transformation hains. . . 131

7.2 Timeof ompletetransformation hains ofthe n-queens problem. . . 131

(17)
(18)

List of Figures

Body of the Dissertation

1.1 Asolution ofthe 8-queensproblem.. . . 1

1.2 Thetransformation pro ess ins-COMMA. . . 4

1.3 Thetransformation framework for CP. . . 5

Part I  State-of-the-art 2.1 Solvingthe 4-queens problemusingGT. . . 10

2.2 Solvingthe 4-queens problemusingBT. . . 11

2.3 Enfor ing ar onsisten y. . . 12

2.4 Solvingthe 4-queens problemusingFC. . . 13

2.5 Solvingthe 4-queens problemusingMAC. . . 13

2.6 Enfor ing hull onsisten y. . . 16

2.7 TheCSP

P = hhxi, hD

x

∈ [−2, 2]i, hx

2

< 2ii

.. . . 17

2.8 Enfor ing box onsisten y. . . 17

3.1 AnECL

i

PS

e

modelofthe n-queensproblem. . . 21

3.2 AGe ode/Jmodel ofthe n-queens problem. . . 24

3.3 AGe ode/Jmodel ofthe n-queens problemusingglobal onstraints. . . 25

3.4 AMiniZin modelofthe n-queens problem. . . 28

3.5 AnAlma-0 modelof then-queensproblem. . . 30

3.6 AnAMPL modelof the n-queensproblem.. . . 31

3.7 As-COMMA modelof the n-queensproblem. . . 34

Part II  The s-COMMA platform 4.1 As-COMMA modelof the ryptarithmeti puzzle

SEN D + M ORE = M ON EY

. . . 40

4.2 As-COMMA modelof thepa king squaresproblem. . . 41

4.3 Anobje t-orienteds-COMMA model ofthe pa king squaresproblem. . . 43

4.4 Dataleof the stablemarriage problem. . . 44

4.5 As-COMMA modelof thestablemarriage problem. . . 45

4.6 Dataleof theso ial golfersproblem. . . 46

4.7 Modelle ofthe so ial golfersproblem. . . 47

4.8 As-COMMA modelof theprodu tion problem. . . 48

4.9 Dataleof theprodu tion problem. . . 49

4.10 TheEngine Problem.. . . 49

4.11 As-COMMA modelof theengine problem. . . 50

(19)

4.13 The Inje tion lassof theenginemodel. . . 51

4.14 Constants. . . 52

4.15 Variableassignments. . . 52

4.16 Variableassignments guidedby indexes. . . 52

4.17 Composition andinheritan e. . . 53

4.18 Importing models. . . 53

4.19 De ision variables. . . 54

4.20 De ision variables,domainsand enumerateddomains. . . 54

4.21 Sets. . . 55

4.22 Obje tsand onstrained obje ts. . . 55

4.23 A onstraint zone. . . 56

4.24 Constraint zoneoverriding. . . 56

4.25 forallloops. . . 58

4.26 Nested forallloops. . . 58

4.27 The sumloop. . . 58

4.28 Conditionals. . . 59

4.29 Optimization statement. . . 59

4.30 A ompatibility onstraint. . . 60

4.31 The industrialmixer problem. . . 61

4.32 Valueand variableorderings. . . 61

4.33 Consisten ylevel. . . 62

4.34 Ordering heuristi s& onsisten ylevel. . . 62

4.35 Adding onstraintsto s-COMMA. . . 63

4.36 Removingsymmetries fromtheso ialgolfersproblem. . . 64

4.37 The Sudokuproblem. . . 65

4.38 Addingnew fun tions. . . 65

4.39 Using thenewfun tions intheSudoku problem. . . 66

4.40 Addingnew heuristi orderingsand onsisten y levels. . . 66

4.41 The tunedmixer lass. . . 67

4.42 Class and data artifa ts. . . 67

4.43 The stablemarriage problemonthe s-COMMAGUI.. . . 68

4.44 Attributes on thes-COMMAGUI. . . 69

4.45 Constraints onthe s-COMMAGUI. . . 70

4.46 Data leson the s-COMMAGUI. . . 70

4.47 Some short utsof the s-COMMAGUI.. . . 71

5.1 The s-COMMAar hite ture. . . 73

5.2 s-COMMAGUIJavapa kages. . . 74

5.3 The AttributeDialog lass.. . . 75

5.4 The ClassArtifa t lass. . . 75

5.5 The SCommaClass lass. . . 76

5.6 The getCodemethod. . . 76

5.7 Tokensand rulesin the ANTLRlexer of s-COMMA. . . 78

5.8 The lexerrule todene numbers. . . 79

(20)

5.11 Parser rules of s-COMMA. . . 80

5.12 Parser rules of s-COMMA. . . 81

5.13 Therule to re ognizeexpressions. . . 82

5.14 Asynta ti error. . . 83

5.15 Treewalkerof s-COMMA. . . 84

5.16 AJava pro edureto he k lassrede larations. . . 84

5.17 Asemanti error. . . 84

5.18 Two s-COMMA lasses. . . 85

5.19 Therule to he kattributes inthese ond pass. . . 85

5.20 Therule to he k onstraintsinthese ond pass. . . 86

5.21 Loop unrolling. . . 87

5.22 Enumeration substitution. . . 88

5.23 Compositionattening. . . 88

5.24 Flatteningarrays ontainingobje ts. . . 88

5.25 Conditionalremoval. . . 89

5.26 Conditionalevaluation. . . 89

5.27 Compatibility removal. . . 89

5.28 Expressionevaluation. . . 90

5.29 AFlats-COMMA modelofthestable marriageproblem. . . 91

5.30 Themapping tool. . . 92

5.31 Tokensand theIDENT ruleintheANTLR lexerof Flats-COMMA. . . 93

5.32 Parser rules of Flats-COMMA.. . . 93

5.33 Parser rules of Flats-COMMA.. . . 94

5.34 Treewalkerof Flats-COMMA. . . 94

5.35 Theinitial pro edure ofthemain Java lassof theGe ode/Jtranslator. . . 95

5.36 Code generationof the Ge ode/J onstru tor. . . 95

5.37 Code generationof Ge ode/Jvariables. . . 96

5.38 Thetree walkerfor the ode generation of onstraints. . . 96

5.39 Two pro edures for the odegeneration of onstraints. . . 97

5.40 AGe ode/Jmodel ofthestablemarriage problem. . . 97

5.41 Ageneral MDA for modeltransformation. . . 98

5.42 Model-driven translationins-COMMA. . . 98

5.43 Anextra t ofthe KM3leof Flats-COMMA. . . 99

5.44 ConstraintsintheKM3leof Flats-COMMA. . . 100

5.45 OperandsintheKM3le of Flats-COMMA. . . 101

5.46 ATL rules for theFlats-COMMA to Ge ode/Jtransformation. . . 101

5.47 ATL rules for the Flats-COMMA to Ge ode/Jtransformation. . . 102

5.48 ATL rules for de omposing matri es ontaining sets. . . 103

5.49 ATL helperto generate a Ge ode/J ve tor. . . 104

5.50 ATL helperto generate an addition. . . 105

5.51 Three templatesoftheTCS le of Flats-COMMA. . . 105

5.52 The model-driven transformation pro ess on the example of Flat s-COMMA (FsC) to Ge ode/J. . . 106

(21)

Part III  The Transformation Framework for CP

6.1 The transformationframework. . . 114

6.2 A s-COMMA modeloftheso ialgolfers problem. . . 115

6.3 The so ial golfersproblemexpressedinECL

i

PS

e

. . . 116

7.1 Three lasses of theKM3 leof s-COMMA. . . 119

7.2 Attributes and variables inthe KM3. . . 120

7.3 Constraint zones andstatementsintheKM3. . . 120

7.4 Some templatesoftheTCS leof s-COMMA. . . 121

7.5 TwoATL rules fora transformation froms-COMMA to pivot. . . 122

7.6 A fragmentof the pivot metamodel. . . 123

7.7 An example oftransformation rule. . . 123

7.8 The omposition atteningtransformation rule. . . 125

7.9 Composition atteningonthe so ialgolfers problem. . . 125

7.10 The enumeration substitution transformation rule. . . 126

7.11 Enumeration substitutionon theso ial golfersproblem. . . 126

7.12 The forallunrollingtransformation rule. . . 126

7.13 Auxiliary variableinsertion transformation rules. . . 127

7.14 Auxiliary variableinsertion pro ess. . . 127

7.15 A fragmentof the ECL

i

PS

e

metamodel. . . 128

7.16 Five templatesof the TCS leof ECL

i

PS

e

. . . 128

7.17 The transformationpro ess on theexample of s-COMMA to ECL

i

PS

e

. . . 129

7.18 An Ants ript forsele ting transformations. . . 130

(22)

C

HAPTER

1

Introduction

C

onstraint Programming (CP) isknownto be an e ient software te hnology for solving

ombinatorial and ontinuous problems.Underthis framework,problems areformulated

asConstraint Satisfa tion Problems(CSP). Su ha representation des ribes aproblem interms

of variablesand onstraints. Variables areunknowns lyingina set ofvalues alleddomain,and

onstraints arerelations among these variables restri ting the values that they an adopt. The

goal isto nda variable-valueassignment thatsatisesthewholeset of onstraints.

As an example, let us onsider the8-queens problem, whi h onsists in pla ing eight hess

queens on a 8x8 hessboard su h that none of them is able to apture any other using the

standard hess queen's moves. A solution requires that no two queens share the same row,

olumn, or diagonal.

Eight variables an be identied,

Q

1

, ..., Q

8

,where

Q

i

denotes therowpositionof thequeen

pla edinthe

i

th olumnofthe hessboard.Thedomainforea hofthesevariablesisgivenbythe

integer intervaldomain

[1, 8]

,whi h representsthepotential positionsof thequeenson therows

of the hessboard. On e the variables have been identied with their orresponding domains,

we an formulate the onstraints of the problem as the following inequalities for

i ∈ [1, 7]

and

j ∈ [i + 1, 8]

:

 To avoidthattwo queensarepla ed inthesame row:

Q

i

6= Q

j

.

 Toavoidthattwoqueensarepla edinthesameSouth-WestNorth-Eastdiagonal:

Q

i

+i 6=

Q

j

+ j

.

 Toavoidthattwoqueensarepla edinthesameNorth-WestSouth-Eastdiagonal:

Q

i

−i 6=

Q

j

− j

.

Figure1.1 Asolution ofthe 8-queens problem.

Asolutiontothisproblemisdepi tedinFigure1.1,it orrespondstothesequen e(3,5,2,8,1,7,

4,6), the rst queen from the left is pla ed on the third row from thetop, these ond queen is

(23)

1.1 From the Roots of CP to Modern Ar hite tures

Theresolutionpro essofCSPsinvolvestwomainaspe ts.Alanguagetoexpresstheproblem,

andalgorithmsto perform thesolvingpro ess.Insomesense,this integrationwasrstly

perfor-med around 1963 by Ivan Sutherland, who developed a language for spe ifying onstraints on

drawings[Sut63 ℄.Afterthislandmark,anaturalseparation o urredbetween thesetwoaspe ts,

andthe resear h workwas divided[FM06 ℄into two main streams:thelanguage stream andthe

algorithm stream.

In the language stream, the notion of onstraint was in orporated in several programming

languages and systems. For instan e, around 1967, El o k developed a de larative language

alled Absys [El 90 ℄ based on the manipulation of equational onstraints. Burstall employed

a form of onstraint in a program for solving ryptarithmeti puzzles [Bur69 ℄. Then, the

ad-van es in the programming languages eld allowed to in orporate onstraints in dierent

pa-radigms. For instan e, Borning ombined obje ts, onstraints, and visual environments in the

ThingLab simulationlaboratory[Bor81 ℄.Constraint werealsomixedwithlogi programming in

theformof onstraintlogi programming(CLP)[JMSY92 ℄.SomeexamplesarePrologIII[Col90 ℄,

CLP(

) [JL87℄,and CHIP[Van89 ℄.

In the algorithm stream, the resear h work was heavily inuen ed by the arti ial

intelli-gen e (AI) domain. The fo us was to develop more e ient sear h and heuristi methods. For

example, Waltz introdu ed in the mid-1970s a ltering algorithm to a elerate the resolution

pro ess of the s ene labeling CSP [Wal75 ℄. Then, Montanari developed other kind of ltering

me hanisms,te hni ally alledlo al onsisten ies, and ageneral framework forreasoning about

onstraints [Mon74 ℄ was established. The algorithm stream followed growing and new AI

om-munities working around the on ept of reasoning were developed su h as onstraint-based

reasoning[FM92℄and ase-based reasoning[AP94 ℄.

Theseparationofbothstreams ontinueduntiltheearly1990swhenagroupofs ientistsfrom

dierent elds attempt to reintegrate them to reate a new single paradigm alled  onstraint

programming. Theideawasto reate a newte hnology underthefollowingprin iple: Theuser

states the onstraints and a general purpose onstraint satisfa tion engine solve them. From

those days many onstraint programming systems have been developed, always integrating the

twoaforesaidstreamsandsometimesinvolvingotherapproa hes,forexampleECL

i

PS

e

[WNS97℄

and GNU Prolog [DC00℄ for onstraint logi programming or Oz [SSW94 ℄, a multiparadigm

language ombining onstraint-basedinferen eanddistributed omputing.Also,severallibraries

havebeenintrodu ed,generallybuiltontopofwell-knownprogramminglanguagessu hasILOG

Solver [Pug94℄andGe ode [ST06 ℄using C++; andCHOCO [www

12

℄running under Java.

At the beginning of the urrent de ade, an important issue arose. The ommunity realized

thatjustaredu ednumberofexpertsmasteredtheCPte hnology.Oneofthemainreasonswas

the omplexityoftheCP'susage.Thefruitfuluseofexistingtoolsimpliedtohavea onsiderable

level of CP expertise, for instan e to deal with en oding aspe ts of host languages or to tune

sear h strategies to perform e ient solving pro esses,in on lusion, themodeling on erns to

state problems were not enough. Thisimportant issueen ouraged the reation of theso- alled

modelinglanguages,su hasOPL[Van99 ℄,whereamoreuser-understandable languageisgiven.

The user deals with a higher-level language without needing to over omethe en oding aspe ts

ofa hostlanguage or to spe ifyasear h strategy.

Three years ago, onstraint programming systems evolved and the last generation of CP

(24)

MiniZin [NSB

+

07℄. This new ar hite ture onsiders three layers, a modeling language on the

top,asetofCPsystemsonthebottomandamappingtoolonthemiddle.Themodelinglanguage

allowsuserstostateproblemsinahigh-levelofabstra tion.Themappingsystemtakesthismodel

and translates itto one of the underlying CP systems,whi h al ulatesthesolution. These CP

systems, generi ally alled solvers, normally have a lower level of abstra tion ompared to the

modeling language.Aninteresting featureof thisar hite ture isthe apabilityofpro essingone

model with dierent solvers. This feature is useful for experimentation tasks, onsidering that

there existsmanykind ofmodels and thereis nosolverhaving thebest resolution for all.

1.2 Motivations & Contributions

Theresear hofhigh-levellanguagesandexiblear hite tures formodeltransformationisan

important hallenge inthe CPeld. Thetaskis hard sin e many aspe ts must beinvestigated.

The denitionof high-levellanguages requiresto onsiderseveral on erns. For instan e,

provi-dingsupportfor a widerangeof problemsdependson thedenition ofsuitablelevels of

expres-siveness. Thedesign of elegant modeling styles isessential for getting on ise and lear models.

Extensibility me hanisms are important to enlarge the expressiveness of languages, and tuning

apabilitiesareusefulfor a hievinge ientsolvingpro esses.Softwarefeaturestoimprovereuse

andmodelmanagement aredesirable parti ularlyfor handlinglargerproblems.Buildingexible

and e ient ar hite tures for model transformation involves the study of additional on erns.

For instan e, the orre tsele tion oftoolsand te hniquesisakeyde isionto implementexible

and modular mappings. Another important aspe t is the openness of this ar hite ture, i.e. it

must be possible to plugnewsolversto the underlying layer.

The development of languages and systems for CP is a long story. Various evolutions,

im-provements and ombinations of previous approa hes an be regarded. However, most of the

aforementioned aspe ts are re ent and they have not been studied enough. In this thesis, we

presentanewvisionforhandling those on erns.Softwareengineeringpra ti esare

omplemen-ted with several innovations to provide high-level problem modeling. Powerful te hniques from

themodelengineeringworldensure modularandexiblemappingstoward thesolverresolution.

Thisnewapproa h onsistsofthree main omponents:thes-COMMAlanguage,thes-COMMAGUI,

and amiddle toolfor transformingmodels to solverprograms.

s-COMMA is the modeling language of the ar hite ture [SG07b ℄. Its design is based on the

experien e of the software engineering world. Features from obje t-oriented languages su h as

modularity, omposition, and inheritan e areintrodu ed to support reuse andthe management

of onstraint models.The ore of thelanguage is a ombination of a high-level obje t-oriented

language with a onstraint language. The onstraint language in ludes usual data stru tures,

ontrol operations, andrst-order logi todene onstraint-basedformulas.Theobje t-oriented

part of the language has been simplied to avoid the omplex en oding on erns present in

programming languages. Asa onsequen e, thelanguage isable to elegantly apture the

stru -ture of problems in single obje ts. This new modeling style is just the rst innovation of our

approa h. The se ond innovation of s-COMMA on erns its tuning apabilities. A simple

forma-lism is provided to perform ustomized solving pro esses [SG08b ℄. This formalism is unique in

obje t-oriented onstraint modeling and it prots of the obje t-oriented style to ongure

(25)

solverlayer.Thisme hanismallowsus toaddnewfun tionalitiessu hasnewglobal onstraints,

newfun tions, or newtuning options [SG07a ℄.

The s-COMMA GUI [CGS08 ℄ is the asso iated authoring tool of the ar hite ture. The visual

language provided an be seen as the graphi al representation of the s-COMMA language. The

design of this new language has also been inuen ed by software engineering pra ti es. In fa t,

the obje t-oriented style of s-COMMA hasbeen naturally represented by means of an extension

oftheUML lassartifa t. Thisnew languageis thefourthinnovation ofthear hite ture, being

thesupportof avisual anda more on iseper eption ofmodels.

The mapping tool is the third omponent of the ar hite ture. This tool is responsible for

transforminganinputmodelintoanexe utablesolverprogram.Amain hallengemustbefa ed

atthisstage.Thetransformationsmustbeexibleandeasyto implement inordertopermitthe

integrationofnewsolverstotheplatform.Thisissueisevidentlyamodeltransformation on ern.

A ordingly, as the fth innovation of the ar hite ture, the mapping tool has been enhan ed

with thein orporation of a model-driven ar hite ture [CGS08 ℄. This approa h provides proper

metamodeling and transformationte hniquesto build exiblemapping tools.

The transformation pro ess performed in s-COMMA is similar to that of Zin or Rules2CP

[FM08℄, ex ept for the transformation of graphi al artifa ts. In s-COMMA we onsider a

three-step transformation phase (see Figure 1.2 ). Firstly, graphi al artifa ts are transformed to the

orrespondings-COMMAmodel.ThismodelmustthenbetransformedtotheFlats-COMMA[SG08a ℄

intermediate language to be loser, in terms of language onstru ts, from the solver language.

Inthispro ess,several high-level onstru ts not supportedat thesolverlevel aretransformed

to simpler ones. For instan e, loopsare unrolled, onditionals arerefa tored, or obje t-oriented

ompositions are attened. This allows one to simplify both the translation pro ess and the

integrationofnewsolvertransformations.Finally,thisintermediatemodelisdire tlytransformed

to theexe utable solverprogram.

s-COMMA

Transformation

Visual-to-Textual

Visual Model

s-COMMA

Model

Transformation

Textual-to-Flat

Flat s-COMMA

Model

Transformation

Flat-to-Solver1

Solver 1

Transformation

Flat-to-Solver1

Solver 2

Transformation

Flat-to-SolverN

Solver N

Figure1.2 The transformationpro ess ins-COMMA.

The s-COMMA platform is the result of an investigation of several important on erns in

the development of modern ar hite tures for CP. Manyinnovations and benets an be found

in this new approa h. A high-level language is provided to smoothly apture the stru ture of

problems.Ana urategraphi alrepresentationofthislanguageisgiventoa hieveamore on ise

representation of problems.As opposedto previous approa hes, theexpressiveness of s-COMMA

anbeextendedtosupportnewfun tionalities.Theuseoftuningme hanismsinobje t-oriented

(26)

a same modelwith dierent solvers ispresent. Finally, the stru ture of thear hite ture an be

updated.New solvers anbe onne ted to theplatform inorderto enlarge theexperimentation

possibilities.

Ase ondwork ispresentedinthis thesisaswell[CGS09 ℄. Thisnewapproa h an beseenas

animprovement ofthesolver-independent ar hite ture.We introdu e anewframeworkallowing

to dene bridgesbetween dierent modeling and solver languages. Themain motivationbehind

this work on erns thefa tthatdeningauniversalmodelinglanguage

1

forCPishard,andthe

users usuallyhavetheir ownpreferen es.Therefore,webelieve thata transformationframework

to dene mappings between many modeling languages and many solvers would be desirable.

Thisnewapproa hinvolvesimportant advantages.For instan e, usersmay hoose theirfavorite

modeling language and the best known solving te hnology for a given problem provided that

the transformation between languages is implemented. Additionally, itmaybe easy to reate a

olle tionof ben hmarks fora given language fromdierent sour e languages.Thisfeature may

speed upprototyping ofone solver,avoidingthe rewriting ofproblemsinitsmodeling language.

Source Model

Transformation

Pivot Model

Source-to-Pivot

Target Model

Transformation

Pivot-to-Target

Pivot-to-Pivot

Refactoring/

Optimization

Figure 1.3The transformation framework for CP.

We implement this transformation framework by means of an ar hite ture ompletely built

using a model-driven approa h. A generi and exible pivot model (intermediate model) has

been introdu ed, to whi h dierent languages an be mapped. This ar hite ture allows one to

perform a omplete transformation in three main steps: from the sour e to the pivot model,

refa toring/optimization of the pivot model, and from the pivot to the target model (see

Fi-gure 1.3 ). Refa toring and optimization steps are always implemented over the pivot so as to

guarantee independen e from external languages. This rening phase is omparable to theone

performedfroms-COMMA to Flats-COMMA,but moreexible sin e thepro essis not xed, i.e.it

is possible to sele t the rening steps to be applied in a transformation. For instan e, if loops

aresupportedatthe targetlevelitisuselessto unrollthem.Thisfeatureallowsone tomakeuse

ofthe onstru ts provided at thetarget leveland thereforetoredu ethedieren es(intermsof

model stru ture) between the sour eand thetarget model.

The work done on this transformation framework an be seen as a natural ontinuation of

the ar hite ture implemented in s-COMMA. Two main innovations an be observed withrespe t

to previous work.Thepossibilityofusing dierent modeling languagesasthesour e ofa

trans-formation, and the possibility of sele ting theappropriate rening phases in a transformation.

The rst featurespeeds up prototyping of solvers andmotivatesmodelsharing, andthese ond

one enables users to generate models targetinga desiredsolving te hnology.

1

(27)

1.3 Outline

This thesis is omposed of three main parts: Part one is devoted to the state of the art

and itis dividedinto two hapters. Therst hapter gives anoverviewof te hniques developed

for solving CSPs. We in lude the main pro edures and we illustrate them by means of several

examples. The se ond hapter gives a summary of languages and systems for modeling and

solving CSPs. The spe trum is very wide, from programming to modeling languages and from

logi toobje t-orientedparadigms.Wealsointrodu e variousmodels ofthen-queensproblemin

orderto ontrast the dierent approa hes.

Part two presents the s-COMMA platform. The rst hapter of this part is devoted to the

modeling features of s-COMMA. A tour of the s-COMMA language is rstly given, followed by a

detailedillustrationofthe modeling onstru ts supported.The hapterendswithapresentation

of the s-COMMA GUI and its graphi al artifa ts. The se ond hapter of this part fo uses on the

whole transformation hain, from graphi al artifa ts to solver models. We present the main

elements involved in the system (e.g. parsers, metamodels and transformation rules) and the

toolsand te hniquesfor implementing them.

The se ond approa h we developed is presented in Part three. The rst hapter presents

thear hite ture of the transformation framework and motivates its implementation through an

example on erning several transformation issues. The following hapter fo uses on the

imple-mentation of themain parts of the transformation framework. We explain the stru ture of the

ar hite ture andthe transformation pro ess fromsour e to target models.The thesisendswith

(28)
(29)
(30)

C

HAPTER

2

Solving Techniques

C

onstraint satisfa tion involves various solving approa hes, whi h are mainly based on

arti ialintelligen e. Inthis hapter, wegivean overviewofthese approa hes. Werstly

introdu e somebasi notationsandthenwepresentthefoundationsofte hniquestosolveCSPs.

We onsiderthebasi sear halgorithmsaswellasmoreadvan edpro eduresthatinvolveltering

me hanisms.

2.1 Constraint Satisfa tion Problems

Denition 2.1 (Constraint Satisfa tionProblem). A Constraint Satisfa tionProblem

P

is

de-ned by a triple

P = hX , D, Ci

where:



X

isa set of variables

{x

1

, x

2

, . . . , x

n

}

.



D

is a set of domains

{d

1

, d

2

, . . . , d

n

}

su h that

d

i

is the domain of

x

i

dened as a subset

of some set

E

i

alled universe,for

i = 1, . . . , n

.



C

is a set of onstraints

{c

1

, c

2

, . . . , c

m

}

su h that

c

j

is a relation over a set of variables

{x

j

1

, . . . , x

j

nj

}

alled its s ope, dened as the set

Γ

j

⊆ d

j

1

× · · · × d

j

nj

, for

j = 1, ..., m

.

c

j

(x

j

1

, . . . , x

j

nj

)

isalso used todenote a onstraint

c

j

over its s ope

x

j

1

, . . . , x

j

nj

.

Asolution to aCSP isan assignment

{x

1

→ a

1

, . . . , x

n

→ a

n

}

su hthat:



a

i

∈ d

i

for

i = 1, . . . , n

. 

(a

j

1

, . . . , a

j

nj

) ∈ Γ

j

,for

j = 1, . . . , m

.

IftheCSPhasasolutionwesaythatitis onsistent;otherwisewesaythatitisin onsistent.

There existdierent lasses of CSPs,for instan e:

 A nite domain CSP orrespondsto a CSP inwhi h ea h domain is a nite subset of

Z

(universe of variables). The onstraints are generally dened as arithmeti , logi , or set

expressions.

 A numeri al CSP orresponds to a CSP in whi h ea h domain is an interval ontaining

valuesfrom

R

.The onstraintsaregenerallydened aslinear andnon linearequations or

inequalities.

2.2 Solving CSPs

Solving CSPs requires to explore the spa e of potential solutions. Su h an exploration an

be performed using a tree data stru ture, where the root is the initial problem and ea h node

(31)

those sub-problems. There exist dierent strategies for traversing the tree su h as deep-rst

sear h and breadth-rst sear h, and also various algorithms for generating and exploring the

tree.Themost basi one istheGenerate andTestalgorithm.

2.2.1 Basi Sear h Algorithms

Generate and Test

TheGenerateandTest(GT)algorithm onsistsingeneratingapotentialsolutionand he king

whetheritsatisesall the onstraints. This pro ess is donebygenerating atree thatrepresents

theCartesianprodu tof domains.

b b b b b b b b b b b b b b b b b b b b b b bb bb b bb b b b b b b b b b b b b b b b b b b b b b b bb b b b b b b b b b b b bb bb bb bb bb b b b b b bb b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b bb bb bb b bb b b b b b b

Figure2.1 Solvingthe4-queens problemusing GT.

Letus illustrate the GT pro essbymeans of the4-queens problem,a smallerversionofthe

8-queensproblemintrodu ed inChapter 1 .Figure2.1depi tsan extra tof thepro ess done by

the GT algorithm to rea h a solution for this problem

1

.The gure shows that onstraints are

he ked onlywhenallthe variablesoftheproblemhave been instantiated. Thus,failures annot

be dete ted as soon as only thevariables relevant to a onstraint have been instantiated. This

approa h issimple to implement,however thesear hing ostis tooexpensive.

Ba ktra king

Ba ktra king (BT) [Lu 91,GB65 ℄ is another approa h for the exploration/generation of the

sear h tree. In this method the potential solutions are generated in rementally by repeatedly

hoosing a value for another variable and as soon as all the variables involved in a onstraint

areinstantiated, the onstraint is he ked. Thus, ifa partial solution violates a onstraint, the

algorithm returns to themost re ently instantiated variablethat still hasalternatives available

(toa hievea solution),eliminating asa onsequen e the oni tingsubspa e.

Figure2.2depi tsthesear hpro essperformedbytheBTpro edureonthe4-queensproblem.

Thegure showsthat BTis ableto dete t failures assoon astwovariables areinstantiated (at

1

(32)

themiddlelevelofthetree),thatismu hearlier thanintheGT approa h.Despitethis,theBT

approa hisnot abletodete t failuresbeforeassigningthevalues toall thevariables involved in

a oni ting onstraint.This problem an be addressedbyusingltering te hniques.

b

b

b

b

b

b

b

b b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b b

b

b

b b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

Figure2.2 Solvingthe 4-queensproblemusing BT.

2.2.2 Filtering te hniques

Theperforman e of basi sear h algorithms an be improved by redu ing the variables'

do-mains ofea h generated sub-problem. Thisis possibleby al ulating a onsisten y propertyon

the onstraints.Theideaistoenfor esu hapropertyonea hsub-problembyusinga onstraint

propagation algorithm.The most usednotionof onsisten y isthear onsisten y [Ma 77℄.

Denition 2.2 (Ar Consisten y). Let

c

j

(x

j

1

, . . . , x

j

nj

)

be a onstraintand let

k

be an integer,

k ∈ {j

1

, . . . , j

n

j

}

. We say that

c

j

is ar onsistent wrt.

x

k

i:

∀a

k

∈ d

k

: ∃a

j

1

∈ d

j

1

, . . . , ∃a

k−1

∈ d

k−1

, ∃a

k+1

∈ d

k+1

, . . . , ∃a

j

nj

∈ d

j

nj

su hthat

(a

j

1

, . . . , a

j

nj

) ∈ Γ

j

A onstraintis saidto be ar onsistent ifit isar onsistent wrt. toall itsvariables. A CSP

is said tobe ar onsistent if all its onstraintsare ar onsistent.

Ar onsisten y allows one to verify that for ea h value of a domain it exists at least one

value in the domain of the other variables su h that the onstraint involved is satised. This

property anbe al ulatedbya onstraintpropagationalgorithminordertoredu ethedomains

of variables.Asan example, letus onsiderthepla ement ofthe rst queenon the ell (1,1) of

the hessboard(see Figure2.3 ). Three ells have been eliminated to make thesub-problem ar

(33)

value in the domain of

Q

1

su h that the onstraint

Q

1

6= Q

2

is satised ( onsidering that the

domainof

Q

1

be ame

{1}

aftertheinstantiation).Inthesameway,thevalue

1

hasbeenremoved

fromthe domainof

Q

3

and

Q

4

.Thispro ess isdone forea h onstraint oftheproblemallowing

to avoidseveral potential wrong instantiations. Letusnote thatthereexist dierent algorithms

to enfor ear onsisten y,for instan eAC-3 [Ma 77 ℄,AC-4 [MH86 ℄andAC-5 [VDT92℄.

b

Q1=1 Q2=1 Q3=1 Q4=1

Figure 2.3Enfor ing ar onsisten y.

Therealsoexiststronger onsisten ynotions,whi hmayeliminatealargernumberof

oni -ting values fromdomains, but at higher ost in termsof omputations. Some examples arethe

path onsisten y[Mon74 ℄ and thek- onsisten y[Fre78℄.

2.2.3 Solving Algorithms

A sear h algorithm an be ombined with onstraint propagation to obtain a more

e- ient solving pro edure. The most ommon approa h is to ombine theBT algorithm withthe

ar onsisten y. Some examples are Forward Che king (FC) and Maintaining Ar Consisten y

(MAC).

Forward Che king

Forward he king [M G79℄ is able to prevent future oni ts by performing ar onsisten y

on the not yet instantiated variables. This is done by removing temporarily the values of the

variables thatwill further ausea oni twiththe urrent variableassignment.Hen e,the

algo-rithmimmediatelydete tsthatthe urrent partialsolution isin onsistent and onsequentlythe

sear hspa e anbepruned earlierthan using simple ba ktra king.

Figure 2.4 illustrates this pro ess: values from domains are removed sin e the se ond level

of the tree. On e a queen is stated, its future oni ting values are temporarily removed, for

instan ethequeen stated atthe position(1,1) removesall values orresponding to therstrow

and theNW-SE diagonal. Then, inthe left subtree, these ond queen is pla ed at theposition

(3,2)whi hisimmediatelysetasin onsistent sin eitdoesnotleaveavailablepla eforthethird

(34)

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

b

1

2

3

4

1 2 3 4

Figure2.4 Solvingthe 4-queens problemusing FC.

Maintaining Ar Consisten y

The Maintaining Ar Consisten y (also alled Full Look Ahead) [Gas74 , SF94 ℄ is a

stron-ger solving algorithm. It he ks the oni ts between future variables in addition to the test

between the urrent andthefuture variables.

b

b

b

b

b

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

Figure 2.5Solving the 4-queens problemusingMAC.

Figure 2.5 illustrates this pro ess, where we an see that the MAC algorithm is able to

prunethesear hspa eearlier thantheforward he king,but doingmu h workon ea hvariable

assignment.Forinstan e,whentherstqueenispla edattheposition(1,1)the oni tsbetween

the urrent position and the futurepositions are removed. After that, thealgorithm he ks the

oni tsamongthefuturevariablesstartingwiththerstavailablepositiononthese ond olumn

thatis,the ell(3,2).Thealgorithm ndsoutthatthe position(3,2) isin onsistentsin eitdoes

(35)

leaves the ell (2,3) as the unique available position on thethird olumn, whi h is then set as

in onsistentsin e itdoesnot leaveavailablepla e forthefourthqueen.Thepro essfollowsuntil

theresultisrea hed ontheright subtree.

2.2.4 Solving numeri al CSPs

In the presen e of onstraints over real numbers, thealready presented ltering te hniques

annotbeapplied due to threemain limitations:

 De iding the onsisten y of onstraints over real numbers is not possible in a general

ontext [Ri 68℄.

 The representation of reals in numeri al omputations is not exa t sin e it is ommonly

done by means of oating-point numbers, whi h orrespond to a nite set of rational

numbers [Gou00 ℄.

 The useofoating point numbersmayleadto rounding errors.

As a onsequen e, spe i ltering te hniques have been dened in order to deal with real

numbers. These te hniques mainly rely on the al ulation of approximations over domains

re-presented by intervals bounded by oating-point numbers. Some te hniques are based on hull

onsisten y[Lho93 ,Lv93 ,BO97 ℄ andon box onsisten y [BMV94℄.

2.2.4.1 Interval arithmeti

Beforepresentingthelteringte hniquesdedi atedtonumeri alCSPs,letusgiveanoverview

ofintervalarithmeti [Moo66 ℄.

Denition 2.3 (Floating-point Interval). An interval

I

bounded by oating-point numbers is

dened as:

I = [a, b] = {r ∈ R|a ≤ r ≤ b,

with

a, b ∈ F}

We denote

inf(I)

asthelowerboundand

sup(I)

astheupperboundoftheinterval.Thefour

basi operations to be usedon oating-point intervals arethefollowing:

[a, b] ⊕ [c, d] = [⌊a + c⌋, ⌈b + d⌉]

[a, b] ⊖ [c, d] = [⌊a − d⌋, ⌈b − c⌉]

[a, b] ⊗ [c, d] = [min(⌊ac⌋, ⌊ad⌋, ⌊bc⌋, ⌊bd⌋), max(⌈ac⌉, ⌈ad⌉, ⌈bc⌉, ⌈bd⌉)]

[a, b] ⊘ [c, d] = [min(⌊a/c⌋, ⌊a/d⌋, ⌊b/c⌋, ⌊b/d⌋), max(⌈a/c⌉, ⌈a/d⌉, ⌈b/c⌉, ⌈b/d⌉)], 0 /

∈ [c, d]

Denition 2.4. Given

a ∈ R

, we denote

a

+

as the smallest element of

F

greater than

a

, and

a

as thegreatest element of

F

smaller than

a

.

Denition 2.5 (Canoni alInterval). We say that a nonempty interval

I

is anoni al if:

I = [a, b]

su h that

b ≤ a

+

,

with

a, b ∈ F

Denition 2.6 (Hull Operator). The hull of a set

S ⊆ R

is dened as the smallest interval

en losing

S

:

(36)

Denition 2.7 (Interval Extension). An interval fun tion

F : I

n

→ I

is an interval extension of a real fun tion

f : R

n

→ R

i :

∀B ∈ I

n

: {f(x)|x ∈ B} ⊆ F (B)

There are various implementations of interval extensions. The natural interval extension of

a real fun tion

f

isdened asthe fun tion

F

inwhi h ea h real onstant isrepla edbyits hull

andea hreal operationisrepla edbyits orrespondingintervaloperation.Asanexampleletus

onsider the following fun tion

f

dened overreal numbers:

f (x, y) = x

2

− (x × y) + 2|x, y ∈ R

thenatural extension

F

of thefun tion

f

isdened asfollows:

F (X, Y ) = X

2

⊖ (X ⊗ Y ) ⊕ [2, 2]|X, Y ∈ I

Given

x ∈ X = [0, 2]

and

y ∈ Y = [1, 3]

we have:

F (X, Y ) = [0, 4] ⊖ [0, 6] ⊕ [2, 2]

F (X, Y ) = [−6, 4] ⊕ [2, 2]

F (X, Y ) = [−4, 6] ⊇ {f(x, y)|x ∈ X, y ∈ Y }

2.2.4.2 Consisten y notions

In this se tion we present two of the onsisten y notions devoted to numeri al CSPs: hull

onsisten y (also alled2B- onsisten y) and box onsisten y.

Denition 2.8 (Hull Consisten y). Given a real onstraint

c

j

(x

j

1

, . . . , x

j

nj

)

, a box

B = I

1

×

. . . × I

n

⊆ I

n

,thebox

B

= I

j

1

× · · · × I

j

nj

,aninteger

k ∈ {j

1

, . . . , j

n

j

}

,wesaythat the onstraint

c

j

ishull onsistent wrt.

x

k

i :

I

k

= hull(π

k

j

∩ B

)),

where

π

k

orrespondstotheproje tionof

c

j

on

x

k

.We saythatthe onstraint

c

j

ishull onsistent

wrt.

B

if that relation istrue for

k ∈ {j

1

, . . . , j

n

j

}.

Denition 2.9 (BoxConsisten y). Givena real onstraint

c

j

of the form

f

j

(x

j

1

, . . . , x

j

nj

) = 0

,

F

j

a natural interval extensionof

f

j

,a box

B = I

1

× . . . × I

n

⊆ I

n

, thebox

B

= I

j

1

× · · · × I

j

nj

, an integer

k ∈ {j

1

, . . . , j

n

j

}

, we saythat the onstraint

c

j

isbox onsistent wrt.

x

k

i :

I

k

= hull({a

k

∈ I

k

|0 ∈ F

j

(I

j

1

, . . . , I

k−1

, hull({a

k

}), I

k+1

, . . . , I

j

nj

)})

Wesaythatthe onstraint

c

j

isbox onsistentwrt.

B

ifthatrelationistruefor

k ∈ {j

1

, . . . , j

n

j

}.

Forthesakeofsimpli itywedenethebox onsisten yonlywrt.equalities,butthisdenition

an beeasily extendedfor inequalities, onsidering that

f ≤ 0 ⇔ f = z, z ∈ [−∞, 0].

Thebox onsisten ypropertyisgenerallyweakerthanhull onsisten y(a omparison anbe

(37)

2.2.4.3 Filtering algorithms

In this se tion, we illustrate two ltering algorithms by using thealready presented

onsis-ten ies.

Enfor ing hull onsisten y

Thehull onsisten y anbe enfor edbyusingintervalarithmeti intwomainphases:forward

evaluationandba kward propagationAsanexample,letus onsiderthenothull onsistentCSP

P = hhx, y, zi, hD

x

∈ [4, 9], D

y

∈ [2, 7], D

z

∈ [3, 8]i, hx = y + zii

.

=

[4,9]

x

+

y

z

[5,9]

[5,15]

[2,7]

[3,8]

=

[5,9]

x

+

y

z

[5,9]

[5,9]

[2,6]

[3,7]

Forward Evaluation

Backward Propagation

Figure2.6 Enfor ing hull onsisten y.

Figure 2.6 depi ts the pro ess performed by thehull onsisten y algorithm. Su h a pro ess

begins with the forward evaluation, whi h is a bottom-up tree traversal to evaluate its terms.

The expression

y + z

is evaluated by onsidering the interval addition operation, giving as a

result theinterval

[5, 15]

. The root of the tree orrespondsto an equal symbol, whi h operates

asan interse tion. Thus, the result of this node is given by

[4, 9] ∩ [5, 15] = [5, 9]

. The forward

evaluationisfollowed bytheba kward propagation, where the onstraint isproje ted ona

top-down treetraversal. Startingwiththeroot,theinterval

[5, 9]

isinterse ted withits hildnodes,

both nodes be ome

[5, 9]

, and the hull onsistent domain of

x

is obtained. Then, to al ulate

the hull onsistent domain of

y

, we reorganize the equation as follows:

y = [5, 9] ⊖ z

. Using

theinterval subtra tion operation, and repla ing

z

by its domain, the result of the equation is

given by

[5, 9] ⊖ [3, 8] = [−3, 6]

.Thenewintervalisinterse tedwiththepreviousdomain of

y

to

obtain thehull onsistent domain of

y

(

[−3, 6] ∩ [2, 7] = [2, 6]

). The hull onsistent domain of

z

is al ulated inthe same way.

Enfor ing box onsisten y

For the sake of simpli ity we onsider a simple algorithm using box onsisten y (the

origi-nalpro edure in ludes theintervalNewton method [Neu90 ℄). Thisalgorithm begins by testing

whetherthedomain ontainssolutions.Ifthedomainisin onsistentitisreje ted;otherwiseits

lo-wer anoni alinterval[

inf(D)

,

inf(D)

+

℄istested.Ifthe anoni alintervalsatisesthe onstraint,

inf(D)

is the newlowerbound.Otherwise,

D

is bise ted and thepro edure is performed again

withtheinterval

[inf(D)

+

,

inf(D)+sup(D)

2

]

andtheinterval

[

inf(D)+sup(D)

(38)

let us onsider the not box onsistent CSP

P = hhxi, hD

x

∈ [−2, 2]i, hx

2

< 2ii

shown in Fi-gure2.7 .

2 =

−1.41421...

2 =

1

.41421...

0

1

2

3

−1

−2

−3

1

2

3

4

Figure2.7 TheCSP

P = hhxi, hD

x

∈ [−2, 2]i, hx

2

< 2ii

.

Figure2.8illustratesthe pro ess performed bythealgorithm. Thepro ess begins bytesting

thedomain

[−2, 2]

whi h ontains onsistent values butits anoni allowerbound(

[−2, −2

+

]

) is

in onsistent,soitisbise tedinto theintervals

[−2

+

, 0]

and

[0, 2]

.Thesame pro essisdonewith

the lower interval, whi h is bise ted again into the intervals

[−2

+

+

, −1]

and

[−1, 0]

. The lower

interval

[−2

+

+

, −1]

is bise ted again, and thenew lower interval isreje ted sin e no solution is

found.Thepro ess ontinuesuntilboththelowerandtheupper anoni alintervalsare onsistent.

Thelowerboundofthe onsistentlower anoni alintervalandtheupperboundofthe onsistent

upper anoni alinterval orrespond to the boundsof thebox onsistent domain.

[-2 ,0]

[-2,2]

[0,2]

[-2 ,-1]

[-1,0]

[-2 ,-1.5]

[-1.5,-1]

[-1.5 ,-1.25]

[-1.25,-1]

[-1.5 ,-1.375]

[-1.375,-1.25]

[-1.5,-1.4375]

[-1.4375,-1.375]

[-1.4375,-1.40625]

[-1.40625,-1.375]

+

++

+

+

+

+

++

++

+

+

(39)

2.2.5 Variable and Value Ordering Heuristi s

Sear h algorithms start the pro ess by sele ting a variable to enumerate or to bise t. The

order in whi h this hoi e is done is referred to as the variable ordering. Several experiments

have demonstratedthata orre torderingde ision anbe ru ialtoperform anee tivesolving

pro ess.There existseveral heuristi sfor sele ting thevariableordering:

 Fail-rst: to sele tthe variablewith the smallestdomain. This hoi e ismotivated bythe

assumption thata su ess an be a hieved byrst tryingthe variables thathave a bigger

han etofail,inthis ase, thevalueswithasmallernumberofavailable alternatives.This

heuristi isknownto bemore adapted todis rete domains.

 Most- onstrained variable:this hoi e an be justiedbythefa tthattheinstantiationof

su h a variable shouldlead to abigger treepruning throughthe onstraint propagation.

 Redu e-rst: to sele tthevariablewiththe biggestdomain.This heuristi isknownto be

more adaptedto ontinuous domains.

 Round-robin:tosele tthevariablesinsomerationalandequitableorder,for instan efrom

therst variabledened inthemodelto thelast one.

After sele ting the variable to enumerate or bise t, the algorithms have to sele t a value

from the variable's domain. This sele tion is alled the value ordering and it an also have a

onsiderableimpa t. For example, ifthe right value is hosen on the rst try for ea h variable,

a solution an be found without performing ba ktra ks. However, ifthe CSP is in onsistent or

the whole set of solutions is required, the value ordering is irrelevant. The literature presents

dierent waysto perform this sele tion whi h,dependingon theproblemnature, may leadto a

moree ient onstraint propagation[Apt03 ℄.

For instan e, ontinuous domains are generally bise ted, i.e. ea h interval is split to obtain

two size-equivalent intervals.It is also possible to enumeratea set of little intervals,whose size

orresponds to the pre ision of variables. The dis rete domains are, in general, enumerated,

however it is also possible to bise t them as usually done in ontinuous domains. After the

enumeration, it is possible to hoose the rst value as well as the smallest, the median or the

maximalvalue.Therealsoexistmore omplexvalueorderingheuristi swhi hareingeneraleither

basedon estimatingthe numberof solutions or estimating theprobability ofa solution[van06℄.

2.3 Summary

Inthis hapter wehave presentedthe mainte hniquesforsolving CSPs.Wehave illustrated

basi sear halgorithmsaswellasmoreadvan edpro eduressu hastheonesinvolving onstraint

propagation.Constraintpropagationisalteringme hanism apableofimprovingthee ien y

of sear h algorithms byenfor ing a onsisten y property.Dierent kinds of onsisten y notions

exist,whi h an beapplied dependingon the nature oftheCSP.

Inthenext hapter,wepresentalargelistoflanguagesandsystemsformodelingandsolving

CSPs. Most of them embed in their internal solving engines the algorithms and te hniques

(40)

C

HAPTER

3

Languages and Systems

L

anguagesandsystemsformodelingandsolvingCSPshavebeendevelopedunderdierent

prin iples. As we have mentioned, the rst system dates ba k from the 1960s, followed

by a large list where very dierent paradigms be ame involved. For instan e, the use of logi

programming as the support for the CLP paradigm or the use of obje ts for thesimulation of

problems under onstraints. From an implementation point of view, dierent ways have been

proposed, for instan e, using libraries upon a host programming language or building a new

programming language with supportfor onstraints. The development of a pure modeling

lan-guage instead of a programming language is a more re ent on ern, the idea is to provide a

more user-understandable language. In the following paragraphs we give an overview of

lan-guages and systems for onstraint satisfa tion organized insix groups: CLP systems, libraries,

modeling languages, programming languages, mathemati al programming systems,and

obje t-oriented languages. To give a general view of similarities and dieren es of su h languages, at

ea h se tion'send amodelofthen-queens problemisintrodu ed.

3.1 Constraint Logi Programming

Constraint Logi Programming isthe paradigmthat extends logi programming to support

onstraint solving. This extension is known to be natural, as the de larativeness of logi

pro-gramming issuitable forstating onstraints,and thebuilt-inba ktra king engine anbe usedto

simplify theimplementation of sear h me hanisms. This idea was pioneered by Colmerauer, in

thedevelopmentofProlog II[Col82 ℄.Su hanapproa hwasthengeneralized intheCLPs heme

established byJaar and Lassez in[JL87℄. Then, many other systems in luding additional

fea-tures were developed, someexamples arepresentedin thefollowing.

Prolog III-IV

Prolog III[Col90 ℄ is the su essor version of the pioneering Prolog II system. This approa h

wasoneoftherstinrepla ingthelogi programminguni ationme hanismbythemoregeneral

me hanismof onstraintsolvingwhi h,fromate hni alstandpoint,isoneofthebasi prin iples

of CLP. The last version of this set of su essors is alled Prolog IV [Col96 ℄, a CLP system

designed to support onstraintsoverdierent domains su hasintegers, realsand booleans.

CLP(

)

CLP(

) [JMSY92 ℄ is another pre ursor CLP tool. It was dened as an instan e of the CLP

(41)

overreals bymeans of analgebrai built-in onstraint solverableto dealwith lineararithmeti

andnon-linear onstraints.

CHIP (Constraint Handling In Prolog)

CHIP [Van89 ℄ is also onsidered a pioneering CLP system together with the already

pre-sented CLP(

) and Prolog III systems. It was originally developed as an extension of Prolog,

being the rst one in in luding global onstraints. The urrent version, CHIP V5, is also

avai-lable as a C and C++ library. CHIP V5 in ludes several features su h as support for dierent

kinds of onstraints, interfa es to graphi al omponents and relational databases. The system

alsointegrates Xpress-MP[www24 ℄asitssolverfor linear programming.

ECL

i

PS

e

ECL

i

PS

e

[WNS97 ℄ is a more re ent CLP system. It provides a very wide range of features

for solving problems under onstraints, in luding the most typi al su h as lists, arrays and

re- ords, support for sets, and ontrol statements su h as onditionals and for loops. ECL

i

PS

e

alsoprovidesaset oflibraries, forexample,for handling ontinuousCSPs, forCHR(Constraint

Handling Rules)[Frü98 ℄ andfor mathemati al programming.Some ofthem an be ombined to

solve problems bymeans ofa hybrid style. Thedenition of ustomized sear h pro edures and

variable andvalueorderings isalso supported.

GNU Prolog

GNU Prolog is another system belonging to the CLP group [DC00 ℄. GNU Prolog has been

designed to supportnitedomain CSPs,however it an be interfa ed to handleCSPoverreals.

It provides a large list of predened Prolog predi ates and onstraints as well as support for

ommon onstru ts su h as lists, sets, and onditionals. Optimization problems and ordering

heuristi sarealsosupported. Aninterfa e hasbeen in luded to allexternal routineswrittenin

C.

SICStus Prolog

The SICStus Prolog system [COC97℄is based on a solver platform for nite domains,

onti-nuous domains and CHR.The host language provides typi al data stru tures su h as lists and

arrays,and alsomore omplexsu h assetsand Prolog-like obje ts.Supportfor onditional

sta-tements, optimization problems and variable ordering heuristi s is available as well. It is also

worth mentioning that SICStus Prolog has one of the most e ient implementations of global

onstraints. The system also provides multiple interfa es, for instan e, for C, C++, .NET and

Java.

Mer ury

Originally, Mer ury[SHC96℄ was designed asa logi /fun tional programming language.

Figure

Figure 2.1  Solving the 4-queens problem using GT.
Figure 2.2  Solving the 4-queens problem using BT.
Figure 2.8  Enforing box onsisteny .
Figure 4.1  A s-COMMA model of the ryptarithmeti puzzle SEN D + M ORE = M ON EY .
+7

Références

Documents relatifs

L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des

We explored the following features to weight the relevance of the bitexts and the individual sentences: corpus weights, alignment scores, recency of the data with respect to the

The aim of the unified requirements engineering meta-model UREM as mentioned in section two and three is to perform translation between different types of requirements engineering

While other model transformation approaches were applied to the same example for translation between source and target language, triple graph grammars additionally show their

Using four in-depth case studies we explore how biotech firms use different business model designs to generate added value and profit from their core competencies, and

On the other hand, if the transformation tool maintains a link relating each port to a port in a target model, then a property like the correctness of a Goto-From removal can

We present two different cases where i- the hard layer is another thin film polymer deposited on the pdms and ii- the hard layer is made by the oxidation of the pdms layer

{ dans l'industrie, les methodes de parallelisation se sont traditionnellement concen- trees sur les nids de boucles et sur les tableaux, avec des degres importants de