• Aucun résultat trouvé

Towards a Generic Framework to Generate Explanatory Traces of Constraint Solving and Rule-Based Reasoning

N/A
N/A
Protected

Academic year: 2023

Partager "Towards a Generic Framework to Generate Explanatory Traces of Constraint Solving and Rule-Based Reasoning"

Copied!
57
0
0

Texte intégral

(1)

HAL Id: inria-00443635

https://hal.inria.fr/inria-00443635

Submitted on 12 Jan 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.

Traces of Constraint Solving and Rule-Based Reasoning

Pierre Deransart, Rafael Oliveira

To cite this version:

Pierre Deransart, Rafael Oliveira. Towards a Generic Framework to Generate Explanatory Traces of Constraint Solving and Rule-Based Reasoning. [Research Report] RR-7165, INRIA. 2009, pp.53.

�inria-00443635�

(2)

a p p o r t

d e r e c h e r c h e

N0249-6399ISRNINRIA/RR--7165--FR+ENG

Domaine 2

Towards a Generic Framework to Generate Explanatory Traces of Constraint Solving and

Rule-Based Reasoning

Pierre Deransart — Rafael Oliveira

N° 7165

Decembre 2009

(3)
(4)

Centre de recherche INRIA Paris – Rocquencourt

R ule-B ased R easoning

Pierre D eransart

y

,R afaelO liveira

zy

D om aine : A lgorithm ique,program m ation,logiciels et architectures E quipes-P rojets C ontraintes

R apport de recherche n°7165 | D ecem bre 2009 | 53pages

A bstract: In this report, w e show how to use the Sim ple Fluent C alculus (SFC ) to specify generic tracers,i.e. tracers w hich produce a generic trace. A generic trace is a trace w hich can be produced by di erent im plem entations of a softw are com ponent and used independently from the traced com ponent.

T his approach is used to de ne a m ethod for extending a java based C H R_ platform called C H R O M E (C onstraintH andling R ule O nline M odel-driven E n- gine) w ith an extensible generic tracer. T he m ethod includes a tracer speci - cation in SFC , a m ethodology to extend it, and the w ay to integrate it w ith C H R O M E ,resulting in the platform C H R O M E -R E F (for R easoning E xplana- tion Facilities), w hich is a constraint solving and rule based reasoning engine w ith explanatory traces.

K ey-w ords: Trace,C H R ,C H R_,C H R O M E ,C H R O M E -R E F,Tracer,M eta- T heory, M odel D riven E ngineering, Tracer D river, A nalysis Tool, P rogram A nalysis,O bservationalSem antics,Softw are C om ponent,D ebugging,P rogram - m ing E nvironm ent,Logic P rogram m ing,Validation

IN R IA P aris-R ocquencourt,P ierre.D eransart@ inria.fr

yW ork done during internship ofR afaelO liveira from

zFederalU niversity ofP ernam buco,rafoli@ gm ail.com

(5)

E xplanatory T races of C onstraint Solving and R ule-B ased R easoning

R esum e : D ans ce rapport, nous m ontrons com m ent utiliser le calcul des uents sim ple (SFC ) pour speci erdes traceursgeneriques,c’est-a-dire quipro- duisent des traces generiques. U ne trace generique est une trace quipeut ^etre produite pardi erentesim plem entationsd’un com posantlogicielet^etreutilisees independam m ent du com posant trace.

C ette approche est utilisee pour de nir une m ethode pour introduire dans une platform e C H R_ basee Java et appelee C H R O M E (C onstraint H andling R ule O nline M odel-driven E ngine)un traceurgeneriqueextensible. La m ethode com prend une speci cation du traceuren SFC ,une m ethodologied’extension,et leur im plantation dans C H R O M E ,a n d’obtenir la plateform e C H R O M E -R E F (R aisonnem ent E xplicatifFacilite),quiest un solveur de contraintes et m oteur de raisonnem ent a base de regles avec des traces d’explications.

M ots-cles : trace, C H R , C H R_, C H R O M E , C H R O M E -R E F, M D E , tra- ceur,m eta-theorie,pilote de tracer,analyseur,outils d’analyse,analyse de pro- gram m e,analyse dynam ique,sem antique observationnelle,com posant logiciel, deboggage,environnem ent de program m ation,program m ation en logique,vali- dation

(6)

1 Introduction

In this report w e de ne a m ethod for extending a java based C H R_1 platform called C H R O M E (C onstraintH andling R ule O nline M odel-driven E ngine) w ith an extensible generic tracer. C H R O M E is presently developed at the Federal U niversity ofPernam buc [56]w ith the purpose to allow the developm entoflarge softw are using C H R paradigm .

T he m ethod consists of rstly to build a form alspeci cation ofa tracer for C H R_,the kernelofthe system ,and to extend it according to further C H R_ extensions. T he speci cation de nes a generic trace w hich is as independent as possible from a particular C H R platform or speci c usages. T hen,secondly,it is suggested to use this speci cation as a guideline to extend the M D E schem e developm ent ofC H R O M E ,w ith a tracer schem e developm ent,resulting in the plateform C H R O M E -R E F (R E F stands for R easoning E xplanation Facilities), w hich is a constraint solving and rule based reasoning engine w ith explanatory traces.

T his report is alm ost based on the internship w ork ofR .O liveira [38]. W e introduce rst som e contextualaspects ofthis w ork.

1.1 T he C H R W orld

T he language C H R has m atured over the last decade to a pow erfuland elegant general-purpose language w ith a w ide spectrum of application dom ains [52].

T he interest in C H R_ stem m ed from past research having show n that:

ˆ C H R is sim ultaneously a Turing-com plete declarative program m ing lan- guage and an expressive know ledge representation language w ith declara- tive form alsem antics in classical rst-order logic [22];

ˆ C H R integratesand subsum esthe threem ain rule-based program m ing and know ledge representation paradigm s,i.e.,(conditional) term rew rite rules [24],(guarded) production rules [55]and (constraint) logic program m ing rules [1];

ˆ A C H R_ inference engine can support an unm atched variety of practi- calautom ated reasoning tasks,including constraintsolving w ith variables from arbitrary dom ains,satis ability [22],entailm ent [50],abduction [1], agent action planning [50]and agent beliefupdate [50]and revision [55].

In addition,itsupportseveralofthese tasksunder logical[50],plausibilis- tic [8]and probabilistic epistem ological[42]assum ptions. [10]addsdefault reasoning to this list,by show ing how to represent default logic theories in C H RV. It also discusses how to leverage this representation together w ith the w ell-know correspondence betw een defaultlogic and N egation A s Failure (N A F) in logic program m ing,to propose an extension C H RV;n af ofC H RV allow ing N A F in the rule heads. A nd [20]adds concurrency.

T he Figure1show s the severalautom atic reasoning services that are sub- sum ed by C H R_ and extensions.

For all its above strengths, C H R rem ained until recently a language for K now ledgeR epresentation and P rogram m ing (K R & P )in-the-sm allm ainly used

1C H R stands for C onstraint H andling R ule [22],C H R_ for C H R w ith disjunction.

(7)

Figure 1: R ule-based C onstraint P rogram m ing and A utom ated R easoning Ser- vices

to fastprototype intelligent,innovative system s. T he O R C A S project2,consti- tutes a rstand prelim inary step tow ardsthe long term goal,to turn C H R into a platform for K R & P in-the-large industrial strength, operationally deployed system s. It addressed one key K R & P in-the-large requirem ent, nam ely rule base engineering scalability through rule base encapsulation and assem bly in reusable softw are com ponents.

1.2 From C H R O M E to C H R O M E -R E F

