+ All Categories
Home > Documents > Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

Date post: 03-Jun-2018
Category:
Upload: askethi
View: 237 times
Download: 0 times
Share this document with a friend

of 47

Transcript
  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    1/47

    Artificial Intelligence 58 (1992 ) 113- 159 113

    Elsevier

    A R T I N T 9 5 1

    onstraint satisfaction using

    constraint logic programming

    P a s c a l V a n H e n t e n r y c k

    Brown Universi ty Bo x 1910 Providence R I 02912 USA

    H e l m u t S i m o n i s a n d M e h m e t i n c b a s

    Cosytec Parc Club Orsay-University 4 ru e Jean-Rostand 91893 Orsay Cedex Fran ce

    Abs tract

    Van He ntenryck, P . , H. Simonis and M. Dincbas, Constrain t satisfact ion using constrain t

    logic programming, Artificial Intelligence 58 (1992) 113-159.

    Constrain t logic program ming (CLP ) is a new class of declarative program ming lan-

    guages whose pr im it ive operat ions are based o n constrain ts (e .g . constrain t so lv ing an d

    constrain t en tai lment) . CLP languages natural ly combine constrain t propagation with

    non dete rm inistic choices. As a consequence, t hey are particularly app ropria te for solv-

    ing a variety of com bina toria l search problems, using the global search paradigm, with

    shor t development t ime and ef f iciency comparable to procedural tools based on the

    same approach. In th is paper , we descr ibe how the CLP language cc(FD), a successor

    of CHIP using consis tency techniques over f ini te dom ains , can be used to so lve two

    practic al applications: te st-patte rn genera tion and car sequencing. For both applications,

    we present the cc(FD) program, descr ibe how constrain t so lv ing is performed, repor t

    experimental results, and com pare the approa ch with existing tools.

    1 .

    ntroduc t ion

    T h e p u r p o s e o f o u r r e s e a r c h i s t o s u p p o r t , w i t h i n c o n s t r a i n t p r o g r a m -

    m i n g l a ng u a g es , c o m p u t a t i o n a l p a r a d i g m s u n d e r l y i n g c o m b i n a t o r i a l s e a r c h

    p r o b l e m s . I t i s m o t i v a t e d b y t h e h o p e o f re d u c i n g s i g n i f i c a n t l y t h e d e v e l o p -

    Correspondence to:

    P. Van Hentenryck, Brow n Univers i ty , Dep ar tme nt of Com puter Science,

    115 Waterman St. , 4th floor, Providence, RI 02906, USA. E-mail: [email protected].

    0004 -3702 /92/$ 05 .00 1992 - - Elsevier Science Publishers B.V. All r ights reserved

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    2/47

    114 P V a n H e n t e n r v c k e t a l

    m e n t t i m e o f t h e s e a p p l i c a t io n s w h i l e p re s e r v i n g m o s t o f t h e e f f ic i e n cy o f

    p r oc e du r a l l a ngua ge s .

    C o m b i n a t o r i a l p r o b l e m s a r e u b i q u i t o u s i n c o m p u t e r s c i e n c e . T h e y a p -

    pe a r i n a r e a s a s d i ve r s e a s ope r a t i ons r e s e a r c h ( e . g . s c he du l i ng ) , ha r dw a r e

    de s i gn ( e . g . c i r c u i t ve r i f i c a t i on ) , b i o l ogy ( e . g . D N A s e que nc i ng ) , f i na nc e

    ( e . g . op t i on t r a d i ng ) , a nd s o f t w a r e de s i gn ( e . g . s i m u l a t i on a nd t e s t i ng o f

    p r o t o c o l s ) , t o n a m e a f ew . M a n y o f th e s e p r o b l e m s a r e o f h i g h c o m p l e x i t y

    ( N P - c o m p l e t e o r w o r s e ) , w h i c h m e a n s t h a t t h e r e i s n o e f f i c i e n t a l g o r i t h m

    f o r s o lv i n g t h e m . M u c h r e se a rc h , h o w e v e r , h a s b e e n s p e n t o n d e s i g n i n g

    a l g o r i t h m s t o t a c k le t h e s e p r o b l e m s a n d o n e o f t h e i n t er e s t in g o u t c o m e s h a s

    b e e n t h e d e v e l o p m e n t o f c o n s t r a i n t s o l v in g a l g o r i th m s f o r v a r i o u s c la ss es o f

    p r o b l e m s .

    C o ns t r a i n t p r o g r a m m i ng ha s a l ong t r a d i t i o n i n a r t i fi c i al i n t e ll i ge nc e . I t

    c a n b e t ra c e d b a c k t o t h e u s e o f c o n s t r a i n t s in S u t h e r l a n d ' s S K E T C H P A D

    [ 6 7 ], t h e C O N S T R A I N T p r o g r a m m i n g l an g u a g e o f S u s s m a n a n d S t e el e [ 6 6 ]

    a n d t h e w o r k o f B o r n i n g o n T h i n g L a b [ 2 ] a m o n g o t h er s. M a c k w o r t h a ls o

    a dv oc a t e d , a s e a r l y a s 1977 , t he u s e o f c ons i s t e nc y t e c hn i qu e s ( a pa r a d i g m

    e m e r g i ng f r om a r t i f ic i a l i n t e ll i ge nc e t o s o l ve c om bi n a t o r i a l s e a r c h p r ob l e m s )

    i n de c l a r a t i ve l a ngua ge s a s a n a l t e r na t i ve t o c h r ono l og i c a l ba c k t r a c k i ng [ 42 ] .

    C o n s t r a i n t p r o c e s s i n g it s e lf h a s a l s o b e e n p r e s e n t i n m a n y s y s t e m s re l a t ed

    t o c o n s t r a i n t s o l v i n g s u c h a s R E F - A R F [ 2 3 ] , A l ic e [ 4 0 ] , ( a s s u m p t i o n -

    b a s e d ) t r u t h m a i n t e n a n c e s y s te m s ( e.g . [ 1 5 , 2 1 ] ) , a n d v a r i o u s s c h e d u l i n g

    a nd p l a n n i ng sy s t e m s ( e .g . [ 2 4 ] ) .

    T h e s t a r t i ng po i n t o f ou r r e s e a r c h w a s , how e ve r , s li gh t ly d i f f e r e n t . W e

    b e g a n b y r e c o g n i z in g t h a t l o g ic p r o g r a m m i n g is a n a p p r o p r i a t e l a n g u ag e

    f o r s t a t i ng c om bi na t o r i a l s e a r c h p r ob l e m s : i t s r e l a t i ona l f o r m m a ke s i t e a s y

    t o s t at e c o n s t r a i n t s w h i l e i ts ( d o n ' t - k n o w ) n o n d e t e r m i n i s m r e m o v e s th e

    n e e d f o r p r o g r a m m i n g a se a r ch p r o c e d u r e . U n f o r t u n a t e l y , t r a d i t i o n a l lo g i c

    p r o g r a m m i n g la n g u a g e s ca n a l s o b e v e r y i n e f fi c i e n t w h e n p r e s e n t e d w i t h

    a n a t u r a l f o r m u l a t i o n o f c o m b i n a t o r i a l s e a r c h p r o b l e m s , l a rg e ly b e c a u s e o f

    t h e i r p a s s iv e u s e o f c o n s t r a i n t s t o t e s t p o t e n t i a l v a l u e s in s t e a d o f p r u n i n g t h e

    s e a r c h s pa c e i n a n a c t i ve m a n ne r [ 27 ] . A s a c ons e que nc e , t r a d i t i on a l log i c

    p r o g r a m m i n g l a n g u a g es ( e.g . P ro l o g ) o f t e n l e a d t o g e n e r a te a n d t e s t o r

    s t a n d a r d b a c k t r a c k i n g a p p r o a c h e s t h a t ex h i b i t t h e p a th o l o g i c a l b e h a v i o r

    k n o w n a s t h r a s h i n g [ 4 2 ] .

    E a r ly ( C L P ) l a n g u a g es s u c h a s C H I P [ 2 0 ] , C L P ( R ) [ 3 7 ] , P r o l o g I I

    [ 1 3 ] , a n d P r o l o g I II [ 1 2 ] a t t e m p t e d t o p r e s e r v e th e a d v a n t a g e s o f l o g ic

    p r o g r a m m i n g w h i le r e m o v i n g t h e ir l i m i ta t io n s . T h e f u n d a m e n t a l i d ea b e h i n d

    t he s e l a ngua ge s , t o u s e c on s t r a i n t s o l v i ng i n s t e a d o f un i f i c a t i o n a s the k e r ne l

    o p e r a t i o n o f th e l a n g u a g e , w a s e l eg a n t ly c a p t u r e d i n t h e C L P s c h e m e [ 3 6 ] .

    T h e C L P s c h e m e d e f i n e s a f a m i l y o f p r o g r a m m i n g l a n g u a g es b a s e d o n

    c o n s t r a i n t s o l v i n g a n d s h a r i n g t h e s a m e s e m a n t i c p r o p e r t i e s . I t c a n b e

    i n s t a n t i a t e d t o p r o d u c e a s p e ci fi c la n g u a g e b y d e f i n i n g a c o n s t r a i n t s y s te m

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    3/47

    Co ns tra in t sa t is fac tion us ing CL P 5

    ( i. e. d e f i n i n g a s e t o f p r i m i t i v e c o n s t r a i n t s a n d p r o v i d i n g a c o n s t r a i n t s o l v e r

    f o r t h e c o n s t r a i n t s ) . T h u s C H I P c o n t a i n s c o n s t r a i n t s y s te m s o v e r f i n it e

    d o m a i n s [ 7 2 ] , B o o l e a n s [ 6 ] , a n d r a t io n a l n u m b e r s [ 3 0 , 7 4 ] , P r o l o g I I I

    i s e n d o w e d w i t h c o n s t r a i n t s y s t e m s o v e r B o o l e a n s , r a t io n a l n u m b e r s , a n d

    l is ts , w h i le C L P ( R ) s o l v es c o n s t r a in t s o v e r r e al n u m b e r s . T h e C L P s c h e m e

    w a s f u r t h e r g e n e r a l i z e d i n t o t h e c c f r a m e w o r k o f c o n c u r r e n t c o n s t r a i n t

    p r o g r a m m i n g [ 5 4 - 5 6 ] t o a c c o m m o d a t e a d d i t i o n a l c o n s t ra i n t o p e r a t io n s

    (e .g . c o n s t r a i n t e n t a i l m e n t [ 4 3 ] ) a n d n e w w a y s o f c o m b i n i n g t h e m ( e.g .

    i m p l i c a t i o n o r b l o c k in g a sk [ 5 4 ] a n d c a r d i n a l i t y [ 7 3 ] ) . M o r e p r ec is e ly ,

    t h e c c fr a m e w o r k a c c o m m o d a t e s al l o p e r a t i o n s o n c o n s t r a i n t s t h a t c a n b e

    de f i ne d a s c l o s u r e ope r a t o r s . T he ge ne r a l i z a t i on s i gn i f i c a n t l y e x t e nds t he

    s c o p e o f C L P l a n g u a g es b y e n a b l i n g i s s u es s u c h a s c o n c u r r e n c y , c o n t ro l , a n d

    e x t e ns i b i l i t y t o be a dd r e s s e d a t t he l a ngua ge l e ve l .

    C L P l a n g u a g e s I s u p p o r t , i n a d e c l a r a t iv e w a y , t h e s o l v i n g o f c o m b i n a -

    t o r ia l s e a r c h p r o b l e m s u s i n g t h e g l o b a l s e a rc h p a r a d i g m . T h e g l o b a l s e a rc h

    p a r a d i g m a m o u n t s t o r e c u r s i v e l y d i v i d i n g a p r o b l e m i n t o s u b p r o b l e m s u n t i l

    t h e s u b p r o b l e m s a re s i m p l e e n o u g h t o b e s o l v e d i n a s t r a i g h t f o rw a r d w a y ,

    a n d i n c l u d e s, a s s p e c ia l ca se s , i m p l i c i t e n u m e r a t i o n , b r a n c h a n d b o u n d , a n d

    c ons t r a i n t s a t i s f a c t i on . I t i s be s t c on t r a s t e d w i t h t he l oc a l s e a r c h pa r a d i gm ,

    w h i c h p r o c e e d s b y m o d i f y i n g a n i n i ti a l c o n f i g u r a t i o n lo c a ll y u n t i l a s o l u -

    t i o n i s o b t a i n e d . T h e s e a p p r o a c h e s a r e o r t h o g o n a l a n d c o m p l e m e n t a r y . T h e

    g l oba l s e a r c h pa r a d i gm ha s be e n u s e d s uc c e s s f u l l y t o s o l ve a l ar ge va r i e t y o f

    c om bi n a t o r i a l s e a r c h p r ob l e m s w i t h r e a s ona b l e ef f i c ie nc y (e .g . s c he du l i ng

    [ 7 ] , g r a p h c o l o ri n g [ 3 9 ] , H a m i l t o n i a n c i r c u i ts [ 9 ] , a n d m i c r o c o d e l a b e li n g

    [ 1 9 ] ) a n d p r o v i d e s , a t t h e s a m e t i m e , t h e b a s i s f o r e x a c t m e t h o d s a s w e l l

    a s a p p r o x i m a t e s o l u t i o n s ( g i v in g r is e t o t h e s o -c a ll ed a n y t i m e a lg o r i t h m s

    [ 14 ] ) .

    T h e p u r p o s e o f t h i s p a p e r i s to i l l u s tr a te h o w C L P l a n g u a g e s c a n b e u s e d

    t o s o l ve t w o p r a c t i c a l c om b i na t o r i a l s e a r c h p r ob l e m s : t e s t - pa t t e r n ge ne r a -

    t i o n a n d c a r s e q u e n c i n g . T e s t - p a t t e r n g e n e r a t i o n i s a s t a n d a r d p r o b l e m i n

    h a r d w a r e d e s i g n a n d m a n y a l g o r i t h m s h a v e b e e n p r o p o s e d f o r t h e t as k . W e

    s h o w h o w t o u s e c o n s t r a i n t l o g ic p r o g r a m m i n g to d e s i g n a s im p l e a l g o r i t h m

    w h o s e b e h a v i o r i s s im i l a r i n s p i r i t to s o m e o f t h e b e s t a l g o r i t h m s f o r th e

    t a s k a n d w h o s e e f f i c ie n c y i s c o m p e t i t i v e w i t h s p e c i a li z e d i m p l e m e n t a t i o n s

    o f t h e se a l g o r it h m s . T h e s e c o n d p r o b l e m , c a r s e q u e n c in g , w a s m o t i v a t e d b y

    i t s p r e s e n t a t i o n a s a c ha l l e nge f o r A I t oo l s [ 4 8 , 49 ] . W e p r op os e a s o l u t i on t o

    t h i s p r o b l e m t h a t c a n b e d e s c r i b e d c o n c is e ly in c o n s t r a i n t l o g ic p r o g r a m m i n g

    a nd w hos e e f f i c i e nc y e na b l e s t o s o l ve l a r ge i n s t a nc e s .

    T h e C L P l a ng u a g e u s ed i n t h e a b o v e p r o b l e m s i s c c ( F D ) , a n i n s ta n c e o f

    t h e c c f r a m e w o r k o v e r f i n i t e d o m a i n s t h a t i s b e s t s e e n a s a s u c c es s o r t o t h e

    l I n t h e f o l lo w i n g , w e u s e t h e t e r m CL P la n g u a g e s g e n e r ic a l ly to d e n o t e b o t h C L P a n d c c

    l a n g u a g e s .

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    4/47

    116

    P V a n H e n t e n r y c k e t a l

    finite-domain part of CHIP. Both languages support the use of consistency

    techniques and local propagation in conjunction with don't-know nondeter-

    minism approximated by backtracking. In addition, they support depth-first

    branch and bound for combinatorial optimization problems. The novel as-

    pects of cc(FD) include the definition of new general-purpose combinators

    (such as cardinality, implication, constructive disjunction, and indexical

    constraints) and the availability of constraint entailment and constraint

    generalization as primitive operations on constraints, cc(FD) generalizes

    in an elegant way (and thus makes unnecessary) several features and con-

    straints o f CHIP that were difficult to justify theoretically. As a consequence,

    it provides additional operational expressiveness, flexibility, and efficiency

    and lets us tackle problems such as disjunctions of constraints and the def-

    inition of primitive constraints. Preliminary solutions of the two problems

    described here were first expressed in CHIP (see [60] and [18]). The pre-

    sentation proposed in this paper subsumes them, both in the algorithmic

    methods, which are more advanced, and in the statement, which is simpler,

    more natural, and based on a solid theoretical foundation.

    The rest of the paper is organized as follows. Section 2 presents a tu-

    torial overview of cc(FD). Since the focus here is on applications, this

    overview is limited to those aspects of direct relevance to the two problems

    considered. Important combinators such as constructive disjunctions and

    indexical constraints are omitted here but can be found in [75]. Sections 3

    and 4 present respectively the test generation and car sequencing problems.

    For each application, we describe in detail how the problem can be stated

    and how constraint solving is performed and we also report a number of

    experimental results and comparisons. Section 5 contains our conclusions.

    2 . O v e r v i ew o f c c F D )

    Here we give an informal overview of the relevant parts of cc(FD). A

    more formal presentation, following the style of operational semantics in

    [54], is given in the appendix.

    Our overview proceeds in several steps. Section 2.1 sketches the syntax of

    the language and Section 2.2 introduces the CLP scheme. Sections 2.3, 2.4,

    and 2.5 discuss constraint entailment, the implication combinator, and the

    cardinality combinator, and Section 2.6 discusses the details of constraint

    solving in cc(FD). Note that the presentation separates the generic aspects

    of the language from the details of its constraint solver. This indicates that

    the combinators are general-purpose.

    2 I S y n t a x

    Figure 1 shows an outline of the syntax of a cc(FD) program. A cc(FD)

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    5/47

    ons t ra i n t sa t i sf ac t i on u s i ng CLP 7

    P r o g r a m

    C l a u s e s

    H e a d

    G o a l

    B o d y

    : : C l a u s e s

    : : = H e a d : -

    B o d y I C l a u s e s C l a u s e s

    : :

    A t o m

    : : = A t o m

    : : = t r u e I G o a l I c I B o d y ,

    B o d y I c - -+ B o d y I # ( l , u , [ c . . .. . C n ] )

    Fig. 1.

    An out l ine of the syntax

    p ( X , Y , X ) : -

    E {0 ..... i0}, Y E {0 ..... I0}, Z E {0 ..... i0},

    X t> Z + 3 ,

    Y ~ < Z ,

    q ( X , Y , Z ) .

    q ( X , Y , Z ) : -

    r ( X , Y ) .

    q ( X , Y , Z ) : -

    Z > _ - Y + 2 .

    r ( X , Y ) : -

    X ~ < Y + 2 .

    Fig . 2 . A

    s imple program

    i s a se t o f c la u s e s i n w h i c h e a c h c l a u s e h a s a h e a d a n d a b o d y . A h e a d

    i s a n a t o m , i .e . a n e x p r e s s i o n o f t h e f o r m p tl . . . . . t , ) w h e r e t l . . . . . t , a r e

    t e r m s . A t e r m i s a v a r i a b l e e . g . x ) o r a f u n c t i o n s y m b o l o f a r i ty n a p p l i e d

    t o n t e r m s e .g . f X , g Y ) ) ) . A b o d y i s e i t h er t r u e t h e e m p t y b o d y ) , a

    g o a l p r o c e d u r e c a ll ) , a c o n s t r a i n t c o n s t r a i n t s o l v i n g ) , a n i m p l i c a t i o n , o r

    a c a r d i n a l i t y c o m b i n a t o r . I n t h i s p a p e r , v a r i a b l e s a r e d e n o t e d b y u p p e r c a s e

    l e t te r s , c o n s t r a i n t s b y t h e l e t t e r c , c o n j u n c t i o n s o f c o n s t r a i n t s b y t h e l e t t e r a ,

    t e r m s b y l e t t e r s t a n d s , a t o m s b y l e t t e r s H a n d B , g o a l s b y t h e l e t t e r G , a n d

    i n t e g e r s b y t h e l e t t e r s l , u , a n d v , a l l p o s s i b l y s u b s c r i p t e d o r s u p e r s c r i p t e d .

    W e a l s o u s e C t o d e n o t e a c o n s t r a in t s y s t e m a n d D , p o s s i b l y s u b s c r ip t e d , t o

    d e n o t e a f i n i te d o m a i n . T o i l lu s t ra t e t h e o p e r a t i o n a l s e m a n t i c s o f p a r t o f )

    c c F D ) , w e u s e t h e s i m p l e p r o g r a m d e p i c t e d i n F i g . 2 .

    2 2 T h e C L P s c h e m e

    A t l e a st f r o m a c o n c e p t u a l s t a n d p o i n t , t h e o p e r a t i o n a l s e m a n t i c s o f t h e

    C L P s c h e m e i s a si m p l e g e n e r a l i z a ti o n o f t h e s e m a n t i c s o f l o g i c p r o g ra m -

    m i n g . I t c a n b e d e s c r i b e d a s a g o a l - d i r e c t e d d e r i v a t i o n p r o c e d u r e f r o m t h e

    i n i t i a l g o a l u s i n g t h e p r o g r a m c l a u s e s . A c ompu t t i o n s t t e i s b e s t d e s c r i b e d

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    6/47

    118

    P V a n H e n t e n r y c k e t a l

    b y

    1) a goa l par t: t h e c o n j u n c t i o n o f g o a l s t o b e s o l v e d ;

    ( 2 ) a constraint s tore: t h e s e t o f c o n s t r a i n t s a c c u m u l a t e d s o f a r.

    I n i t i a l l y t h e c o n s t r a i n t s t o r e i s e m p t y a n d t h e g o a l p a r t i s t h e i n i t i a l g o a l .

    I n t h e f o ll o w i n g , w e d e n o t e t h e c o m p u t a t i o n s t a te b y p a ir s ( G [ ] a ) , w h e r e

    G i s t h e g o a l p a r t a n d a i s t h e c o n s t r a i n t s t o r e . W e u s e e t o d e n o t e a n e m p t y

    g o a l p a r t o r c o n s t r a i n t s t o r e . A n e x a m p l e c o m p u t a t i o n s t a t e i s

    (q (X ,Y ,Z ) [] X, Y, Z E {0 ..... 0} ~ X i> Z + 3 ~ Y ~< Z).

    A c o m p u ta t i o n s t e p ( i . e . t h e t r a n s i t i o n f r o m o n e c o m p u t a t i o n s t a t e t o

    a n o t h e r ) c a n b e o f tw o t y p e s d e p e n d i n g u p o n t h e s e le c ti o n o f a n a t o m o r a

    c o n s t r a i n t i n t h e g o a l p a r t . I n t h e f i r s t c a s e , a c o m p u t a t i o n s t e p a m o u n t s t o

    ( 1 ) s e l e c t i n g a n a t o m i n t h e g o a l p a r t ;

    ( 2 ) f i n d i n g a c l a u s e t h a t c a n b e u s e d t o r e s o l v e t h e a t o m ; t h i s c l a u s e

    m u s t h a v e t h e s a m e p r e d i c a t e s y m b o l a s t h e a t o m , a n d t h e e q u a l i t y

    c o n s t r a i n t s b e t w e e n t h e g o a l a n d h e a d a r g u m e n t s m u s t b e c o n s i s t e n t

    w i t h t h e c o n s t r a i n t s t o r e ;

    ( 3 ) d e f i n i n g th e n e w c o m p u t a t i o n s t a t e a s t h e o l d o n e w h e r e t h e s e le c t e d

    a t o m h a s b e e n r e p l a c e d b y t h e b o d y o f th e c l a u se a n d t h e e q u a l i t y

    c o n s t r a i n t s h a v e b e e n a d d e d t o t h e c o n s t r a i n t s t o r e .

    I n t h e s e c o n d c a s e , a c o m p u t a t i o n s t e p a m o u n t s t o

    ( 1 ) s e l e c t i n g a c o n s t r a i n t i n t h e g o a l p a r t t h a t c a n b e s a t i s f i e d w i t h t h e

    c o n s t r a i n t s t o r e ;

    ( 2 ) d e f i n i n g t h e n e w c o m p u t a t i o n s t a t e a s t h e o l d o n e w h e r e t h e s e l e c t e d

    c o n s t r a in t h a s b e e n r e m o v e d f r o m t h e go a l p a r t a n d a d d e d t o t h e

    c o n s t r a i n t s t o r e .

    F o r i n s t a n c e , g i v e n a c o m p u t a t i o n s t a t e

    ( q ( X , V , Z ) [ ] X , Y , Z C { 0 . .. .. 0 } X > i Z + 3 ~ Y ~ < Z )

    a c o m p u t a t i o n s t e p c a n b e p e r f o r m e d u s i n g t h e s e c o n d c l a u se o f q ( s e e

    F i g. 2 ) t o o b t a i n a n e w c o m p u t a t i o n s t a te

    (Z >/ Y + 2 [] X,Y ,Z C {0 ..... 0} ~ X >i Z + 3 ~ Y ~ Z).

    A n o t h e r c o m p u t a t i o n s t ep l e a d s to t h e c o n f i g u r a ti o n

    (e [] X, Y, Z E { 0 ..... 0} X >i Z + 3 Y ~< Z ~ Z >i Y + 2),

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    7/47

    onstraint satisfaction using LP

    1 1 9

    s i n c e t h e r e s u l t i n g c o n s t r a i n t s t o r e i s s a t i s f i a b l e . N o t e t h a t , s t r i c t l y s p e a k i n g ,

    e q u a t i o n s s h o u l d h a v e a p p e a r e d b e t w e e n t h e v a r i a b le s i n t h e a b o v e e x a m p l e ;

    t h e y w e r e o m i t t e d f o r c l a r i t y , s i n c e t h e v a r i a b l e s h a v e t h e s a m e n a m e s i n

    t h e p r o g r a m .

    A s s h o u l d b e c l e a r , t h e b a s i c o p e r a t i o n o f t h e l a n g u a g e a m o u n t s t o d e c i d i n g

    t h e s a t i s fi a b i li ty o f a c o n j u n c t i o n o f c o n s tr a i n ts . N o t e a ls o t h a t e a c h c o m -

    p u t a t i o n s t a t e h a s a s a t i s f i a b l e c o n s t r a i n t s t o r e . T h i s p r o p e r t y i s e x p l o i t e d

    i n s i d e C L P l a n g u a g es t o a v o i d s o l v in g t h e s a t i sf i a b il it y p r o b l e m f r o m s c r a t c h

    a t e a c h s t e p . I n s t e a d , C L P l a n g u a g e s k e e p a r e d u c e d ( e . g . s o l v e d ) f o r m o f

    t h e c o n s t r a i n t s a n d t r a n s f o r m t h e e x i s t i n g s o l u t i o n i n t o a s o l u t i o n i n c l u d i n g

    t h e n e w c o n s t r a i n t s . H e n c e t h e c o n s t r a i n t s o l v e r i s m a d e i n c r e m e n t a l . F o r

    i n s t a n c e , t h e la s t c o n s t r a i n t s t o r e m a y b e r e p r e s e n t e d a s

    ( e [ ]

    x E {s

    . . . .

    1 o } ~ Y E { o

    . . . .

    5} ~

    z E

    { 2

    . . . .

    7 }

    X >_- Z + 3 Y ~< Z ~ Z >~ Y + 2).

    A c o m p u t a t i o n s t a t e i s

    t e rm ina l

    i f

    t h e g o a l p a r t i s e m p t y ;

    n o c l a u s e c a n b e a p p l i e d t o t h e s e le c t e d a t o m t o p r o d u c e a n e w c o m -

    p u t a t i o n s t a te o r t h e s e l e c te d c o n s t r a i n t c a n n o t b e s a t is f i e d w i t h th e

    c o n s t r a i n t s t o re .

    compu ta t ion

    i s s i m p l y a s e q u e n c e o f c o m p u t a t i o n s t e p s t h a t e i t h e r

    e n d s i n a t e r m i n a l c o m p u t a t i o n s t a t e o r d i v e r g e s . A f i n i t e c o m p u t a t i o n

    is

    success fu l

    i f t h e f i n a l c o m p u t a t i o n s t a t e h a s a n e m p t y g o a l, a n d

    f a i l s

    o t h e r w i s e .

    T o i ll u s tr a t e c o m p u t a t i o n s i n a C L P l a n g u a g e, c o n s i d e r o u r s i m p l e p r o g r a m

    a g a in . T h e p r o g r a m h a s o n l y o n e s u c c e s sf u l c o m p u t a t i o n , n a m e l y

    p x , Y , Z ) [ ] e )

    ( s e l e c t i n g t h e f i r s t c o n s t r a i n t )

    ( s e l e c t i n g t h e l a s t c o n s t r a i n t )

    (q( X,Y ,Z) [] X,Y ,Z E {0 ..... 0} X >i Z + 3 Y ~< Z)

    ( u s i n g t h e s e c o n d c l a u s e o f

    f l )

    z > i v + 2 [ ] x , Y , Z E { 0 . . . . . 1 0 } ~ X > I Z + 3 ~ Y ~ < Z )

    ( s e l e c t i n g t h e c o n s t r a i n t )

    (e [] X,Y ,Z E {0 ..... 0} ~ X I> Z + 3 ~ Y ~< Z ~ Z i> Y + 2)

    T h e p r o g r a m h a s a ls o o n e f a i le d c o m p u t a t i o n :

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    8/47

    120

    P V a n H e n t e n r y c k e t a l

    ( p ( X , Y , Z ) [ ] e )

    ( s e l e c t i n g t h e f i r s t c o n s t r a i n t )

    ( s e l e c t i n g t h e l a s t c o n s t r a i n t )

    (q (X ,Y ,Z ) [] X, Y, Z 6 { 0 ..... O} ~ X >_- Z + 3 Y ~< Z)

    ( u s i n g t h e f i r s t c l a u s e o f q )

    (r( X,Y ,Z) [] X,Y ,Z C {0 ..... 0} g X i Z + 3 Y ~ Z>

    ( u s i n g t h e c l a u s e o f r )

    (X ~< Y + 2 [] X,Y ,Z C {0 ..... 0} ~ X >_- Z + 3 g Y ~< Z).

    T h e l a st c o m p u t a t i o n s t a t e i s t e r m i n a l s i n c e t h e c o n j u n c t i o n o f c o n s t r a i n t s

    X ~> Z + 3 & Y ~< Z & X ~< Y + 2

    i s n o t sa t i s f i ab l e .

    N o t e t h a t t h e r e s u l t s o f t h e c o m p u t a t i o n a r e t h e c o n s t r a i n t s t or e s o f t h e

    s u c c e s s f u l c o m p u t a t i o n s . A l s o , n o t h i n g h a s b e e n s a i d s o f a r o n t h e s t r a t e g y

    u s e d t o e x p l o r e th e s p a c e o f c o m p u t a t i o n s . M o s t C L P l a n g u a g e s u s e a

    c o m p u t a t i o n m o d e l s i m i l a r t o P r o lo g : a t o m s a r e s e l e c t ed f r o m l e f t t o r i g ht

    i n t h e c l a u s e s , c l a u s e s a r e t r i e d i n t e x t u a l o r d e r , a n d t h e s e a r c h s p a c e i s

    e x p l o r e d i n a d e p t h - f i r s t m a n n e r w i t h c h r o n o l o g i c a l b a c k t r a c k i n g i n c a s e o f

    f a i l u r e s. 2 F o r i n s t a n c e , o n t h e s i m p l e p r o g r a m , a C L P l a n g u a g e t y p i c a l l y

    u s e s t h e f i r s t c l a u s e f o r p , t h e n t h e f i r s t c l a u s e f o r q , a n d f i n a l l y e n c o u n t e r s

    a f a i l u r e w h e n t r y i n g t o s o l v e r . E x e c u t i o n t h e n b a c k t r a c k s t o t h e s e c o n d

    c l a u s e o f q, g iv i n g t h e s u c c e s s f u l c o m p u t a t i o n .

    2 .3 . Co ns tra in t en ta i lme nt

    A s m e n t i o n e d p r e v io u s ly , t h e c c f r a m e w o r k c o n s i d er s o t h e r o p e r a t io n s o n

    c o n s t r a i n t s b e y o n d c o n s t r a i n t s o l vi n g a s w e l l a s a d d i t i o n a l w a y s o f c o m b i n i n g

    t h e m . A n i m p o r t a n t o p e r a t i o n o n c o n s t ra i n ts is cons tra in t en ta i lment w h i c h

    a m o u n t s t o f i n d i n g o u t i f a s in g le c o n s t r a i n t i s i m p l i e d b y a c o n j u n c t i o n o f

    co n s t ra i n t s , i . e .

    c ~ ( v ) ( a ~ c ) .

    C o n s t r a i n t e n t a i l m e n t w a s i n t r o d u c e d i n t h e c o n t e x t o f c o n c u r r e n t l o gi c

    p r o g r a m m i n g ( e. g. [ 5 8 ] ) b y M a h e r [ 4 3 ] t o e n d o w t h e s e l a n g u a ge s w i t h a

    l o g ic a l s e m a n t i c s . I t c a n b e v i e w e d a s w e l l a s a g e n e r a l i z a t i o n o f l a n g u a g e s

    a l l o w i n g c o r o u t i n i n g a n d d e l a y m e c h a n i s m s ( e .g . [ 1 0 , 1 3 ,1 7 , 2 8 ,4 7 ] ) , a n d i s

    2We see below that the additional combina tors of cc (FD) permit more sophisticated search

    procedures.

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    9/47

    onstraint satisfaction using LP 121

    o n e o f th e c o r n e r s to n e s o f t h e c c f r a m e w o r k , w h e r e i t i s u se d t o s y n c h r o n i z e

    c o n c u r r e n t l y e x e c u t i n g a g e n ts . I t w a s a l s o u s e d i n CH IP ( s e e [ 2 0 , 3 1 ] ) i n s i d e

    t h e

    if then else

    c o n s t r u c t a n d w a s i n s t r u m e n t a l i n s i m u l a t i n g h y b r i d c i r c u it s .

    I ts i n t e r e s t f o r C L P l a n g u a g es l ie s in t h e o p p o r t u n i t y i t g i ve s to r e a s o n a b o u t

    t h e c o n s t r a i n t s a n d t o u s e t h e i n f o r m a t i o n g a i n e d i n p r u n i n g . A s w e w i l l

    s e e , i t c a n b e u s e d t o e x p r e s s n o n - p r i m i t i v e c o n s t r a i n t s f o l l o w i n g g e n e r a l

    p r i n c i p l e s f r o m a r t i f i c i a l i n t e l l i g e n c e a n d o p e r a t i o n s r e s e a r c h .

    B o t h i m p l i c a t i o n a n d c a r d i n a l i t y , t h e t w o c c ( F D ) c o m b i n a t o r s u s e d i n o u r

    a p p l i c a ti o n s , m a k e u s e o f c o n s t r a i n t e n t a i l m e n t . T h e i m p l i c a t i o n c o m b i n a t o r

    w a s i n t r o d u c e d i n [ 5 4 ] i n th e c o n t e x t o f c o n c u r r e n t l og i c p r o g r a m m i n g ,

    w h i l e t h e c a r d i n a l i t y c o m b i n a t o r w a s p r o p o s e d e x p l i c i t l y f o r C L P l a n g u a g e s

    i n [ 7 3 ] .

    2 4 The implicat ion combinator

    Mot iva t ion

    L o c a l p ro p a g a t i o n i s o n e o f t h e k e y i d ea s b e h i n d c o n s t r a in t p r o g r a m m i n g

    l an g u a ge s s u c h a s C O N S T R A I N T S [ 6 6] a n d T h i n g L a b [ 2 ]. L o c a l p r o p a ga -

    t i o n ( o r v a l u e p r o p a g a t i o n ) a m o u n t s t o d e d u c i n g v a l u e s f o r s o m e v a r i a b l e s

    f r o m t h o s e o f o t h e r v a r ia b l e s . F o r i n s t a n c e , a n a n d - g a t e i n a d i g it a l c i r c u i t

    m a y b e d e f i n e d b y r ul es o f th e f o r m

    I f o n e i n p u t i s 0 t h e n t h e o u t p u t is 0 ,

    I f t h e o u t p u t i s 1 t h e n t h e i n p u t s a r e b o t h 1 .

    T o i m p l e m e n t a p r o g r a m a c h i e v i n g t h i s f o r m o f p r o p a g a t i o n , i t is n e c e s s a ry

    t o i n t r o d u c e a f o r m o f d a t a - d r i v e n c o m p u t a t i o n i n w h i c h go a ls a r e s u s-

    p e n d e d w h e n n o t e n o u g h i n f o r m a t i o n is a v ai la b le a n d r e a c t iv a t e d w h e n n e w

    i n f o r m a t i o n a l lo w s t h e m t o b e r e c o n s i d e r e d . T h e p u r p o s e o f t h e i m p l i c a t i o n

    c o m b i n a t o r f o r C L P l a n g u a g es is to a c h i e v e t h is f o r m o f b e h a v i o r , t o g e n -

    e r a l i z e i t t o a n y c o n s t r a i n t s y s t e m , a n d t o c o m b i n e i t w i t h n o n d e t e r m i n i s t i c

    c h o i c e .

    Description

    A s m e n t i o n e d p r e v i o us l y , t h e im p l i c a t io n c o m b i n a t o r h a s th e f o r m c ~ A

    w h e r e c i s a c o n s t r a i n t a n d A i s a b o d y . I t s d e c l a r a t i v e s e m a n t i c s i s s i m p l y

    g i v e n b y l o g i c a l i m p l i c a t i o n .

    T h e m a i n o r i g i n a li t y o f t h e i m p l i c a t i o n c o m b i n a t o r l ie s in i t s o p e r a t i o n a l

    s e m a n t i c s . T h e i m p l i c a t i o n c ~ A e n s u r e s th a t A is e x e c u t e d o n l y w h e n

    ( a n d a s s o o n a s ) c is e n t a i l e d b y t h e c o n s t r a i n t s t o r e . I n o t h e r w o r d s , i f c is

    e n t a i l e d b y t h e c o n s t r a i n t s t o r e , c ~ A r e d u c e s t o A . I f -~ c i s e n t a i l e d b y t h e

    c o n s t r a i n t s t o r e , c ~ A r e d u c e s t o true O t h e r w i s e , t h e c o m p u t a t i o n b l o c k s ,

    w a i t in g f o r m o r e i n f o r m a t i o n .

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    10/47

    122

    P V a n H e n t e n r y c k e t a l

    C o n s i d e r a g a i n t h e d e s c r i p t i o n o f a n a n d - g a t e u s i n g lo c a l p r o p a g a t i o n

    t e c h n i q u e s :

    n d X , Y , Z ) : -

    X = 0 --+ Z = 0 ,

    Y = O - + Z = O ,

    Z = I --* X = I , Y = i) ,

    X = I - + Y = Z ,

    Y = I - + X = Z ,

    X = y --+ X = Z.

    T h e f i r s t r u l e s a y s th a t , a s s o o n a s t h e c o n s t r a i n t s t o r e e n t a i l s x = 0 , t h e

    c o n s t r a i n t z = 0 m u s t b e a d d e d t o t h e c o n s t r a i n t s t o r e . N o t e t h a t t h e l a s t

    t h r e e r u le s a c t u a ll y d o m o r e t h a n l o c a l v a l u e p r o p a g a t i o n ; t h e y a l so p r o p a g a t e

    s y m b o l i c e q u a l i t i es a n d o n e o f t h e m is c o n d i t i o n a l t o a s y m b o l i c e q u a l it y .

    N o w t h e g o al ( a n d ( X , Y , Z ) [ ] X = O) p r o d u c e s a c o n s t r a i n t s t o r e x = o t z --

    0 , s i n c e t h e g o a l ( x = 0 --+ z = o [ ] x = 0 ) r e d u c e s t o ( z ,, 0 [ ] x = o ) a n d

    h e n c e t o t h e c o n s t r a i n t s t o r e x = 0 ~ z = 0 . H o w e v e r t h e g o a l ( ~ m d (X , Y ,Z )

    [ ] e ) d o e s n o t m o d i f y t h e c o n s t r a i n t s t o r e , s i n c e n o n e o f t h e c o n s t r a i n t s i n

    t h e i m p l i c a t i o n c o n s t r u c t s a r e e n ta i l e d b y t h e c o n s t r a i n t s to r e .

    A s m e n t i o n e d p r e v i o u s l y , a g o a l t h a t is b l o c k e d c a n b e r e s u m e d w h e n n e w

    i n f o r m a t i o n b e c o m e a v a i l a b l e in th e c o n s t r a i n t s t o r e. A s s u m e f o r i n s t a n c e

    t h e c o m p u t a t i o n s t a t e

    < X = 0 - ~ Z = 0 , T = 0 - + X = 0 [ ] T = 0 ) .

    T h e f i r s t g o a l x = 0 ~ z = 0 b l o c k s s i n c e x = o i s n o t e n t a i l e d b y t h e c o n -

    s t r a i n t s t o r e . B u t t h e s e c o n d g o a l c a n b e e x e c u t e d , l e a d i n g e v e n t u a l l y t o th e

    c o m p u t a t i o n s t a t e

    (X = 0 --+ Z = 0 [] X = 0 & T = 0) .

    N o w x = o is e n t a i l e d b y t h e c o n s t r a i n t s t o r e a n d h e n c e t h e f i rs t i m p l i c a t i o n

    c a n b e e x e c u t e d . T h e f i n a l c o n s t r a i n t s t o r e w i l l b e x = 0 t T = 0 t Z = 0 .

    N o w c o n s i d e r b u i l d i n g a f u l l - a d d e r u s i n g l o g i c a l g a t e s:

    f a X , Y , C i n , S , C ) : -

    ~ n d X , Y , C l ) ,

    x o r X , Y , S l ) ,

    a n d t i n , S I , C 2 ) ,

    x o r C i n , S i , S ) ,

    o r C I , C 2 , C ) .

    I n t h e a b o v e c i r c u i t , x a n d Y a r e t w o i n p u t b i t s , C i n i s t h e c a r r y - i n , s i s t h e

    r e s u lt b i t, a n d c i s t h e c a r r y - o u t . I f w e u s e t h e i m p l i c a t i o n c o m b i n a t o r t o

    d e f i n e a l l l o g i c a l g a t e s , t h e q u e r y f a ( X , V , 1 , s , o ) p r o d u c e s t h e c o n s t r a i n t s t o r e

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    11/47

    onstraint satisfaction using LP 123

    X = 0 & Y = 0 & S = I .

    T h e r e a s o n i s t h e f o l l o w i n g . S i n c e t h e r e s u l t o f t h e o r - g a t e i s 0, i ts t w o i n p u t s

    c l a n d c 2 m u s t b e 0 . S i n c e t h e s e c o n d a n d - g a t e h a s o u t p u t c 2 e q u a l t o 0 a n d

    i n p u t t i n e q u a l t o 1 , i t f o l l o w s t h a t S l m u s t b e 0 , w h i c h i m p l i e s t h a t x a n d

    Y m u s t b e e q u a l b e c a u s e o f t h e f i r s t xo r - g at e . S i n c e x a n d v a p p e a r b o t h a s

    i n p u t s i n t h e s a m e a n d - g a t e , t h e y m u s t b e e q u a l t o i t s o u t p u t C l, w h i c h i s 0.

    T h e i m p l i c a t io n c o m b i n a t o r t h u s i n t ro d u c e s a n o t i o n o f c o r o u t in i n g b e-

    t w e e n g o a ls i n t h e l a n g u a g e , a n d t h e e x e c u t i o n o f g o a ls c a n b e i n t e r l e a v e d

    i n c o m p l e x w a y s. N o t e t h a t th e g oa ls s y n c h r o n i z e b y a s k i n g i f s o m e c o n -

    s t r a i n t s a r e e n t a i l e d b y t h e c o n s t r a i n t s t o r e a n d t h a t a s u s p e n d e d g o a l c a n

    b e r e s u m e d b y a m o d i f i c a t i o n o f th e c o n s t r a i n t s t o re b y o t h e r g oa ls . M o r e -

    o v e r , t h e i m p l i c a t i o n c o m b i n a t o r i s n o t r e s t r i c t e d to s i m p l e c o n s t r a i n t s , a s

    i l l u s t r a t e d a b o v e , b u t a l l o w s a r b i t r a r y c o n s t r a i n t s o f t h e l a n g u a g e .

    2 5 The card ina li ty combina tor

    Mot iva t ion

    T h e c a r d i n a l i t y c o m b i n a t o r i s a d e c l a r a t i v e a n d r e l a t i o n a l o p e r a t o r , i n -

    t e n d e d f o r t h e h a n d l i n g o f g e n e r al f o r m s o f d i sj u n c ti o n s w h i c h o f t e n o c c u r

    i n p r a c t i c a l a p p li c a t io n s . I t c a n b e u s e d t o e n f o r c e a r c - c o n s i s t e n c y o n a n y

    a r b i t ra r y f i n i t e - d o m a i n c o n s t r a i n ts ( w i t h in t h e c o m p l e x i ty b o u n d o f t h e o p -

    t i m a l a l g o r i t h m o f [ 4 4 ] ) b u t , a s s h o u l d b e c l e a r f r o m t h e p r e s e n t a t i o n , i t

    i s n o t l i m i t e d t o f i n i t e - d o m a i n c o n s t r a i n t s . T h e c a r d i n a l i t y h a s b e e n u s e d

    i n n u m e r o u s a p p l i c a t i o n s i n c l u d i n g s c h e d u l i n g , a s s i g n m e n t , H a m i l t o n i a n

    c i r c u i t , a n d w a r e h o u s e l o c a t i o n p r o b l e m s . I t w i l l b e i m p o r t a n t i n t h e c a r

    s e q u e n c i n g a p p l i c a ti o n .

    B e f o r e e n t e r i n g i n t o t h e d e s c r i p t i o n o f th e c o m b i n a t o r , l e t u s g iv e a n

    e x a m p l e to m o t i v a t e t h e r e a d e r . C o n s i d e r , f o r i n s ta n c e , a s c h e d u l i n g p r o b l e m

    a n d a s s u m e t h a t w e f a c e a d i s j u n c t i v e c o n s t r a i n t b e t w e e n t w o t a s k s , i . e . t h e

    e x e c u t i o n o f t h e t w o t a s k s c a n n o t o v e r l a p . A s s u m e th a t s l a n d s 2 r e p r e s e n t

    t h e s t a r t i n g d a t e s o f t h e t a s k s a n d D1 a n d D2 t h e i r d u r a t i o n s , t h e c o n s t r a i n t

    c a n b e e x p r e s s e d a s

    d i s j u n c t i v e ( SI , D I, S 2 , D 2 ) : -

    S 1 + D 1 ~ 2 .

    d i s j u n c t i v e ( S l , D I, 2 , D 2 ) : -

    S2 + D2 ~< I.

    U n f o r t u n a t e l y t h e a b o v e c o n s t r a in t i s n o n d e t e r m i n i s t i c a n d i n t ro d u c e s c h o i c e

    p o i n t s d u r i n g t h e e x e c u t i o n . T h e f i r s t a l t e r n a t i v e , i . e . t h e s e c o n d t a s k i s

    s c h e d u l e d a f t e r t h e f i r s t t a s k , w i l l b e s e l e c t e d a n d i t s c o n s t r a i n t w i l l b e

    a d d e d t o t h e c o n s t r a i n t s t o r e . S u b s e q u e n t e x e c u t i o n m a y l e a d t o a f a i l u r e

    a n d r e q u i r e t h i s c h o i c e to b e r e c o n s i d e r e d . T h e s e c o n d a l t e r n a t i v e , i. e. t h e

    f i r s t t a s k i s s c h e d u l e d a f t e r t h e s e c o n d t a s k , w i l l t h e n b e c o n s i d e r e d . I n

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    12/47

    124 P V a n H e n t e n r y c k e t a l

    general, it is better to postpone choices as long as possible. The above con-

    straint can be used in two ways to achieve pruning: (1) if the maximal start

    date of s2 is smaller than the minimal start date of Sl added to D1, then the

    second task cannot be scheduled after the first task and (2) if the maximal

    start date of Sl is smaller than the minimal start date of s2 added to D2,

    then the first task cannot be scheduled after the second task. The cardinality

    combinator enables us to express this pruning in a natural way.

    Descr ip t ion

    As mentioned previously, the cardinality combinator has the form

    ( l , u , [ cl . . . . ,cn] )

    where l and u are integers and cl . . . . . c, are constraints.

    The declarative semantics is given as follows. #(l, u , [ca , . . . , cn ]) is true

    iff the number of constraints ci (1 ~ i ~ n) satisfiable is not less than l

    and not more than u. It is false otherwise.

    Note that this combinator is quite expressive. A conjunction cl A... A

    c, can be expressed as #(n,,, [ C l , ' , c n ] ) where is a don't-care value,

    a disjunction Cl v ... v

    cn

    as #( 1, , , [cl . . . . .

    cn]) ,

    and a negation -~c as

    # ( , , 0, [c l). Other connectives such as equivalence ~ can now be obtained

    easily. In the applications, we feel free to use the logical operators instead

    of the cardinality combinator when convenient.

    Using the cardinality combinator, the disjunctive constraint can be im-

    plemented as follows:

    d i s j u n c t i o n ( S l , D I , S 2 , D 2 ) : -

    ( I , * , [ S l + D 1 ~ S 2 , S 2 + D 2 ~ < S l ] ) .

    Once again, the main interest of the cardinality combinator lies in its

    operational semantics. The combinator implements a principle well known

    in operations research and artificial intelligence: infer simple constraints

    from difficult ones . The intuitive idea is to make sure that the cardinality

    combinator can be satisfied in some way. Moreover, if there is only one

    way to satisfy it, then the constraints necessary to satisfy it are introduced

    in the constraint store. Constraint entailment is used to check if there is a

    way to satisfy the constraint. In the disjunctive example, the system makes

    sure that either the first task can be scheduled before the second one or the

    second task can be scheduled before the first one (or both). If the constraint

    store makes it impossible to schedule the first task before the second, then

    a constraint forcing the second task to be scheduled first is added to the

    constraint store.

    Consider a simple example:

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    13/47

    ons tra in t sa t is fac tion us ing LP 125

    ( # ( 1 , 2 , [ x = 4 , Y - t o ] ) ~ x> 6 [ ] e )

    ( # ( 1 , 2 , [ x = 4 , Y = lO ] ) [] x > 6)

    ( # ( 1 , 2 , [ Y = 1 o 1 ) [ ] x > 6)

    1

    X>6 & Y=IO

    T h i s e x a m p l e c o n t a i n s a c a r d i n a l it y c o m b i n a t o r r e q u i r i n g t h a t x = 4 o r

    Y = 1 0 b e t r u e . I n i t i a l l y n e i t h e r t h e s e t w o c o n s t r a i n t s n o r t h e i r n e g a t i o n s

    a r e e n t a i l e d b y t h e c o n s t r a i n t s t o re , s o t h e e x e c u t i o n o f t h e c a r d i n a l i t y

    c o m b i n a t o r b l o c k s . T h e s e c o n d g o a l x > 6 i s se l e c te d , w h i c h i m p l i e s t h a t

    x ~ 4 i s e n t a i l e d b y t h e c o n s t r a i n t s t o re . T h e r e i s n o w o n l y o n e w a y t o

    s a t i s f y t h e c a r d i n a l i t y c o m b i n a t o r , i .e . a d d i n g t h e c o n s t r a i n t Y = 1 0 t o t h e

    c o n s t r a i n t s t o r e .

    T h e c a r d i n a l i t y c o m b i n a t o r c a n b e u s e d t o e n f o r c e a r c - c o n s i s t e n c y o n a n y

    b i n a r y c o n s t r a in t i n t i m e O ( e d 2 ) , w h e r e e i s t h e n u m b e r o f c o n s tr a i n ts a n d

    d i s t h e s i z e o f t h e l a r g es t d o m a i n . G i v e n a c o n s t r a i n t c X, Y) w i t h X ~ Dx

    a n d Y e B y , i t i s s u f f i c i e n t t o g e n e r a t e f o r e a c h v a l u e v E Dx a c o n s t r a i n t

    o f th e f o r m

    X= v ** YE D

    w h e r e D = {w ~ Dy I c v, w) } a n d v i c e v e r s a f o r Y . T h e e q u i v a l e n c e c a n

    b e r e w r i t t e n e a s i l y i n t o t w o c a r d i n a l i t y f o r m u l a s . T h e o p t i m a l b o u n d s o f

    M o h r a n d H e n d e r s o n [ 4 4 ] c a n b e o b t a i n e d b y u s in g c o u n te r s t o im p l e m e n t

    c a r d i n a l i t y a n d e n t a i l m e n t .

    2.6. Constraint system

    H e r e w e g i ve a n i n f o r m a l p r e s e n t a t i o n o f t h e c o n s t r a in t p a r t o f c c ( F D ) .

    Syntax

    D e f i n i t i o n 2 . 1 . A n a r i t h m e t i c t e r m i s d e f i n e d i n d u c t i v e l y a s f o l l o w s :

    ( 1 ) A v a r i a b l e i s a n a r i t h m e t i c t e r m .

    ( 2 ) A n a t u r a l n u m b e r i s a n a r i t h m e t i c t e r m .

    ( 3 ) t l + t 2, t l , t2 , a n d t l - t2 a r e a r i t h m e t i c t e r m s i f t l a n d t2 a r e a r i t h m e t i c

    t e r m s .

    T h e p r i m i t i v e c o n s t r a i n t s o f t h e l a n g u a g e a r e a s f o l lo w s :

    D e f i n i t io n 2 .2 . A p r i m i t i v e c o n s t r a i n t i n c c ( F D ) c a n b e o f t w o f o r m s :

    (1) x ~x {vl . . . . . Vn}

    ( 2 ) t 1 ~2 t2,

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    14/47

    126

    P V a n H e n t e n r y c k e t a l

    w h e re x i s a v a r i a b l e , 'u I

    . . . .

    'un a r e n a t u r a l n u m b e r s , 81 ~ { ~ , ~ } , t l a n d t2

    a r e a r i t h m e t i c t e r m s , a n d 82 ~ { > , > i, = , # , ~

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    15/47

    ons tra in t sa t is fac tion us ing LP

    127

    d i v i de t he p r i m i t i ve c o ns t r a i n t s i n t o t w o c la ss es : ( 1 ) ba s i c c ons t r a i n t s ( t hos e

    a l lo w i n g a n e f fi c i en t d e c i s i o n p r o c e d u r e ) a n d ( 2 ) n o n - b a s i c co n s t r a i n t s

    d e f i n e d i n t e r m s o f t h e c o m b i n a t o r s . 3 T h e m a i n b e n e f i t o f i n v e s t ig a t i n g t h e

    f o r m a l s e m a n t i c s h as b e e n t h e i d e n t if i c at i o n o f a n u m b e r o f n e w c o m b i n a t o r s

    ( e. g. c o n s t r u c t i v e d i s j u n c t i o n a n d i n d e x i c a l c o n s t r a i n t s ) t h a t s u p p o r t , a t t h e

    l a n g u a g e le v el , p r u n i n g p r i n c i p l e s p r e v i o u s l y h i d d e n i n t h e i m p l e m e n t a t i o n .

    3. Test pattern generation

    T he f i r s t a pp l i c a t i on w e c ons i de r i s i n t he f i e l d o f d i g i t a l c i r c u i t de s i gn :

    a u t o m a t i c t e s t - p a t te r n g e n e r a t i o n ( A T P G ) . P r o b l e m s f r o m c i r c u it d e s i g n a r e

    u s e f u l i n e v a l u a t i n g g e n e r a l p r o b l e m s o l v in g t e c h n i q u e s , s i n c e m a n y s p e ci al -

    p u r p o s e m e t h o d s h a v e b e e n d e v e l o p e d i n t h is a r e a a n d d i f fe r en t a p p r o a c h es

    c a n b e c o m p a r e d , u s i n g w i d e l y a v a i l a b l e b e n c h m a r k s . C L P i n g e n e r a l , a n d

    C H I P i n p a rt ic u l ar , h a v e b e e n a p p l i e d to a n u m b e r o f p r o b l em s f r o m

    d i g i t a l c i r c u i t de s i gn , i nc l ud i ng f o r m a l ve r i f i c a t i on [ 65 ] , d i a gn os i s [ 63 ] ,

    s y n t h e s is [ 6 4 ] a s w e l l a s s i m u l a t i o n o f h y b r i d c i r c u i ts [ 3 1 ] . T h e u s e o f

    C L P f o r te s t g e n e r a t i o n h a s b e e n d i s c u s s e d b e f o r e [ 5 9 , 6 0 ,6 2 ] . T h e m e t h o d

    d e s c r i b e d h e re is b a s e d o n [ 6 1 ] . W e s h o w t h a t c c ( F D ) a ll o w s a s i m p l e

    a n d d e c l a r a ti v e f o r m u l a t i o n o f te s t g e n e r a t i o n a s a c o n s t r a i n t s a t is f a c ti o n

    p r o b l e m . M o r e o v e r , b y u s i n g t h e i m p l i c a t i o n o p e r a t o r t o d e f i n e d e m o n s , i t is

    pos s i b l e t o de s i gn a n e f f i c i c n t t e s t ge ne r a t i on a l go r i t hm t ha t r e qu i r e s on l y a

    f r a c t io n o f th e d e v e l o p m e n t e f fo r t n e c e ss a r y w i t h c o n v e n t i o n a l a p p r o a c h e s .

    3 . 1 . P r o b l e m s t a t e m e n t

    V L S I c h i p s a re p r o d u c e d b y c o m p l e x p r o c es s e s i n w h i c h e r ro r s c a n a r i se ,

    he n c e on l y a c e r t a i n pe r c e n t a ge o f c h i p s w i ll be e r r o r f re e . T h i s

    y i e l d

    va r i e s

    w i t h d i f f e r e n t c i r c u i t t ype s a nd p r oc e s s e s , bu t c a n be a s low a s a f e w pe r c e n t

    f o r a n e w f a b r i c a t i o n p r o c e s s . T h e m a n u f a c t u r e r , o n t h e o t h e r h a n d , w a n t s

    t o s e l l c h i p s w i t h a l ow

    defect level

    i . e . a l ow pe r c e n t a ge o f f a u l t y c h i p s

    pa s s i ng qua l i t y c on t r o l .

    T e s t g e n e r a t i o n

    i s t he p r oc e s s o f de f i n i ng t he t e s t s

    t o a pp l y t o a c i r c u i t i n o r de r t o de t e c t s f a u l t s . W i l l i a m s [ 78 ] ha s p r e s e n t e d

    a m o d e l e x p r e s si n g t h e d e f e c t le v e l a s a f u n c t i o n o f y i e l d a n d

    f au l t coverage

    t h e p e r c e n t a g e o f a ll f a u l ts d e t e c t e d b y t e st in g . T h i s m o d e l m a k e s c l e a r t h e

    ne c e s s i t y o f f i nd i n g a ve r y h i g h pe r c e n t a ge o f al l f a u l t s in o r de r t o o b t a i n a

    l ow de f e c t l e ve l f o r a p r oc e s s w i t h a l ow y i e l d .

    3 T h e s e c o n s t r a i n t s n e e d n o t b e c o n s i d e r e d p r i m i t i v e c o n s t r a i n t s i n t h e l a n g u a g e , s i n c e t h e y

    c a n b e d e f i n e d a t t h e l a n g u a g e l e v e l .

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    16/47

    128

    P. Van Henten ryck et al.

    7 .1 .1 . F au l t mod e l s

    S i n c e m a n y d i f f e r e n t p h y s i c a l f a i l u r e s c a n o c c u r i n a c i r c u i t , t h e o n l y

    w a y t o t e s t f o r a l l p o s s i b l e f a u l t s i s t o t e s t a l l c i r c u i t b e h a v i o r s o v e r t i m e ,

    w h i c h i s c l e a r l y i m p r a c t i c a l . T h e p r i n c i p a l i d e a o f

    s t ruc tura l t e s t i ng

    i s to use

    k n o w l e d g e a b o u t t h e s t r u c t u re o f a c ir c u i t a n d t h e u n d e r l y i n g t e c h n o l o g y

    t o l i m it t h e n u m b e r o f c a se s w e h a v e t o c o n si d e r. T h e r e h a v e b e e n m a n y

    a t t e m p t s t o d e s c r i b e w h a t t y p e s o f f a u l ts c a n o c c u r i n d i f f e re n t t e c h n o l o g i e s

    [ 1 ] . O n e o f t h e e a r l ie s t a n d s ti ll w i d e l y u s e d f a u l t m o d e l s is t h e s t u c k - a t

    m o d e l . T h i s a s s u m e s t h a t a l l f a u l t s l e a d t o t h e s i t u a t i o n w h e r e s o m e s i g n a l

    i n a c i r c u i t i s p e r m a n e n t l y s e t t o 1 o r 0 . T h e s i g na l i s t h e n s a i d t o

    b e s t u c k - a t 1 ( s a l ) o r s t u c k - a t 0 ( s a 0 ). T h i s f a u l t m o d e l c o v e r s m a n y ,

    t h o u g h n o t a l l , d e v i c e f a u l t s i n s i d e a V L S I c i r c u i t . I t h a s b e e n s h o w n t h a t

    a t e s t s e t t h a t d e t e c t s a l l s i n g l e s t u c k - a t f a u l t s a l s o c o v e r s m a n y o t h e r f a u l t s

    ( w i t h t h e e x c e p t i o n o f t i m e - s e n s i t i v e f a u l t s ). M o s t t e s t g e n e r a t i o n s y s t e m s

    r e s t r i c t t h e m s e l v e s t o t h e d e t e c t i o n o f s i n g le s t u c k - a t f a u l t s a t t h e l o g ic a l g a t e

    l e v e l . W e w i l l u s e t h i s m o d e l a n d , i n t h e r e s t o f t h e s e c t i o n ,

    f au l t coverage

    s h o u l d b e u n d e r s t o o d a s t h e p e r c e n t a g e o f al l d e t e c t e d s in g l e s tu c k - a t e r ro r s.

    N o t e a l s o t h a t t e s t i n g f o r s t u c k - a t f a u l t s i n a c i r c u i t d o e s n o t r e q u i r e

    g e n e r a t i n g t e s t s f o r e a c h f a u l t , a s s o m e f a u l t s a r e

    covered

    b y o t h e r f a u l t s

    [ 5 1 ] . F o r i n s ta n c e , t e s ti n g t h e o u t p u t o f a n a n d - g a t e f o r saO a u t o m a t i c a l l y

    t e s t s t h e g a t e i n p u t s f o r s a 0 . W e c a n e a s i l y g e n e r a t e t h i s m o r e i n t e r e s t i n g

    co l lapsed fau l t se t i n a p r e p r o c e s s i n g s t e p .

    3 .1 .2 . Tes t genera t ion and fau l t s imu la t io n

    T h e A T P G p r o b l e m i s c o n c e p t u a l ly s p li t in t o t w o s u b p r o b l e m s : test gener-

    a t ion

    a n d

    f a u l t s i m u l a t i o n . T e s t g e n e r a t io n

    e n t a i l s f i n d i n g a t e s t t h a t d e t e c t s

    a c e r t a i n f a u l t f o r s o m e c o m p o n e n t i n s i d e t h e c i r c u i t ; f a u l t s i m u l a t i o n d e -

    t e c t s w h i c h f a u l t s a r e c o v e r e d b y a p a r t i c u l a r p a t t e r n . O f t e n t h e t w o p a r t s

    a r e i n t e r t w i n e d a n d t h e w h o l e p r o c e s s t e r m i n a t e s w h e n e i t h e r a p r e s e t f a u l t

    c o v e r a g e i s o b t a i n e d o r a t i m e l i m i t i s e x c e e d e d . T h e p r e s e n t a t i o n h e r e i s

    r e s t r i c te d t o t h e t e s t g e n e r a t i o n p h a s e , w h i c h t y p i c a l ly c o n s is t s o f th r e e s t e p s

    [ 3 ] :

    Setup: T o t e s t a f a u l t a t t h e o u t p u t o f a c e r t a i n g a t e , it is n e c e s s a r y t o

    e n s u r e d i f f e r e n t b e h a v i o r f o r t h e g o o d a n d f a u l t y c i rc u i t s f o r th i s s i gn a l.

    T h i s c a n b e a c h i e v e d b y

    con t ro l l i ng the ga te

    i . e . b y a p p l y i n g c e r t a i n

    s i g n a ls t o t h e i n p u t s o f t h e g a t e . F o r i n s t a n c e , t e s t i n g a n a n d - g a t e f o r

    a s t u c k - a t - z e r o f a u l t r e q u i r e s u s t o s e t b o t h i n p u t s o f t h e g a t e t o 1 .

    Propagat ion:

    I t i s c l e a r l y n o t e n o u g h t o c r e a t e a n i n t e r n a l d i f f e r e n c e

    b e t w e e n t h e b e h a v i o r o f t h e g o o d a n d t h e f a u l t y c i r cu i t. T h i s d i f f e r e n c e

    m u s t b e

    observab le

    a t s o m e o u t p u t o f t h e c i rc u i t. T h e p r o p a g a t i o n s t e p

    c r e a t e s a

    s e n s i t i z e d p a t h

    f r o m t h e g a t e u n d e r t e s t t o s o m e c i r c u i t

    o u t p u t . I n g e n e r a l , o n e o r s e v e ra l s y m b o l i c v a l u e s ar e i n t r o d u c e d a n d

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    17/47

    ons tra in t sa t is fac tion us ing LP

    129

    the propagation step amounts to propagating these symbolic values

    towards the primary outputs. The symbolic values represent the value

    or the negation of the value at the gate under test and indicate where

    the result of the test can be observed.

    Just i f ica t ion:

    The last step assigns values to all signals in the circuit in

    order to satisfy the conditions enforced by the setup and propagation

    steps. Generating a test basically amounts to finding an assignment

    of values for each of the primary inputs, that satisfies the constraints

    imposed by the setup and propagation steps on the signals throughout

    the circuit.

    How these steps are implemented makes the difference between the various

    test generation algorithms.

    3 2 P r o b l e m s o l u t io n

    In this section, we present the test generation program in cc(FD). We

    proceed in several steps. Section 3.2.1 discusses how circuits can be repre-

    sented in logic programming. Section 3.2.2 shows how ATPG can be seen

    as a constraint satisfaction problem. Section 3.2.3 shows how to implement

    the basic elements as demons using the implication operator. Section 3.2.4

    presents the basic test generation program, and Section 3.2.5 shows how

    heuristics can improve the algorithm efficiency.

    3 2 I C i rcu i t descr ip t i on

    Logic programming can be considered as a simple but powerful hardware

    description language. It supports in a natural way top-down development

    and mixing of various hierarchical levels of circuit description. In logic

    programming, a circuit can be specified by means of c lauses that describe

    components and modules and the interactions between them. A general

    description of a full-adder can be given as follows:

    f a M , N , X , Y , Z , S , C ) : -

    a n d M , [ I i N] , X , Y , C l ) ,

    x o r M , [ 2 1 N ] , X , Y , S I ) ,

    f a n o u t M , [ S I N ] , S I , S I I , S 1 2 ) ,

    a n d M , [ 4 i N ] , Z , S I I , C 2 ) ,

    xor(M, [5IN] ,Z ,S t2, S) ,

    o r M , [ 6 I N ] , C l , C 2 , C ) .

    For simulation, the definition of the basic elements and, xor, and or can be

    given by a set of ground clauses (the truth table definition). For instance,

    an and-gate can be expressed as

    a n d s i m u l , N , O , O , O ) .

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    18/47

    130

    P V a n H e n t e n ~ c k e t a l

    and(simul,N,O,l,O).

    and(simul,N,l,O,O).

    and(simul,N,l,l,1).

    H e r e t h e fi r st a r g u m e n t c o n t a i n s t h e o p e r a t i o n m o d e ( f o r i n s ta n c e , t e s t

    f o r t e s t g e n e r a t i o n , s i m u l f o r c i r c u i t s i m u l a t i o n o r t i m e f o r d e l a y t i m e

    c o m p u t a t i o n ) t o d i s ti n g u is h b e t w e e n s e v e r a l u s e r -d e f i n e d o p e r a t io n m o d e s .

    T h e s e c o n d a r g u m e n t a s s i g n s a u n i q u e i d e n t i f i e r t o e a c h p a r t ( m o d u l e o r

    b a s i c c o m p o n e n t ) o f t h e c ir c u i t. T h u s a h i e r a r c h ic a l n a m i n g c o n v e n t i o n c a n

    b e e a s i l y i m p l e m e n t e d . T h e o t h e r a r g u m e n t s a r e t h e i n p u t s a n d o u t p u t s o f

    t h e c o m p o n e n t s . N o t e t h a t n o d i s t in c t i o n i s n e c e s s a r y b e t w e e n i n p u t s a n d

    o u t p u t s . M u l t i p le i n t e rn a l c o n n e c t i o n s b e t w e e n c o m p o n e n t s a r e r e p r e se n t e d

    b y

    f a n o u t p o i n t s ,

    s i n c e t h e y a r e o f s p e c i a l i n t e r e s t i n t e s t g e n e r a t i o n . I n

    p r e v i o u s e x a m p l e s ( s e e S e c t i o n 2 .5 ) , c o n n e c t i o n s w e r e r e p r e s e n t e d b y sh a r e d

    l o g i c a l v a r i a b l e s .

    T h e f u l l - a d d e r c a n n o w b e u s e d i n o t h e r c i r c u i t d e s c r i p t i o n s a n d p a r a m e -

    t e r i z e d l i b ra r i e s o f m o d u l e s c a n b e g e n e r a t e d u s i n g h ie r a r c h i c al d e s c r i p t i o n s .

    T h i s k i n d o f h i e ra r c h i c a l d e s c r i p t i o n o f c i rc u i t s f o l lo w s t h e s t y l e o f lo g i c

    p r o g r a m m i n g i n to p - c l o w n d e v e l o p m e n t : o n e c a n r e p l a c e t h e d e s c r i p t i o n

    o f a lo w e r - l e v e l c o m p o n e n t w i t h o u t a f f e c ti n g t h e h i g h e r -l e v e l c i r cu i t d e f -

    i n i t i o n . T h e s a m e c i r c u i t d e s c r i p t i o n c a n b e u s e d i n v a r i o u s a p p l i c a t i o n s

    i n c l u d i n g s i m u l a t i o n , f o r m a l v e r i f i c a t i o n a n d f a u l t d i a g n o s i s ( s e e [ 6 2 ] ) .

    S i m i l a r w a y s o f d e s c r i b i n g h a r d w a r e i n l o g ic p r o g r a m m i n g a r e r e p o r t e d i n

    [ 1 1 , 2 2 , 3 2 , 3 3 , 6 8 ] .

    3 .2 .2 . ATPG as a cons t ra in t sa t i s fac t ion prob lem

    O u r s t r a t e g y is b a s e d o n t r e a t i n g t h e t e s t g e n e r a t i o n p r o b l e m a s a c o n s i s t e n t

    l a b e l i n g p r o b l e m . W e u s e s i x s y m b o l i c v a l u e s , 0 , 1 , d , ~ o t , e , a n d e n o t . T h e

    v a l u e s d a n d e r e p r e s e n t t h e v a l u e a t t h e g a t e u n d e r t e s t w h i l e

    d n o t

    a n d

    e n o t

    r e p r e s e n t t h e i r n e g a t i o n s. T h e b a s i c d i ff e r e n c e b e t w e e n d, dnot , a n d e , e n o t

    i s i n t h e w a y t h e s e v a l u e s a r e p r o p a g a t e d , d i s a s s i g n e d t o t h e g a te u n d e r

    t e s t a n d t h e g o a l o f t e s t g e n e r a t i o n i s t o p r o p a g a t e d o r

    d n o t

    t o a p r i m a r y

    o u t p u t s o t h a t t h e g a t e c a n b e o b s e r v e d . O n c e a t e s t h a s b e e n f o u n d , i t i s

    s u f f i c ie n t t o r u n t h e c i r c u i t w i t h t h e t e s t a n d t o o b s e r v e t h e v a l u e o f t h e

    g a t e a t a s u i t a b l e p r i m a r y o u t p u t . T h e v a l u e s e a n d

    e n o t

    a r e i n t r o d u c e d

    b e c a u s e o f f a n o u t p o i n t s : w i t h o u t t h e v a l u e s e a n d enot , a f a n o u t p o i n t

    w o u l d n e e d t o p r o p a g a t e a d o r

    d n o t

    v a l u e t o a l l o u t p u t s . S i n c e t h e v a l u e s d

    a n d

    d n o t

    i m p o s e s e v e r e c o n s t r a i n t s o n t h e g a t e s i n o r d e r t o p r o p a g a t e t h e m

    t o w a r d s t h e p r i m a r y o u t p u t s , t h e a l g o r i t h m m a y b e u n a b l e t o f i n d a t e s t i n

    s o m e c a s e s . W i t h t h e v a l u e s e a n d

    enot ,

    a f a n o u t p o i n t p r o p a g a t e s a d ( o r

    a dno t

    o n o n e o u t p u t a n d a n e ( o r a n

    e n o t

    o n t h e o t h e r o u t p u t s . S i n c e

    i t d e v o t e s n o e f f o r t t o p r o p a g a t i n g e a n d enot , t h e a l g o r i t h m a v o i d s t h e

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    19/47

    Con s tra in t sa t is fac tion us ing CL P 3

    a n d 0 1 d d e i

    0 0 0 . . . . 0 0

    1 0 1 d d e

    d d . . . . d

    e 0 e d e 0

    i o i ~ o i

    Fig. 3. Definition of an and gate in six value logic.

    x o r

    0

    1

    d

    0 i d d e

    0 1 d d e

    1 0 d d i e

    d d . . . . . . . .

    ~ d . . . . . . . .

    e

    ~ . . . . 0 1

    ~ e 1 0

    Fi g . 4 . D e f i n i t i o n o f a n xor - ga te i n s i x - va l ue log ic .

    n o t l O I d d e i

    I

    0 d d ~ e

    Fi g . 5 . D e f i n i t i on o f a no t - ga t e i n s i x - va l ue l ogi c .

    a b o v e - m e n t i o n e d d r a w b a c k . T h e r e s u l t i n g a l g o r i t h m i s c o m p l e t e ( i t f i n d s a

    t e s t i f o n e e x i s t s) , w h i c h i s n o t t h e c a s e f o r t h e a l g o r i t h m u s i n g a f i v e - v a lu e

    log ic .

    F i g u r e s 3 - 5 g i v e t h e d e f i n i t i o n s o f s o m e g a t e s

    d n o t

    a n d

    e n o t

    a r e r e p r e -

    s e n t e d b y d a n d V ) . T h e s e d e f i n i t i o n s a r e i n t e n d e d t o p r o p a g a t e t h e v a l u e s d

    a n d d n o t t o w a r d s t h e p r i m a r y o u t p u t s a n d h e n c e s o m e i n p u t c o m b i n a t i o n s

    a r e p r o h i b i t e d . C o n s i d e r f o r e x a m p l e t h e a n d - g a t e. I f a n i n p u t i s a v a l u e

    d , t h e n t h e o t h e r i n p u t m u s t b e e i t h e r 1 o r e i n o r d e r to p r o p a g a t e d t o

    t h e o u t p u t . T h e h a n d l i n g o f th e v a l u e d n o t i s s i m i l a r . N o t e a l s o t h a t t h e

    v a l u e s e a n d

    e n o t

    a r e n o t n e c e s s a r i ly p r o p a g a t e d t o t h e o u t p u t o f t h e g a te ;

    t h i s i l lu s t r at e s t h e m a i n d i f f e r e n c e b e t w e e n t h e v a l u e s e , e n o t a n d t h e v a l u e s

    d , d n o t .

    T h e x o r - g a t e i s a l s o i n t e r e s t i n g t o a n a l y z e . A s s o o n a s a n i n p u t i s d

    o r

    dno t ,

    t h e o t h e r i n p u t m u s t b e 0 o r 1 r e s p e c ti v e l y . N o t e t h a t a v a l u e d c a n

    t h u s b e p r o p a g a t e d a s a d n o t o n t h e o u t p u t . T h e n o t - g a t e is s t r a ig h t f o r w a r d .

    T h e p o s s i b le v a l u e s f o r a f a n o u t p o i n t a r e g i v e n b y t h e p r e d i c a t e d e f i n i t i o n

    i n F i g . 6. N o t e e s p e c i a l ly h o w t h e v a l u e d i s p r o p a g a t e d : o n l y o n e o f t h e

    o u t p u t s i s a s s i g n e d t o d , t h e o t h e r b e i n g g i v e n t h e v a l u e e . T h e r e a r e

    o f c o u r se t w o p o s s ib le w a y s o f p ro p a g a t in g d d e p e n d i n g u p o n t h e o u t p u t

    c h o s e n .

    T e s t g e n e r a t i o n is t h e n p e r f o r m e d b y th e f o l lo w i n g m e t h o d . V a r i a b l e s

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    20/47

    132

    P V a n H e n t e n r y c k e t a l

    ~, f a n o u t M o d e , L a b e l , S t e m , B r a n c h i , B r a n c h 2 )

    f a n o u t M , N , O , O , O ) .

    f a n o u t M , N , l , 1 , 1 ) .

    f a n o u t M , N , d , d , e ) .

    f a n o u t M , N , d , e , d ) .

    f a n o u t M , N , d n o t , d _ n ot , n o t ) .

    f a n o u t M , N , d n o t , e n o t , d n o t ) .

    f a n o u t M , N , e , e , e ) .

    f a n o u t M , N , e n o t , S h O t , e n o t ) .

    F ig . 6. D ef in i t i on o f a f anou t i n t he s i x -va lue l og i c .

    t h r o u g h o u t t h e c i r c u i t a r e r e q u i r e d t o t a k e o n e o f t h e s i x si g n al v a lu e s . I n

    a d d i t i o n , t h e p r i m a r y i n p u t s c a n o n l y t a k e v a l u es 0 o r 1 . O n e p r i m a r y o u t p u t

    w i l l h a v e a d o r dnot v a l u e a n d s o m e o t h e r s c a n h a v e e o r enot v a l u es .

    T h e c i r c u i t g a t e s i m p o s e l o c a l c o n s t r a i n t s b e t w e e n t h e i r i n p u t s a n d o u t p u t s

    ( d e f i n e d b y t h e t r u t h t a b l e s a b o v e ) . T h e g a t e u n d e r t e s t w il l h a v e a d a s

    o u t p u t a n d s u i ta b l e i n p u t s t o c o n t r o l t h e g at e. T h e k e y a d v a n t a g e o f t h i s

    d e s c r i p t i o n i s t h a t a l l c o n s t r a i n t s c a n b e e x p r e s s e d j u s t a s l o c a l c o n s t r a i n t s .

    T h e e x i st e n ce o f a d - p a t h f r o m t h e gate under test t o a p r i m a r y o u t p u t i s

    g u a r a n t e e d b y t h e c o n s t r a i n ts . T h i s i s t h e m a i n d i f f e r e n c e f r o m t h e c l a ss ic a l

    A T P G a l g o r i th m s [ 2 6 , 2 9 ,5 3 ] , w h i c h u s e a f i v e - v a lu e l o gi c a n d r e l y o n a

    g l o ba l c o n t r o l s t r a te g y to c r e a t e t h e d - p a t h a n d c h o o s e b e t w e e n a l t e r n a ti v e s .

    N o t e a l s o t h a t t h e s o l u t i o n i s n o t d e s c r i b e d a l g o r i t h m i c a l l y b y c h a n g e s t o

    b e a p p l i e d t o a n e m p t y a s s i g n m e n t , b u t r a t h e r a s a c o n s t r a i n t s a t is f a c t io n

    p r o b l e m .

    3 2 3 Gates as demons

    A s i m p l e d e f i n i t i o n o f t h e g a t e s as t r u t h t a b l e s w o u l d l e a d t o a n e x -

    t r e m e l y i n e f f ic i e n t p r o g r a m . F o r a b e t t e r a p p r o a c h , w e e x p l o i t t w o f e a t u r e s

    o f c c ( F D ) : d o m a i n c o n s t r a in t s a n d t h e i m p l i ca t i o n o p e r at o r . E a c h l in e i n

    t h e c i r c u i t is a s s o c i a t e d w i t h a v a r i a b l e c o n s t r a i n e d t o t a k e o n e o f t h e s ix

    p o s s i b l e v a l u e s . I n a d d i t i o n , t h e p r i m a r y i n p u t s a r e c o n s t r a i n e d t o b e 0 o r

    1 . T h e i m p l i c a t i o n o p e r a t o r i s t h e n u s e d t o d e f i n e a d e m o n f o r e a c h t y p e

    o f ga t e. T h e d e m o n s m a k e s u r e t h a t t h e g a te s p r o p a g a t e v a l u e s as s o o n

    a s p os s ib l e a n d r e d u c e t h e s e a r c h s p a c e w h e n e v e r p o s si b le b y r e m o v i n g

    v a l u e s f r o m t h e v a r ia b l e s. T h e d e m o n d e f i n i t i o n i s a g e n e r a l i z a t io n o f th a t

    p r e s e n t e d i n t h e d e s c r i p t i o n o f t h e i m p l i c a t i o n o p e r a t o r . F o r i n s t a n c e , th e

    d e m o n f o r a n a n d - g a t e i s d e p i c t e d i n F i g . 7 .

    N o t e t h a t t h e im p l i c a t io n s u s e b o t h e q u a t i o n s a n d n o n - m e m b e r s h i p a n d

    d o m a i n c o n s t r a i n t s t o r e d u c e t h e s e a r c h s p a c e b y r e m o v i n g v a r i a b l e v a l u e s .

    A l s o , e a c h i m p l i c a t i o n s o l v e s t h e c o n s t r a i n t , i .e . i f a n i m p l i c a t i o n h a s b e e n

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    21/47

    on s tr a i n t sa t i sf a c t i on u s i n g

    LP

    1 3 3

    a n d _ d e m o n X , Y , Z ) : -

    x = o - ~ z = o , Y ~ { d , d n o t } ) ,

    Y -- 0 ~ z = 0 , x { d , ~ o t } ) ,

    Z -- 1 --~ ( X = 1, Y -- 1 ,

    X = 1 - -~ Y = Z ,

    Y = I - ~ X = Z ,

    X = Y - - -+ ( X = Z , X ~ { d , d n o } ) ,

    X = d --+ Y E < l , e } , Z = d ) ,

    Y

    =

    d ~

    ( Y 6 { i , e } , Z = d ) ,

    X = d . no - --+ ( Y E { 1 , e n o t } , Z = d n o t ) ,

    Y = d n o t --+ ( Y E { 1 , e n o t } , Z = d n o t ) ,

    X = e ---+ Y = e no t -+ Z = O,

    X = e n o t -~ Y = e -~ Z = O.

    F i g . 7 .

    I m p l e m e n t a t i o n o f a n a n d g at e i n t h e s i x v a l u e l o g ic .

    a n d t e s t G a t e l , F a u l t ) , G a t e , X , Y , d ) :-

    G a t e l = G a t e ,

    i n v e r s e F a u l Z , S e t u p ) ,

    a n d ( X , Y , S e t u p ) .

    a n d ( t e s t ( G a t e 1 , F a u l t ) , G a t e , X , Y , Z ) : -

    G a t e l ~ G a Z e ,

    Z E { O , l , d , d n o t , e , e n o t } ,

    a n d _ d e m o n ( X , Y , Z ) .

    t h i s i s t h e g . u . t .

    t o t e s t t h e f a u l t

    s e t u p o p p o s i t e v a l u e

    u s e t h e 0 - 1 d e m o n

    i t i s n o t t h e

    g . u . t .

    d o m a i n c o n s t r a i n t

    u s e t h e s i x - v a l u e d d e m o n

    F i g . 8 . The and gate de f in i t io n for A T P G .

    a p p l i e d , t h e n

    l l

    r e m a i n i n g v a l u e s f o r i t s v a r i a b l e s a r e v a l i d . F i n a l l y , n o t e

    t h a t w e d o n o t e n f o r c e a n a s s i g n m e n t o f t h e g a te i n p u t s i n t h e c a se w h e r e

    t h e o u t p u t t a k e s t h e v a l u e 0 . T h e c o n s t r a i n t b l o c k s u n t i l a n a s s i g n m e n t i s

    m a d e t o a n i n p u t e it h e r b y p r o p a g a t i o n o r b y a l a b e l in g r o u t i n e .

    3 2 4 T h e b as ic A T G P p r o g r m

    W e c a n n o w p r e s e n t t h e b a s i c p r o g r a m .

    E a c h t y p e o f g a t e is a s s o c i a t e d w i t h a n e w p r o c e d u r e . F i g u r e 8 i l lu s t r a te s

    t h e a p p r o a c h f o r a n a n d - g a t e . B e s i d e s t h e i n p u t s a n d o u t p u t , t h e p r o c e d u r e

    r e c e i v e s t w o a r g u m e n t s : a t e r m t e s t G a t e , F a u l t ) , w h i c h i s t h e s a m e f o r

    a l l g a t es , a n d a u n i q u e i d e n t i f i e r f o r t h e g a te . T h e t e r m t e s t a a t e , F a u l t )

    i n d i c a t e s w h i c h g a t e G a t e i s u n d e r t e s t f o r a g i v e n f a u l t F a u l t ; f o r e x a m p l e ,

    t e s t [ 2 ] , 1 ) i s u s e d f o r t e s t i n g a s a l f a u l t a t g a t e 2 .

    T h e p r o c e d u r e f o r e a c h t y p e o f g a te i s d e f i n e d b y t w o c l a u s e s . T h e f i r s t

    c l a u s e h a n d l e s t h e c a s e o f t h e ga t e u n d e r t e s t g . u . t .) , r e c o g n i z e d b y t h e

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    22/47

    1 3 4 P Van He n t e nr y c k e t a l

    test +,+,+,-): generat e test for output of Gate at Fault saO or sal

    the third arg is a list of inputvars of the circuit

    t e s t G a t e , F a u l t , I n p u t l i s t , O u t p u t ) : -

    d o m a i n _ c o n s t r a i n t s I n p u t l i s t , O , 1 ) ,

    c i r c u i t t e s t G a t e , F a u l t ) , [ ] , I n p u t l i s t , O u t p u t ) ,

    l a b e l i n g I n p u t l i s t ) .

    labeling +): assign 0 or i to all inputs of the circuit

    labeling []).

    l a b e l i n g [ X l T ] ) : -

    m e m b e r X , [ O , l ] ) ,

    labeling T).

    F ig . 9. A T P G p r o g r a m .

    equality Gate1 = G a t e where G a t e l is the unique identifier of the gate under

    test and Gate is the gate currently considered. The clause simply assigns the

    value d to the output. In addition, the clause controls the gate by stating a

    constraint on the inputs to produce the desired output. The desired output is

    obtained from the type of fault by the procedure inverse and the constraint

    is enforced using the 0-1 definition of the and-gate as described in Section

    2.4. For example, an sa0 fault for the and-gate would produce 1 as the

    desired output (i.e. Setup is l) and the 0-1 and-gate is called with x, Y,

    and Setup as arguments. In this case, the 0-1 defin ition assigns x and Y

    to 1. The second clause handles the general case, i.e. when the gate under

    consideration is not the gate under test. The clause simply enforces a domain

    constraint for the output and calls the six-value definition.

    The complete program for test generation is shown in Fig. 9. It uses a

    circuit description and the predicate definitions above. The first argument

    of test is the label of the gate to test, the second argument is the fault type

    to test, and the third argument must be instantiated to the list of variables

    for the primary inputs of the circuits (this list is assigned 0-1 values by

    the labeling routine). The predicate domain constraints generates suitable

    domain constraints for the primary inputs to guarantee that they are given

    a 0-1 value. The second goal enforces the constraints associated with each

    gate relating its inputs to outputs. The last goal simply assigns values to the

    primary inputs. As usual in constraint programming, the generat ion phase is

    interleaved with the constraint propagation part at run time, although they

    are separated in the problem statement.

    The algorithm described so far is complete, i.e. it finds a test pattern if

    one exists and fails otherwise. We now explore several ways of improving

    its efficiency.

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    23/47

    Constraint satisfaction using CLP 135

    3 2 5 H eur i s t i cs

    T h e b a s i c p r o c e d u r e d e s c r i b e d s o f a r r e q u i r e s m a k i n g m a n y p o s s i b l e

    c h o i c e s. T o o b t a i n a n e f f i c i e n t s y s t e m , i t is n e c e s s a r y t o d e v e l o p h e u r i s ti c s

    t h a t a v o i d m a k i n g t h e

    w r o n g

    c h o i c e s . I n t h i s s e c t i o n w e d e s c r i b e s o m e

    o f th e h e u r i s t i c s u s e d i n o u r t e s t g e n e r a t i o n p r o g r a m . W e s h o w t h a t t h i s

    i n f o r m a t i o n c a n e a s il y b e a d d e d i n to t h e p r o g r a m .

    Contro l lab i l i t y and observabi l i t y

    W h e n p r o p a g a t i n g a d - v a l u e f r o m t h e f a u l t t o a p r i m a r y o u t p u t , n o c h o i c e s

    a r e n e e d e d a s l o n g a s t h e r e i s a u n i q u e p a t h . W h e n a d - v a l u e r e a c h e s

    a f a n o u t s t e m h o w e v e r , t h e d - p a t h c a n c o n t i n u e a l o n g a n y o f t h e s t e m s

    a n d w e h a v e t o d e c i d e w h i c h o n e t o f o l l o w . S e v e r a l m e a s u r e s h a v e b e e n

    p r o p o s e d t o e s t i m a t e t h e d i f f i c u l t y o f f in d i n g a p a t h f r o m s o m e p o i n t i n s i d e

    t h e c i r c u i t t o a n o u t p u t [ 4 ] . T h i s v a l u e , c a l le d a n observabi l i t y m e a s u r e , c a n

    b e p r e c o m p u t e d i n a p r e p r o c e s s i n g s t e p . F o r e a c h f a n o u t p o i n t , w e o b t a i n

    a n o r d e r i n g f o r t h e f a n o u t s t e m s , a n d t r y t o p r o p a g a t e t h e d - v a l u e a l o n g t h e

    p a t h w i t h h i g h e s t o b s e r v a b i l i t y f i r s t .

    A s i m i l a r m e a s u r e e s t i m a t e s h o w d i f f i c u l t i t i s t o s e t a p o i n t i n s i d e t h e

    c i r c u i t t o a p a r t i c u l a r v a l u e , 0 o r 1 . T h i s control labi l i ty i s u s e d t o d e c i d e

    w h i c h v a l u e s t o a s s ig n t o c o n t r o l l in g i n p u t s o f x o r - g at e s in t h e d - p a t h . I f it

    i s e a sy t o se t a p o i n t t o 0 , we u se t h i s v a l u e ; i f n o t , we se t i t t o 1 .

    B o t h c o n t r o l l a b il i ty a n d o b s e r v a b i l i ty a r e h e u r i s t ic v a l u e s . S i n c e t h e y a r e

    o b t a i n e d b y s i m p l e c o m p u t a t i o n s , f o r e x a m p l e ig n o r i n g r e c o n v e r g e n t f a n o u t ,

    t h e y g i v e o n l y h i n t s o n w h i c h v a l u e s t o t e s t f i r s t , a n d d o n o t e l i m i n a t e t h e

    n e e d f o r b a c k t r a c k i n g c o m p l e t e l y .

    L a b e l i n g

    T h e c h o i c e o f a n a p p r o p r i a t e l a b e l in g r o u t i n e i s c r u c i a l f o r m a n y c o n s t r a i n t

    s a t i s f a c ti o n p r o b l e m s b u t t u r n s o u t n o t t o b e a s i m p o r t a n t f o r t e s t g e n e r a t i o n .

    W e u s e a r o u t i n e t h a t a s s i g n s t h e v a r i a b l e s i n t h e o r d e r g i v e n , b u t c h o o s e s

    r a n d o m l y b e t w e e n 0 a n d 1 f o r th e f i rs t a ss i g nm e n t . F o r m o s t o f th e e x a m p l e

    c i r c u it s t e s t e d b e lo w , t h e l a b e li n g is d o n e w i t h o u t a n y d e e p b a c k t r a c k i n g .

    L i m i t i n g b a c k t r a c k i n g

    S o m e f a u l t s in c i r c u it s c a n b e u n t e s t a b le ; t h e y a r e r e d u n d a n t T h e p r o g r a m

    m a y n o t b e a b l e t o d e t e c t t h i s i n r e a s o n a b l e t i m e . T e s t s f o r o t h e r f a u l t s c a n

    b e v e r y d i f f i c u lt to o b t a i n . T o a v o i d s p e n d i n g t o o l o n g tr y i n g t o f i n d a t e s t,

    w e h a v e t o l im i t t h e s e a r c h p e r f o r m e d o n a n y o n e f a u lt . T h is c a n b e d o n e

    i n t w o w a y s: o n e i s t o l i m i t t h e n u m b e r o f b a c k t r ac k s t e ps p e r f o r m e d i n

    t h e s e a r c h , t h e o t h e r i s t o l i m i t t h e e x e c u t i o n t im e s p e n t o n e a c h c a s e . B o t h

    m e t h o d s a r e r a t h e r s i m p l e t o a d d t o t h e p r o g r a m .

  • 8/11/2019 Pascal Van Hentenryck Constraint satisfaction using constraint logic programming

    24/47

    136 P V a n H e n t e n r y c k e t a l

    Z C1 Cout

    Fig. 10. Test generation example.

    X ~ ~ C1 r--,,,

    x ~ c1 [ ~ u t

    y ~ C2

    Fig. 11. T est generation example (continued).

    3 3 Examp le

    W e u s e t h e f u l l - a d d e r c i r c u i t d e s c r i b e d a b o v e t o i l l u s t r a t e t h e b e h a v i o r

    o f t h e p r o g r a m . W e e x p l a i n t h e s t e p s r e q u i r e d t o g e n e r a t e a t e s t f o r a n s a l

    f a u l t a t t h e o u t p u t o f x o r - g a t e 2 ( s e e F i g . 1 0 ) .

    T h e q u e r y t o e x e c u t e i s

    ? - t e s t [ 2 ] , l , [ X , Y , Z ] , [ S , C o u t ] ) .

    T h e p r o g r a m e n f o r c e s al l c o n s t r a i n t s i m p o s e d b y t h e c i r cu i t. T o c o n t r o l

    g a t e 2 , s l i s a s s i g n e d t h e v a l u e d . I n a d d i t i o n , s i n c e t h e t e s t i s a n s a l f a u l t ,

    t h e v a r i a b l e S e t u p i s a s s i g n e d t o o . T h e x o r - d e m o n f o r t h e g a t e i s t h e n

    e x e c u t e d w i t h t h e o u t p u t e q u a l t o 0 . T h i s a s s i g n m e n t e n t a i l s , b y d e f i n i t i o n

    o f th e x o r - g a te , t h e e q u a l i t y o f b o t h i n p u t s o f g a te 2 ( s e e F i g. 1 0 w h e r e

    t h e e q u a l i t y i s s h o w n a s a d o u b l e a r r o w ) , w h i c h i s t h e w e a k e s t c o n s t r a i n t

    n e c e s s a r y t o m a k e s u r e t h a t t h e o u t p u t i s 0 . A l l o t h e r g a t e s u s e t h e s i x - v a lu e

    d e f i n i t i o n s ; t h e i r p u r p o s e i s t o p r o p a g a t e t h e v a l u e d ( o r d n o t ) t o w a r d s t h e

    p r


Recommended