C H R O M E stands forC onstraint H andling R ule O nline M odel-driven E ngine,isa m odel-driven,com ponent-based,scalable,online,Java-hosted C H R_ engine to lay at the bottom ofthe fram ew ork as the m ost w idely reused auto- m ated reasoning com ponent. T he idea ofC H R O M E is also to dem onstrate how a standard set of languages and processes prescribed by M D A can be used to design concrete artefacts,such as: a versatile inference engine for C H R_ and its com piler com ponent that generates from a C H R_ base the source code ofJava classes.

T heprojectC H R O M E -R E F (C onstraintH andling R uleO nlineM odel-D riven E ngine w ith R easoning E xplanation Facilities) constitutes a prelim inary step, tow ards extending C H R and C H R engines w ith a form ally founded, exible and user-friendly reasoning explanation facility. T he need for exible and user- friendly explanatory reasoning tracing facilities for rule-based system s has been recognized since the initialsuccessofproduction rule expert system sin the 80s.

H ow ever,the expressive pow er ofC H R being far superior than that ofa m ere production system ,through the addition offunctionalterm s,rew rite rules and backtracking search,m akesdebugging a C H R rule base also m ore com plex than debugging a production rule base. In turn, this added com plexity m akes the

2http://www.cin.ufpe.br/~jr/mysite/C4RBCPProject.html

(8)

need for sophisticated rule engine tracing facilities m ore crucialand the issues in their design and im plem entation m ore challenging.

T hisprojectispioneering the investigation ofthese issues. C H R O M E assem - bles C H R base independent run-tim e com ponents for constraint store m anage- m ent, red ruled history m anagem ent,constraint entailm ent,query processing and intelligent search,w ith optim ized com ponents resulting from the com pila- tion ofthe C H R base. Follow ing the K obrA 2 m odel-driven,com ponent-based, orthographic softw are engineering m ethod [4,5], C H R O M E w as built by rst specifying a re ned P latform -Independent M odel(P IM ) in the O M G standards U M L2/ O C L2 (U ni ed M odeling Language / O bject C onstraint Language).

T his P IM w as then im plem ented in Java.

T he fact that C H R O M E com piling a declarative C H R base into im perative Java objects is crucialfor its reasoning perform ance. H ow ever,it m akes tracing far m ore com plex since it introduces a m ism atch betw een,on the one hand,the abstract,high-levelrule interpretation operationalsem anticsthatthe developer follow s w hen conceiving a C H R base, and, on the other hand, the concrete, low -levelobject m ethod calloperationalsem antics e ectively executed by the engine. To help the developerdebug the rule base,the tracerm ustthusgenerate a high-levelruleinterpretation tracesim ulation from thelow -levelobjectm ethod calls executed by the com piled code.

O ur objective here is to integrate the independently constructed tracer ar- chitecture w ithin the com ponent-based architecture ofC H R O M E follow ing the K obrA 2 m ethod.

1.3 T ow ards G eneric T race

D espite the fact that C H R_ provides an elegant general-purpose language w ith a w ide spectrum ofapplication dom ains,a key issue is how easily you can w rite and m aintain program s. Severalstudies [48,45][7][6]show that m aintenance is the m ost expensive phase of softw are developm ent: the initialdevelopm ent represents only 20% ofthe cost,w hereas error xing and addition of new fea- tures after the rst release represent,each,40% ofthe cost. T hus,80% ofthe cost is due the to the m aintenance phase. D ebugging is said to be the least established area in softw are developm ent: Industrialdevelopers have no clear ideas about generaldebugging m ethods or e ective and sm art debugging tools, yetthey debug program sanyw ay. T here are severalw aysto analyze a program , for instance: program analysis tools help program m ers understand program s, type checkers [37]help understand data inconsistencies,slicing tools [30]help understand dependencies am ong parts ofa program . Tracers give insights into program executions.

A t present, there exists a num ber of useful debugging tools for C H R , for exam ple, E C LiP Se P rolog [2], SW I-P rolog [58] or C H R O M E [56]. B ut, these tools w ere designed and im plem ented in a speci c w ay for each solver,not all toolsbene t from allthe existing tool. T he Figure2show sthis currentcenario, for each C H R solver a speci c im plem entation ofthe debugging tool.

T his w ay each im plem entation results in a set ofone-to-one specialized con- nections betw een a solverand its tools. Ifw e w antto interchange data betw een each solver,hookshave to be added into the solvercode in orderto be able to do it. Furtherm ore,the types ofbasic inform ation required by a given debugging

(9)

Figure 2: C urrent situation: each solver is strictly connected to its debugging tool. Figure adapted from [31]

Figure 3: O urapproach:a generic trace schem a enablesw ork and m aintain just one process ofdebugging

toolis notoften m ade explicit and m ay have to be reverse-engineered.T his is a non neglectable part ofthe cost ofporting debugging toolfrom one constraint program m ing platform to another.

In order to solve the above-m entioned problem and im prove analysis and m aintenance ofrule-based constraint program s,like C H R_,there is a need for user-friendly reasoning explanatory facilities that are exible and portable.

G iven this scenario w e take advantage of the recent research in trace en- gineering [16,14,15] to propose a generic architecture that produces generic debugging inform ations for C H R_ and potentialextensions. In that w ay,any debugging toolchangesits focus to generic traces,instead ofto be concerned in speci c platform im plem entations.

T he Figure3illustrates the idea of\generic trace",w hich is as independent as possible from a particular C H R platform or speci c usages. It show s the structure of a tracing process w hich can be decom posed into three likely \in- dependent" com ponents: trace extraction,fulltrace ltering according to som e query,and reconstruction of a sub-trace to be used. It show s also the several aspects w hich m ust be speci ed: a sem antics for the generic trace (called O b-

(10)

CHR−OS

FC

CHROME

UML

CHROME−REF

UML

Figure 4: Tow ards C H R O M E -R E F

servationalSem antics), a query language to select the sub-trace of interest to be used, and a sem antics to interpret the selected trace (called Interpretative Sem antics).

A generic trace needs to be understood independently from the observed process. For this reason it is necessary to be able to give it a sem antics as precise as possible. T his is the purpose of the O bservational Sem antics. It w illallow for validation tests and studies of som e trace properties before and after im plem enting it. In this report w e focus on the observationalsem antics of traces.

T he FluentC alculus(FC )isa logic-based representation languageforknow l- edge about actions,change,and causality [54]. A s an extension ofthe classical Situation C alculus [43], Fluent C alculus provides a generalfram ew ork for the developm entofaxiom atic sem anticsfordynam ic dom ains. Itappearsto be w ell suited to describe the O bservationalSem antics and,though its Flux im plem en- tation [53],to be a likely executable speci cation.

1.4 C onnecting all the P ieces

T he C H R O M E project focuses on extending C H R w ith rule-base encapsula- tion in softw are com ponents for reuse by assem bly across applications. It has as intention to produce the rstdom ain-independent fram ework highly reusable debugging tool, supporting a variety of reasoning explanation facilities. T he m ain contribution is to perm it any C H R_ engine to be extensible w ith com - ponents for com prehensive, exible and e cient reasoning explanation trace generation and user-friendly trace query speci cation and trace visualization.

To achieve this is necessary to integrate design patterns for tracing facilities such as tracer driver w ith design patterns for G raphicalU ser Interface (G U I) such as M odel-V iew -C ontroller (M V C ) w ithin an overallM odel-D riven A rchi- tecture (M D A )fram ew ork [3]. Itw illalso involvede ning a com prehensivetrace query language,as w ellas experim ents to em pirically evaluate the engineering productivity gains obtained through the use ofthe tracing com ponents.

In the reportw e describe the approach illustrated by the Figure4. Itconsists rst in an observationalsem antics ofthe extensible generic trace ofC H R w hich is speci ed in Fluent C alculus. T his sem antics is thus m apped into the P IM description ofC H R O M E ,leading to a com pleteP IM ofC H R O M E -R E F in U M L, the constraint solving and rule based reasoning engine w ith explanatory traces.

(11)

T he C H R O M E -R E F environm ent w illbe built such an editor as a E clipse P lugin for rapid prototyping deployed w ith a G U I to interactively subm it re- quests and inspect solution explanations at various levels ofdetails.

T he rest ofthis report is organized in three m ain sections.

T he Section2presents a restricted trace m eta-theory focused on trace pro- duction com ponents and com position. It introduces also the observationalse- m antics ofa trace and its representation in the sim pli ed uent calculus.

T he Section3presents the observationalsem antics of C H R_ in uent cal- culus including tracer and extraction schem es.

T he Section4show s the introduction ofthe tracer in the P IM ofC H R O M E using the K obrA 2 m ethod and resulting in a P IM of C H R O M E -R E F w ith a very rst im plem entation.

Four annexes give respectively a description ofthe O bservationalSem antics ofC H R in SFC ,the X M L schem e ofa generic trace ofC H R_,a short exam ple of trace produced by the java com piled C H R O M E -R E F, and the O S of an application.

2http://w w w .eclipse.org/

(12)

2 Specifying T racers

T he Trace M eta-T heory (T M T ) [15]provides a set ofde nitions about how to design a trace for a speci c dom ain ofobservation.

A trace m ay be interpreted as a sequence of com m unication actions that m ay take place betw een anobserverand anobserved process. It consists of niteunbounded sequencestraceevents.T hereisalso thetracerthatm eansthe generatoroftrace. A ccording to [14],the T M T focusesparticularly on providing sem antics to tracers and the produced traces as independent as possible from those ofthe processes or from the w ays the tracers produce them .

T here are tw o concepts oftrace [14](cf. the Figure5and the Section2.2).

T he rst one is thevirtual trace,it represents a sequence ofevents show ing the evolution of a virtual state w hich contains all that one can or w ants to know about the observed process. T he second one is calledactual trace, it representsthegenerated tracein the form ofsom eencoding ofthe currentvirtual state. Finally, there is the idea offull traceif the param eters chosen to be observed about the process representthe totality ofusefulknow ledge regarding it (explicitly or im plicitly).

2.1 C om ponents of T race G eneration and U se

T he Figure6show s the di erent com ponents related to a unique trace. W e distinguish 5 com ponents,in this order.

1. O bserved process

T heobserved processisassum ed m oreorlessabstracted in such a w ay that his behavior can be described by a virtualtrace,that is to say,a sequence of(partial) states. A form aldescription ofthe process,ifpossible,can be considered asa form alsem antics,w hich can be used to describe the actual trace extraction.

Figure 5: V irtualand A ctualTrace.

2. E xtractor

T his com ponent is the extraction function of the actual trace from the virtualtrace. From a theoreticalpoint ofview ,w e can see it as a speci c

(13)

Process

Obs. T^v

Full

T^w Full

OS

Extractor

T^v Partial

IS Filtering

Partial T^w

Analyser Driver

query

Rebuilder

Figure 6: C om ponents ofthe T M T

T^w Driver

T^w Full

query

Tw extraction Full Tv

OS IS

Partial Tv Rebuilding Partial

Figure 7: Form alconcepts related to the generation and use ofa trace com ponent,but in practice it correspondsto the tracer w hose realization, in the case of a program m ing language, usually requires m odifying the code ofthe process.

3. Filter

T he role ofthe lter com ponent,ordriver[32],is to select a usefulsub- trace. T his com ponent requires a speci c study. It is assum ed here that it operates on the actualtrace (that produced by the tracer). T he fact ofm aking it as a proper com ponent corresponds to the speci c approach adopted here,w hich im plies that the extracted actualtrace is full. T he ltering depends on the speci c application,im plying that the fulltrace already contains allthe inform ation potentially needed for various uses.

4. R ebuilder

T he reconstruction com ponent perform s the reverse operation ofthe ex- traction,at least for a subpart of the trace, and then reconstructs a se- quence ofpartialvirtualstates. Ifthe trace is faithful(i.e. no inform ation is lost by the driver) [15],this ensures that the virtualtrace reconstruc- tion is possible. In this case also,the separation betw een tw o com ponents (rebuilder and analyzer) is essentially theoretical;these tw o com ponents m ay be in practice very entangled.

5. A nalyzer

T he com ponent using a trace m ay be a trace analyzer or any application.

W ith these com ponents it m ay be associated three m ain speci cation steps, as illustrated on the Figure7.

- O bservationalSem antics (O S)

(14)

T he O S describes form ally the observed process(ora fam ily ofprocesses)and the actual trace extraction. T his aspect w ill be studied deeper in the Sec- tion2.2. T he intention here is to express the O S using sim ple uent calculus.

- Q uerying

D ue to the separation in several com ponents, the actual trace m ay be ex- pressed in any language. W e suggest using X M L.T his allow s to use standard querying techniques de ned for X M L.T his aspectw illnot be developed here, but w e chose to express the trace in X M L and give in the A ppendixB the corresponding X M L schem a.

- Interpretative Sem antics (IS)

T he interpretation ofa trace,i.e. the capacity ofreconstructing the sequence ofvirtualstates from an actualtrace,is form ally described by the Interpreta- tive Sem antics. In the T M T no particular application is de ned;its objective is just to m ake sure that the originalobserved sem antics of the process has been fully com m unicated to the application,independently ofw hat the appli- cation does.

2.2 C ontiguous Full T races

W e introduce here the tw o traces w hich m ay be associated to a single process equipped w ith a tracer. W e recallhere the de nitions used in [15].

2.2.1 V irtual T race

A full virtual trace is de ned on a dom ain of states. G ivenP a nite set of (nam es) of param eterspide ned on the dom ainsPi. T hePiare dom ains of objects of any kind. T hey m ay also have relations (functional or otherw ise) betw een them and they can be in nite in size.

A dom ain ofstatesS is de ned on the C artesian product ofthe param eter dom ains:S P1 ::: Pn.

D e nition 1 (C ontiguous Full V irtual T race) A contiguousfullvirtualtrace is a sequence oftrace events ofthe form et:(t;rt;st); t 1,where:

ˆ t: is thechrono, speci c tim e of the trace. It is an integer increased by one unit in each successive event. To point a particular value of the chrono,we willtalk aboutm om entofthe trace.

ˆ rt: an identi er ofaction characterizing the type of actions undertaken to m ake the transition from statest1 to statest.

ˆ st: is an elem ent of the state dom ain. st = p1;t;:::;pn ;t is the current state reached at m om entt, and thepi;tare values of theparam eterspi at m om entt.stis thecurrent fullvirtualstate.

A nite virtualtrace overt(t> 0)eventsw illbe denotedTtv =< s0;et>,w here s0 is the initialfullvirtualstate andetrepresents the sequencee1:::ei:::et.

T he fullvirtualtrace iscontiguousinsofar asallthe m om ents in the interval [1::t]are present in the traceTtv=< s0;et>.

(15)

2.2.2 A ctual T race

T he fullvirtualtrace represents w hat w e w ant or w hat is possible to observe of a process. It describes the developm ent stages ofthis process in the form ofthe evolution ofa state w hich containsthe observables. A s the currentvirtualstate of a process can be fully represented in this trace, one cannot expect neither to produce it nor to com m unicate it e ciently. In practice w e w illperform a kind of \com pression" of the inform ation conveyed by the virtual states and their evolution,transm itted or com m unicable to the process observers,and one shall ensure that these processes are able to \decom press" it. T his actually com m unicated inform ation is theactualtrace.

A n actualfulltraceisde ned on an actualstate dom ain. LetA be a nite set of(nam es of) attributesaide ned on dom ains ofattributesAi. T he attributes m ay have relationships (they are not necessarily independent) and they can be in nite in size.

A n actualstate dom ainA is de ned on the C artesian product ofattributes dom ains:A A1 ::: An.

D e nition 2 (C ontiguous Full A ctual T race)A n actualtrace isa sequence oftrace events ofthe form wt:(t;at); t 1,where:

tis the chrono andat 2 A denotes a nite sequence ofattributes values.atis the currentactualstate. T he num ber ofattributes ofa trace eventis bound byn.

Each stateatcontains at m ostn attributes whose num ber depends exclusively on the type ofaction which produced it.

A n actualtrace w itht(t > 0) events is denotedTtw =< s0;wt>,w heres0 is the initialvirtualstate com m on to both traces andwtrepresents the sequence w1;:::wi;:::;wt.

2.3 G eneric T race and C om position

W e study here the m ethodology of generic fulltrace developm ent for a m ulti- layer based application.

2.3.1 G eneric T race of a Fam illy of O bserved P rocesses

C onsider again the Figure3in the introduction. It illustrates the fact that di erentim plem entationsofC H R can be abstracted by a unique sim plerm odel.

T his com m on m odelis used to specify the unique virtualand actualtraces of these im plem entations. T his illustratesthe w ay w e w illproceed to geta generic trace of C H R : starting from an abstract theoretical, general but su ciently re ned,sem antics ofC H R w hich is (alm ost) the sam e im plem ented in allC H R platform s.

2.3.2 C om position of T races

N ow w e consider the case of an application w ritten in C H R . It m ay be for exam ple a particular constraints solver like C LP (FD ).In this case there exists already a generic trace calledG enTra4C P[12]. T his trace is generic for m ost of the C LP (FD )existing constraintssolvers.T herefore a tracerofC LP (FD )solver im plem ented in C H R should also produce this trace. B ut w e m ay be interested

(16)

Analysis Tools

Querying APL

OS APL IS APL

Full Full

Extractor

Rebuilder Filter Partial

T^w T^w T^v APL

Partial API T^w

Extractor

Partial Rebuilder

Filter

IS CHR T^w

OS CHR

Full Full Partial

Querying CHR trace

T^v CHR T^v CHR

CHR

T^w Extractor

Rebuilder Filter APL in

+ CHR T^v APL

Full

T^v APL API + CHR APL T^v APL

Driver APL

T^w APL+CHR Partial CHR

Querying APL + CHR IS APL + CHR OS APL + CHR

Driver CHR

Driver APL + CHR

Figure 8: C om position ofG eneric FullTraces for a tw o Layers A pplication in re ning the trace considering that there are tw o layers: the layer of the application (C LP (FD ))and the layerofthe language in w hich itisim plem ented (C H R ).T he m ostre ned trace w illthen be the trace in the G enTra4C P form at extended w ith elem ents ofthe generic fulltrace ofC H R alone. T he generic full trace ofC LP (FD ) on C H R is an extension ofthe application trace taking into account details oflow er layers.

T his is illustrated by the Figure8in the case oftw o layers: an application (like C LP (FD )forexam ple)im plem ented in C H R .T hism ethod can be general- ized to applications w ith severallayers ofsoftw are. T he Figure5show s in fact at least 4 layers.

In our com ponents based approach it m eans that w e m ay de ne separately and independently speci c generic fulltraces for each layer,and,so in this case for the application (A P L) and the under-layer of C H R .T he generic fulltrace A P L on C H R is a kind ofcom positionoftraces and w illbe obtained by som e m erging ofboth generic fulltracesinto a unique one. T he resultm ay notexactly be a union ofallactions,param eters and attributes,but it is not our purpose here to study m ore deeply this aspect. For m ore details see [15].

2.4 O bservational Sem antics

T he O bservationalSem antics(O S)isa description ofa possibly unbounded data ow w ithoutexplicitreference to the operationalsem anticsofthe processw hich produced it [16]. T he O S m ay be considered as a abstract m odelofprocess,in the case ofa single observed processoritcan be an abstraction ofthe sem antics to severalprocesses. It is de ned as a Labelled Transition System s (LT S) [25].

(17)

2.4.1 R epresentation of the O bservational Sem antics

T he O bservationalSem antics has tw o parts: a state transition function and a trace extraction function.

T he rst part is a form alm odelon the w ay successive events ofthe virtual trace are related. It is a virtualtrace sem antics in the sense that,given a full virtualtrace

Ttv=< s0;et>,it explains the sequence ofeventsetby a transition function3 recursively applied from an initialvirtualstate.

T hesecond part,thefunction ofextraction,producesw hatisactually \broad- casted" outside from the observed process. T his function has as argum ents the current state and the type ofaction,and produces the attributes ofthe actual trace.

D e nition 3 (O bservational Sem antics (O S))A n O bservationalSem antics is de ned by the tuple< S;RO;A ;E ;T;S0>,where

ˆ S is a virtual state dom ain, where each state is described by a set of param eters.

ˆ RO is a nite setofaction types,setofidenti ers used as labels for tran- sitions.

ˆ A is aactualstate dom ain, where each state is described by a set of at- tributes.

ˆ E is the localextraction function ofthe actualstatea,perform ed by tran- sition ofaction typerissued from states,E :R xS! A,which satis es by de nition:E(r;s) = a(a2 A, set of actualstates). M ore precisely, the set of attributesat of the eventtof the actualtrace is derived from the current state at m om entt 1of the virtualtrace and the transition labelled by the action typert,i.e.

E(rt;st1)= at

ˆ T state transition functionT :R x! S,i.e.

T(rt;st1)= st

ˆ S0 S,set ofinitialstates.

T he O S m ay be represented by \rules",one for each action,describing the transition and the actualtrace event extraction corresponding to the action. A rule has 4 item s.

ˆ A T ype: an action identi err2RO

ˆ A C ond:fsom e auxiliary com putations on the current virtualstate and condition for executing the action corresponding to the transition: a rst- order logic form ula using predicates on the param etersg

3It is fact a relation since the transitions m ay be nondeterm inistic.

(18)

ˆ V SE ect:fthe e ect ofthe actionron the current states,resulting in a new states0,and som e auxiliary com putationsrelative to the attributes ofthe trace eventg

ˆ E trace:fthe attributes ofthe trace event produced by the actionr:a, new extracted actualtrace eventg

E xam ple 2.1: the F ibonacci Function

Idealized (biologically unrealistic) rabbit population.

T he O S < S;If;RO;A ;E ;T;S0 >, describes the determ inistic transition functionTl.

S:N+ (positive integers list),stis the com plete evolution ofthe population from m om ent 0 untilm om entt+ 1:st= [popu0;:::;poput;poput+ 1]

RO:fm gg(m onthly grow ing)

A:N+,atis the population at m om entt+ 1 (popu(t+ 1)).

E:E(m g;s)= plast(s)+ last(s). T here is one rule only to describeE. Tl: T(m g;s) = s o[plast(s) + last(s)] (respectively before last and last elem ents ofthe list ss,odenote lists concatenation). T he new virtualstatetis the previous state to w hich the sum ofthe tw o last elem ents is appended.

S0:s0= [1;1].

A T ype:m g A C ond:ftrueg

V SE ect:fv plast(s)+ last(s)^ s0 s o[v]g E trace:fvg

T races:

T5v=< [1;1];[(1;m g;[1;1;2]);(2;m g;[1;1;2;3]);:::;

(4;m g;[1;1;2;3;5;8]);(5;m g;[1;1;2;3;5;8;13])]>

T5w =< [1;1];[(1;2);(2;3);(3;5);(4;8);(5;13)]>

2.4.2 Sim ple F luent C alculus

T he Fluent C alculus (FC ) is a logic-based representation language for know l- edge about actions,change,and causality [54]. A s an extension ofthe classical Situation C alculus [43], Fluent C alculus provides a generalfram ew ork for the developm ent ofaxiom atic sem antics for dynam ic dom ains.

T he sim ple uent calculus (SFC ) has the follow ing appealing qualities:

- Sim pli cation ofthe description,since the notions ofvirtualstate and actual trace are \naturally" em bedded in the uent calculus (the situation corre- sponding to a state can be view ed as a representation ofthe actualtrace).

- R easoning on transitions m ay be sim pler,as it supports handling partialvir- tualstates (w ith appropriate axiom atisation). Form alproofs becom e sim pler in the SFC (less deductions,at least for \direct closed" e ects,see [54,51]).

It follow s that properties like \faithfulness" [16] should be easier to prove form ally. T he Sym m etry of\state axiom s" allow s forw ard and backw ard rea- soning. W ith the sim plicity ofthe representation ofstate changes,this should m ake such proofs sim pler.

(19)

- T he description in SFC m akes such speci cation potentially executable in Flux. T here is som e lim its to the executability,related to the partialaxiom a- tisation oftheobservationalsem anticsand executability ofform alspeci cation in general. H ow ever such fram ew ork m ay facilitate som e sim ulations.

T he Fluent C alculus is a sorted logic language w ith four standard sorts:

FLU E N T , STAT E ,A C T IO N , and SIT (w hich stands for situation). A uent describesa single state property thatm ay change by the m eansofthe actionsof som e agent. A state is a collection of uents. A dopted from Situation C alculus, the standard sort SIT describes sequences ofactions.

T he pre-de ned constant;:ST A T E standsfor the em pty state. E ach term of sort FLU E N T is also an (atom ic) STAT E ,and the function :ST A T E ST A T E 7! ST A T E, w ritten in in x notation, represents the com position of tw o states. T he follow ing abbreviationH olds(f;z)isused to expressthat uent fholds in statez:

H olds(f;z)=def(9z0)f z0= z (1) T he behavior of function \ " is governed by the foundational axiom s of Fluent C alculus,w hich essentially characterize states as sets of uents.

(z1 z2) z3= z1 (z2 z3) (2)

z1 z2= z2 z1 (3)

z z= z (4)

z1 ;= z (5)

H olds(f;f1 z) f1_H olds(f;z) (6) States can be updated by adding and/or rem oving one or m ore uents.

A ddition of a sub-statez to a statez1 is sim ply expressed asz2 = z1 z, and rem ovalis de ned by

z2= z1 z=def (H olds(f;z2) H olds(f;z1)^ :H olds(f;z)) (7) T he standard predicateP oss:A C T IO N ST A T E in Fluent C alculus is used to axiom atize the conditions under w hich an action is possible in a state, i.e.,the situations in w hich thepre-conditionofthis actions is satis ed.

T he pre-de ned constantS0 :SIT is the initial(i.e., before the execution ofany action) situation. T he functionD o:A C T IO N SIT 7! SIT denotes the addition ofan action to a situation. T he standard functionState:SIT 7! ST A T E is used to denote the state, i.e., the uents that hold in a situation, after a sequence of actions. T his allow s to extend m acro H olds and predicate P ossto SIT U AT IO N argum ents as follow s.

H olds(f;s)=def H olds(f;State(s)) (8) P oss(a;s)=def P oss(a;State(s)) (9)

(20)

In a Fluent C alculus A xiom atization,beyond the de nition of the dom ain sorts,functions and predicates,w e can de ne a set ofaxiom s that m ust follow three pre-de ned axiom schem as: the precondition axiom s, the state update axiom s and the state constraint axiom s.

D e nition 4 (P ure State Form ula)A Pure State Form ula is a FirstO rder form ula (z)

ˆ T here is only one free state variablez

ˆ It is com posed ofatom ic form ulas in the form : H olds( ;z),where is ofthe sort FLU EN T

atom s which do not use any reserved predicate ofFluent C alculus

D e nition 5 (P recondition A xiom ) A precondition axiom follows the schem a:

P oss(A(~x);z) (~x;z),where (~x;z)is a Pure State Form ula.

T his kind of axiom states that the execution of the actionA w ith the pa- ram eters~xis possible in the statezifand only if A(~x;z) is true.

D e nition 6 (State U pdate A xiom ) A state update axiom follows the schem a:

P oss(A(~x);State(s))^ (~x;State(s)) (State(D o(A(~x);s));State(s)) where

(State(D o(A(~x);s));State(s))= State(D o(A(~x);s))= State(s) #+ # where

#+ and# are partialstates.

2.4.3 O bservational Sem antics in Sim ple F luent C alculus

A virtualstate ofthe observed process corresponds to a state in SFC described by a set of uents (this correspondence m ust be explicitly speci ed).

E ach type of action in the O S is an action nam e in the SFC .A particular action is denotedR in the follow ing.

A ctual states are elem ents of the C artesian product of attribute dom ains (this dom ain m ust be explicitly speci ed).

Transition and extraction function (or relation) are described using both fundam entalfollow ing schem es (fundam entalaxiom s ofthe Fluent calculus)

1.Pre-C ondition A xiom s: P oss(R ;~x;z) (~x;z) 2.State U pdate A xiom s:

P oss(R ;~x;State(s))^ (~x:~y;State(s))

R(State(D o(R ;w(~x:~y;State(s));s));State(s))

w herew(~x:~y;State(s)) is an actualtrace event associated w ith the tran- sition,and derived from the current state (using localvariables too).

(21)

T hereareasm any pre-conditionsand stateupdate axiom sasthereareaction typesR in the O S. R m ay be a disjunction. It de nes the new virtualstate and the corresponding extracted actualtrace event attributesw(~x:~y;State(s)).

N ota: a situationscontains the sequence ofactions in the O S executed to reach the current virtualstatez= State(s),and also the sequence ofextracted actualtrace events such thatTw = E(Tv).

A n actualtraceTw isthe sequence ofwi,w ith chrono,found in the situation s= D o(Rn;~xn;wn;D o(Rn 1;~xn 1;wn 1;:::;S0):::)

It m ay be com puted according to the follow ing axiom s:

E xtraction(0;S)= S

E xtraction(n+ 1;D o(R ;~x;w ;s))= ((n+ 1):w):E xtraction(n;s) E xam ple 2.2: O S for F ibonacci

T he virtual state contains only one uentF ib=1 of type L ist(Int) >

F luent, and there is only one type of action M g. T he actual state contains just 2 attributes,respectively oftypeStringandInt. A vector is represented by a sequence (P rolog list syntax).

S0= F ib([1;1])

P oss(M g;[l;pl];z) H olds(F ib([l;pljx]);z) P oss(M g;[l;pl];State(s))^v= l+ pl

State(D o(M g;[M g;v];s))= State(s) F ib([v;l;pljx]) F ib([l;pljx])

2.5 T race Q uery and A nalysis T ools

Trace query and analysis tools are considered here as separate com ponents, as illustrated in the Figure6. A lthough they are part of the C H R O M E -R E F project, they are not studied m ore deeply here. Instead, w e propose a rst repesentation ofthe actualC H R trace using X M L.T he X M L schem a is given in the A ppendixB, and an exam ple of produced trace in the X M L form at in the A ppendixC.

(22)

3 T racing R ule-B ased C onstraint P rogram m ing

C onstraintH andling R ulesem ergesin the contextofC onstraintLogic P rogram - m ing (C LP )asa language fordescribing C onstraintSolvers. In C LP,a problem is stated as a set of constraints,a set of predicates and a set of logicalrules.

P roblem s in C LP are generally solved by the interaction ofa logicalinference engine and constraint solving com ponents. T he logicalrules (w ritten in a host language) are interpreted by the logical inference engine and the constraint solving tasks are delegated to the constraint solvers.

3.1 C H R by E xam ple

T he follow ing rule base handles the less-than-or-equalproblem :

reflexivity r1@ leq(X,Y)<=> X=Y j tru e. antisymmetry r2@ leq(X,Y) , leq(Y,X)<=> X=Y. idempotence r3@ leq(X,Y) n leq(X,Y)<=> tru e. transitivity r4@ leq(X,Y) , leq(Y,Z)<=> leq(X,Z) .

T his C H R program speci es how leqsim pli es and propagates as a con- straint. T he rules im plem ent re exivity,antisym m etry,idem potence and tran- sitivity in a straightforw ard w ay. C H R reflexivitystatesthatleq(X ;Y)sim pli- es totrue,provided it is the case thatX = Y. T his test form s the (optional) guard ofa rule,a precondition on the applicability ofthe rule. H ence,w henever w e see a constraint ofthe form leq(X ;X) w e can sim plify it to true.

T he ruleantisym m etrym eans that ifw e ndleq(X ;Y) as w ellasleq(Y;X) in the constraint store, w e can replace it by the logically equivalentX = Y. N ote the di erent use ofX = Y in the tw o rules: in thereflexivityrule the equality isa precondition (test)on the rule,w hile in theantisym m etryrule itis enforced w hen the rule res. (T he re exivity rule could also have been w ritten asreflexivity@leq(X ;X)<=> true:)

T he rulesreflexivityand antisym m etryaresim pli cation C H R. In such rules, the constraint found are rem oved w hen the rule applies and res. T he ruleidem potenceis asim pagation C H R,only the constraintin the rightpartof the head w illbe rem oved. T he rule says that ifw e ndleq(X ;Y) and another leq(X ;Y) in the constraint store,w e can rem ove one.

Finally,the ruletransitivitystatesthatthe conjunctionleq(X ;Y);leq(Y;Z) im pliesleq(X ;Z). O perationally,w e addleq(X ;Z) as (redundant) constraint.

w ithout rem oving the constraintsleq(X ;Y);leq(Y;Z). T his kind of C H R is calledpropagation C H R.

T he C H R rules are interpreted by a C H R inference engine by rew riting the initialset ofconstraints by the iterative application ofthe rules. Its extension w ith disjunctive bodies,C H R_ boosts its expressiveness pow er,turning it into a generalprogram m ing language (w ith no need ofan host language).

3.2 O bservational Sem antics of C H R

T he observational sem antics of a tracer is based on a sim pli ed abstract se- m antics of the observed process. In the case of C H R_, w e suggest to use an

(23)

adaptation ofthe re ned theoreticalsem antics ofC H R as presented in [17]. To start w ith,w e show how to build an observationalsem antics for C H R based on the theoreticaloperationalsem antics!t[22]. T he description of!tin SFC is borrow ed from [9].

3.2.1 T heoretical O perational Sem antics!tof C H R

W e de neC T asthe constrainttheory w hich de nesthe sem antic ofthe built-in constraints and thus m odels the internalsolver w hich is in charge ofhandling them . W e assum e it supports at least the equality built-in. W e use [HjT]to indicate the rst (H) and the rem aining (T) term s in a list,+ + for sequence concatenation and []for em pty sequences.

W e use the notationa0;:::;an for both bags and sets. B ags are sets w hich allow repeats. W e use[ for set union and] for bag union,andfgto represent both the em pty bag and the em pty set. T he identi ed constraints have the form c#i, w here c is a user-de ned constraint and ia naturalnum ber. T hey di erentiate am ong copies ofthe sam e constraint in a bag. W e also assum e the functionschr(c#i)= candid(c#i)= i.

A n execution state is a tuplehQ ;U ;B ;Pin,w hereQ is the G oal,a bag of constraints to be executed;U is the U D C S (U ser D e ned C onstraint Store),a bag of identi ed user de ned constraints;B is the B IC S (B uilt-In C onstraint Store), a conjunction of constraints;P is the P ropagation H istory, a set of sequences, each recording the identities of the user-de ned constraints w hich

red a rule;nis the next free naturalused to num ber an identi ed constraint.

T he initialstate is represented by the tuplehQ ;[];true;[]in. T he transitions are applied non-determ inistically untilno transition is applicable or the current built-in constraintstore isinconsistent. T hese transitionsare de ned asfollow s:

Solve hfcg ]Q ;U ;B ;Pin 7! hQ ;U ;c^B ;Pin w herecis built-in

Introducehfcg]Q ;U ;B ;Pin 7! hQ ;fc#ng]U ;B ;Pin+ 1

w herecis user-de ned constraint

A pplyhQ ;H1]H2]U ;B ;Pin 7! hC]Q ;H1]U ;e^B ;P0in w here existsa ruler@H10nH20, gbC and a m atching sub- stitution e,such thatchr(H1) = e(H10);chr(H2) = e(H20) and C T j= B 9(e^ g); and the sequenceid(H1) + +id(H2)+ +id[r]62P;andP0= P [id(H1)+ +id(H2)+

+ [r]

E xam ple 3.1T he follow ing is a (term inating) derivation under!tfor the queryleq(A ;B);leq(B ;C);leq(C ;A) executed on the leq program in E xam ple 3.1. For brevity,P have been rem oved from each tuple.

(24)

hfleq(A ;B);leq(B ;C);leq(C ;A)g;;;;i1 (1) 7

!in troducehfleq(B ;C);leq(C ;A)g;fleq(A ;B)# 1g;;i2 (2) 7

!in troducehfleq(C ;A)g;fleq(A ;B)# 1;leq(B ;C)# 2g;;i3 (3) (transitivity r4X =A^Y=

B^Z=C)

7

!apply hfleq(C ;A);leq(A ;C)g;fleq(A ;B)# 1;leq(B ;C)# 2g;;i3 (4)

7

!in troducehfleq(C ;A)g;fleq(A ;B)# 1;leq(B ;C)# 2;leq(A ;C)# 3g;;i4 (5) 7

!in troduceh;;fleq(A ;B)# 1;leq(B ;C)# 2;leq(A ;C)# 3;leq(C ;A)# 4g;;i5 (6) (antisym m etry r2X = C^

Y=A)

7

!apply h;;fleq(A ;B)# 1;leq(B ;C)# 2g;fA=Cgi5 (7)

(antisym m etry r2X = C^ Y=A)

7

!apply h;;;;fA=C ;C=Bgi5 (8)

N o m ore transition rules are possible,so this is the nalstate.

3.2.2 T heoretical O perational Sem antics!tof C H R in SF C

T he follow ing is the description of the theoreticaloperationalsem antics!tin term s ofthe sorts,relations,functions and axiom s ofthe sim ple uent calculus.

(a) D om ain Sorts

-N A T U R A L,naturalnum bers;

-R U L E,the sort ofC H R rules andR U L E ID the sort ofthe rule identi- ers;

-C O N ST R A IN T, the sort of constraints, w ith the follow ing subsorts:

B IC (the built-in constraints),w ith the subsortE Q (constraints in the form x= y),andU D C (the user-de ned constraints),w ith the follow ing subsort:ID E N T IF IE D (constraints in the form c#i). In short:

E Q < B IC < C O N ST R A IN T and

ID E N T IF IE D < U D C < C O N ST R A IN T;

-P R O P H IST O R Y = Seq(N A T U R A L) R U L E, the elem ents of the P ropagation H istory,tuples ofa sequence ofnaturalnum bers and a rule;

Foreach de ned sortX,threenew sorts:Seq(X),Set(X)andB ag(X) containing the sequences,the sets and the bags ofelem ents ofX. W e use []for the em pty sequence andfgfor the em pty set and the em pty bag.

-C H R A C T IO N < A C T IO N, the subsort ofA C T IO N containing only the actions in the C H R sem antics.

(b) P redicates

-Q uery:B ag(C O N ST R A IN T),Q uery(q) holds i qis the initialquery;

-C onsistent:ST A T E,holds i theB IC S ofthe state is consistent (i.e., ifit does not entailfalse).

-M atch(hk;hR;u1;u2;e;z) holds i (i)u1 andu2 are in theU D C S ofz and (ii) the set ofm atching equations e is such thatchr(u1)= e(hk) and chr(u2)= e(hR);

-E ntails :Set(B IC) Set(E Q) B ag(B IC),E ntails(b;e;g) holds if C T j= b! 9(e^g).

(25)

(c) Functions

- # :U D C N A T U R A L 7! ID E N T IF IE D,de nes the syntactic sugar for de ning identi ed constraints in the form c#i;

-m akeR ule:

R U L E ID B ag(U D C) B ag(U D C) B ag(B IC) B ag(U D C) 7! R U L E,

m akesa rule from its com ponents. W e de ne the syntactic sugarfor rules asrid@hknhR $ gjb= m akeR ule(rid;hk;hR;g;b);

-B ics:ST A T E 7! Set(B IC),w hereB ics(z)= fcjH olds(InB ics(c);z)g; -id:Set(U D C)7! Set(N A T U R A L),w hereid(H)= ijc#i2H

- T he usual set, sequence and bag operations: 2 for elem ent,[ for set union,] for bag union, + + for sequence concatenation,jfor sequence head and tail(E x: [headjtail]) andnfor set subtraction.

(d) Fluents

-G oal:B ag(U D C)7! F L U E N T,G oal(q) holds i qis the current goal;

-U dcs:B ag(ID E N T IF IE D)7! F L U E N T,U dcs(u) holds i u is the current U D C S;

-InB ics:B IC 7! F L U E N T,InB ics(c)holds i cis in the currentB IC S;

-InP ropH istory:P R O P H IST O R Y 7! F L U E N T,InP ropH istory(p) holds i pis in the current P ropagation H istory;

-N extId:N A T U R A L 7! F L U E N T,N extId(n) holds i n is the next naturalnum ber to be used to identify a identi ed constraint.

(e) A ctions

-Solve :B IC 7! C H R A C T IO N,D o(Solve(c);s) executes theSolve transition w ith the built-in constraintc;

-Introduce:U D C 7! C H R A C T IO N,D o(Introduce(c);s) executes the Introduce transition w ith the user-de ned constraintc;

-A pply:R U L E B ag(U D C) B ag(U D C)7! C H R A C T IO N ,

D o(A pply(r;u1;u2);s) executes the A pply transition m atching the con- straintsu1 and u2 in theU D C S w ith the kept and rem oved heads of r.

(f) A xiom s

-Q uery(q)! State(S0)= G oal(q) U dcs(fg) N extId(1),

T he InitialState A xiom states that in the initialstate,the goalcontains the constraints in the query, the user de ned constraint store is em pty and the next ID for identi ed constraints is 1;

Solve

-P oss(Solve(c);z) (9q)(H olds(G oal(q);z)^c2q)

T he Solve P recondition A xiom states that the only precondition for the Solveaction on the built-in constraintcis that this constraint should be in the goal.

(26)

-P oss(Solve(c);s)^H olds(G oal(q] fcg);State(s))

State(D o(Solve(c);s))= State(s) G oal(q) InB ics(c) G oal(q] fcg)

T he Solve State U pdate A xiom states that the result oftheSolveaction over the constraintcis that this constraint is rem oved from goal and added toInB icslist in current state;

Introduce

-P oss(Introduce(c);z) (9q)(H olds(G oal(q);z)^c2q) -P oss(Introduce(c);s)^H olds(G oal(q]c);State(s))^

H olds(U dcs(u);State(s))^H olds(N extId(n);State(s))

State(D o(Introduce(c);s)) = State(s) G oal(q) U dcs(u]c#n) N extId(n+ 1)

G oal(q] fcg) U dcs(u) N extId(n) Apply

-P oss(A pply(r@hknhR $ gjd;u1;u2);z) (9e)(9b)(M atch(hk;hR;u1;u2;e;z)^

:H olds(InP ropH istory(id(u1);id(u2);r);z)^B ics(b;z)^E ntails(b;e;g)) -P oss(A pply(r@hknhR $ gjd;u1;u2);State(s))^

H olds(U dcs(u1]u2]u);State(s))^H olds(G oal(q);State(s))^ M atch(hk;hR;u1;u2;e;z)

State(D o(A pply(r@hknhR $ gjd;u1;u2);s))= State(s) G oal(d]q) U dcs(u1]u) InB ics(e) InB ics(g) InInP ropH istory(id(1u);id(u2);r)

G oal(q) U dcs(u1]u2]u)

3.2.3 O bservational Sem antics of C H R based on !t

T he follow ing is the description of the observationalsem antics of C H R using the sim ple uent calculus w ith m odi ed axiom s of the Section 2.4.3. Sorts, P redicates,Functions and Fluents are the sam e asin the previoussection;there is on additionalitem for the attributes.

T he actions are now constants and w e m ake explicit 4 actions:

Init;Solve;Introduce;F ail. (e) A ctions

-Init:7! C H R A C T IO N,D o(Init;[goal(q)ja];s) executes the top-levelini- tial transition (starting the resolution) w ith som e queryqin the current state (astands for other attributes list in the associated trace event);

-Solve:7! C H R A C T IO N,D o(Solve;[bic(c)ja];s) executes theSolvetran- sition w ith the built-in constraintc;

-Introduce :7! C H R A C T IO N,D o(Introduce;[udc(c)ja];s) executes the Introduce transition w ith the user-de ned constraintc;

-A pply:7! C H R A C T IO N,

D o(A pply;[rule(r)jt];s) executes the A pply transition w ith rulerm atching the constraints in theU D C S w ith the kept and rem oved heads;

(27)

-F ail:7! C H R A C T IO N,D o(F ail;[goal(q)ja];s) ifnoA pplyis possible.

T here are also 5 attributes in the actualtrace:goal;udc;bic;hind;rule. (f) A ttributes

-goal:C O N ST R A IN T S7! A T T R IB U T E,is the set ofconstraints in the current G oal;

-udc:C O N ST R A IN T S 7! A T T R IB U T E,is the set ofconstraints in the current U ser D e ned C onstraints Store;

-bic:C O N ST R A IN T S 7! A T T R IB U T E,is the set of constraints in the current B uilt-In C onstraints Store ;

-hind:7! IN T E G E R,isthe new propagation history index (increm ented by Introduce);

-rule:R U L E 7! A T T R IB U T E,is the rule applied to reach this state.

Apply

W e just com m ent the adaptation of one rule, the full description is in A p- pendixA.

(g) A xiom s ofthe O bservationalSem antics -P oss(A pply;[r;hk;hR;g;u1;u2];z)

(9e)(9b)(M atch(hk;hR;u1;u2;e;z)^

:H olds(InP ropH istory(id(u1);id(u2);r);z)^B ics(b;z)^ E ntails(b;e;g))

-P oss(A pply;[r;hk;hR;g;u1;u2];State(s))^

H olds(U dcs(u1]u2]u);State(s))^H olds(G oal(q);State(s))^ M atch(hk;hR;u1;u2;e;z)

State(D o(A pply;

[apply,rule(r@hknhR $ gjd;u1;u2);goal(d]q);udc(u1]u);bic(g)];s))=

State(s) G oal(d]q) U dcs(u1]u) InB ics(e) InB ics(g) InP ropH istory(id(u1);id(u2);r)

G oal(q) U dcs(u1]u2]u)

T he observationalsem antics of C H R_ can be form alized sim ilarly w ith 11 actions (hence 11 di erent kinds oftrace events),

initState;solve;activate;reactivate;drop;sim plify;propagate;derive;

clean;split;fail,

using the re ned operationalsem antics!r_,according to [17,9].

(28)

3.3 T ow ards Full G eneric T race of C H R

_

A s suggested in the Section 2.3.2, a full trace w ill be progressively obtained by com posing severallayers oftraces and severalpotentialapplications in such a w ay that as m any as possible of potential uses can be satis ed by such a trace. T he Figure5suggests 4 levels of re nem ents corresponding to 4 layers ofim plem entations,i.e. from bottom to top: environm ent of execution (W in- dow s/Linux/M ac...),im plem entation language (m ost ofC H R are im plem ented in P rolog),C H R ,and application w ritten in C H R . T here m ay be other low er levels, like W A M abstract m achine im plem ented in Java for the P rolog level, etc... E ven ifeach layer has its ow n levelofabstraction and m ost ofthe C H R users don’t care about low er softw are layers,it m ay be interesting to keep som e trace ofthem in the \full" trace.

If w e consider the point of view of debugging som e application w ritten in C H R ,here are som e inform ation w hich could be usefully found in a trace used by a debugging tool.

ˆ E xecution environm ent: activation of system com m ands during interac- tions

ˆ Im plem entation languages (there m ay be several layers): speci c local error m essages,activated layer,...

ˆ C H R :nam e ofused rules

W e m ean here that,at som e point,it m ay be usefulto nd in the trace of the application som e inform ation regarding di erent layers of im plem entation in order a debugging toolto be able to \understand" som e bugs.

Let us consider an exam ple of application. In the A nnexD w e give the observationalsem anticsin SFC ofa sim ple application of[53]. T hisO S speci es possible traces ofactions perform ed by robots (here there is only one). W e m ay assum e that this sm allw orld is program m ed in C H R and therefore the trace of the w hole system is a kind ofcom bination ofboth traces: the one ofthe robot and the trace corresponding to the C H R program execution. T he resulting fulltrace corresponds to the trace com position described in the Section 2.3.2 (com prehensively treated in [15]).

If one w ants just to follow w hat the robots are doing, then the sub-trace consisting ofthetraceeventsregarding therobot’sactionsissu ciently relevant.

B ut,atleastatthe stage ofdebugging,som e dysfunction observed in the robot’s trace (for exam ple crossing a closed door)can be understood only by looking at a m orecom plete tracew hich includeseventsrelated to the C H R layerbehaviour.

Finally there is one m ore level, w hich corresponds to the speci city and versatility ofC H R :the m any extensions and applications w hich are em bedded in C H R w ith C H R as im plem entation language, quoted as the \C H R w orld"

in the introduction. H ere are som e of them [22]: B oolean algebra for circuit analysis,resolution oflinear polinom ialequations -C LP (R)4-w ith application in nances and non linear equations, nite dom ain solvers - C LP (FD ) - w ith applicationsin puzzles,scheduling and optim isation,butm any othersasquoted at the beginning ofthe report.

4C LP stands for C onstraint Logic P rogram m ing.

(29)

A fullC H R_ trace should probably include traces related to severalexten- sions like C LR (X) w hereX stands for som e constraint dom ain,and C H RV;n af forexam ple. T hisispossible,butthere isstilla need to specify an observational sem antics for severalofthese extensions.

(30)

4 T ow ards C H R O M E -R E F

T his section details the architecture of C H R O M E -R E F,the extensible im ple- m entation ofa generic tracerforC onstraintSolving and R ule-B ased R easoning.

E ach com ponentofthe C H R O M E -R E F isdescribed in term sofU M L2.1 accord- ing the K obrA 2 m ethodology [4,5]. W e rstgive a briefoverview ofC H R O M E .

4.1 C H R O M E

C H R O M E stands forC onstraint H andling R ule O nline M odel-driven E ngine,isa m odel-driven,com ponent-based,scalable,online,Java-hosted C H R_ engine to lay at the bottom ofthe fram ew ork as the m ost w idely reused auto- m ated reasoning com ponent. T he idea ofC H R O M E is also to dem onstrate how a standard set of languages and processes prescribed by M D A can be used to design concrete artefacts,such as: a versatile inference engine forC H R_ and its com piler com ponent that generates from a C H R_ base the source code ofJava classes.

4.1.1 G oals and D esign P rinciples

T he m ain goalofC H R O M E ifto take C H R enginesa step beyond,by designing a new C H R_ engine and a corresponding com piler using a com ponent-based m odel-driven approach. C H R O M E is a C H R_ engine w ith an e cient and com plete search algorithm (e.g. the con ict-directed backjum ping algorithm ), the rst versatile rule-based engine,integrating production rules,rew rite rules, itsbuilt-in beliefrevision m echanism (reused forhandling disjunctions)and C LP rules to run on top of a m ainstream O bject O riented (O O ) platform (Java).

B ecause it is a rule-based engine follow ing a com ponent-based m odel-driven approach,it allow seasy portto other O O platform s such asP ython,JSP,C + + and others. Finally the com piler is the rst that uses a m odeltransform ation pipeline to transform from a source relational-declarative language into a O O im perative paradigm language.

T he C H R O M E architecture is divided into tw o m ain sub-com ponents (see the Figure9):

i) T he AT L-pipeline com piler(C H R C om pilercom ponent)thattakesasinput a relational declarative C H R_ base and produces an e cient constraint handling im perative object-oriented com ponent assem bly.

ii) T he C H R O M E run-tim e engine (show n in the Figure9as the Q ueryP ro- cessorcom ponent) thatprovidesthe servicesand data structuresnecessary to execute a C H R_ base given a particularquery (collection ofconstraints).

T he Figure10 show s the com plete M O F m etam odel of C H R_. A t this abstract syntax levelallC H R_ rules are generalized as sim pagation rules. T he m eta-associations keep and del from the C H R_ m eta-class to the C onstraint m eta-class respectively represent the propagated and sim pli ed heads of the rule. T he heads m ust be instances of R D C s (R ule D e ned C onstraints). A guard ofa rule m ust be a collection ofB IC s (B uiltIn C onstraints). B oth R D C s and B IC s are specializations ofC onstraint m eta-class.

(31)

Figure 9: C H R O M E

Figure 10: M eta-m odelofC H R_ and C H R data structures.

Références

Outline

Documents relatifs

Par exemple, la marque d’une automobile peut être vue comme un attribut du type-entité Véhicule de la base de données d’une préfecture mais aussi comme un type-entité

Intuitively, the local transition label (r, n) denotes the fact that a rule r is applied along an embedding that matches the agent with identifier n in the left hand side of the rule

For instance, high-resolution observations or high-resolution models can be used to tune a statistical model for unresolved scales; a model of the atmospheric boundary layer can be

• Interact with DC devices to communicate personal data with their DS policies (implementation of the collect op- eration) or to reject collection requests from DC devices when

Given a plant P , the aim of the synthesis of a controller is to find a process C called a controller which, when supervising P forces it to satisfy a control objective, given that

Observer les interactions familiales en considérant l' ensemble des membres de la famille permet d'aller chercher davantage d ' information que l'observation des dyades à

On this basis, each evaluation team eventually formulated a handful of sense- making (from the view point of the stakeholders) realistic impacts and related

Ainsi dans cette thèse notre objectif est la conception d’une visualisation interactive permettant aux utilisateurs de trouver des modifications dans l’utilisation de leurs