SlideServe
Menu
Préférences
© SlideServe · v2026

Action Rules for Programming Constraint Propagators and Interactive User Interfaces

fjudd avatar
27 diapositives · 319 Views · Jan 04, 2020

Learn about action rules for programming reactive systems, constraint propagators, interactive user interfaces, and more. Discover how to handle events, concurrency, and agent actions effectively. Explore examples and techniques for efficient constraint propagation.

Action Rules for Programming Constraint Propagators and Interactive User Interfaces - slide 1
01 / 27Action Rules for Programming Constraint Propagators and Interactive User Interfaces
1 / 17

Télécharger la présentation

Action Rules for Programming Constraint Propagators and Interactive User Interfaces
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Action Rulesfor Programming Constraint Propagators and Interactive User Interfaces Neng-Fa Zhou CUNY Brooklyn College & GC zhou@sci.brooklyn.cuny.edu www.sci.brooklyn.cuny.edu/~zhou

  2. Outline of Talk • Motivation • Action Rules • Programming Constraint Propagators(www.sci.brooklyn.cuny.edu/~zhou/papers/arule.ps) • CGLIB: Constraint-based Graphics Library(www.sci.brooklyn.cuny.edu/~zhou/papers/acmdoc01.pdf) • Demo of B-Prolog v.6 (www.probp.com)

  3. Motivation • The need for a language for programming reactive systems • Constraint propagators • Event handling • Concurrency • Interactive user interfaces • Agents

  4. Action Rule • Syntax Agent, ConditionSeq, {EventSet} => ActionSeq • Operational semantics • An agent (sub-goal) C will be suspended if: • C matches Agent, • ConditionSeq is met, and • EventSet is not empty • C is activated whenever an event in EventSet is posted • ActionSeq is executed when C is activated and ConditionSeq is met • C is suspended again after ActionSeq is executed • The next rule is tried if ConditionSeq fails • Cfails if ActionSeq fails

  5. Posting Eventspost(E) • event(X,O) • X – suspension variable • O – event object • Events for programming propagators • ins(X) – X is instantiated • … • Events for graphics programming • actionPerformed(O) – action performed on O • …

  6. Example 1An Echoing Agent echo_agent(X), {event(X,Message)} => write(Message),nl.

  7. Example 2freeze(X,G) freeze(X,G), var(X), {ins(X)} => true. freeze(X,G) => call(G).

  8. Programming Constraint Propagators • Action rules are expressive • Propagators for maintaining node, interval, arc consistency • Propagators for global constraints • Action rules are efficient • B-Prolog is competitive with Ilog solver and GNU-Prolog

  9. Constraint Propagation X = Y+1 (X,Y in 1..5) Algorithm Change Propagation Node consistency X=3 X = 3, Y = 2 Interval consistency generated X in 2..5, Y in 1..4 5 notin X X in 2..4, Y in 1..3 Arc consistency 4 notin X X in [2,3,5], Y in [1,2,4]

  10. Events for Programming Propagators • ins(X) • X is instantiated • minmax(X) • The bound of X is updated • dom(X,E) • An inner element E has been excluded from X

  11. Propagators for aX=bY+c • Forward checking 'aX=bY+c_forward'(A,X,B,Y,C),var(X),var(Y), {ins(X),ins(Y)} => true. 'aX=bY+c_forward'(A,X,B,Y,C),var(X) => T is B*Y+C,Ex is T//A, (A*Ex=:=T->X = Ex; true). 'aX=bY+c_forward'(A,X,B,Y,C) => T is A*X-C, Ey is T//B, (B*Ey=:=T->Y is Ey;true). When either X or Y is instantiated, instantiate the other variable.

  12. Propagators for aX=bY+c • Interval consistency 'aX in bY+c_interval'(A,X,B,Y,C),var(X),var(Y), {minmax(Y)} => 'aX in bY+c_reduce_domain'(A,X,B,Y,C). 'aX in bY+c_interval'(A,X,B,Y,C) => true. Whenever the bound of Y’s domain is updated, reduce X’s domain to achieve interval consistency.

  13. Propagators for aX=bY+c • Arc consistency 'aX in bY+c_arc'(A,X,B,Y,C),var(X),var(Y), {dom(Y,Ey)} => T is B*Ey+C, Ex is T//A, (A*Ex=:=T -> exclude(X,Ex);true). 'aX in bY+c_arc'(A,X,B,Y,C) => true. When an element Ey is excluded from Y’s domain, exclude Ey’s counterpart Ex from X’s domain.

  14. Propagator for A1*X1+...+An*Xn+C = 0 'A1*X1+...+An*Xn+C=0'(C,A1,A2,...,An,X1,X2,..,Xn), n_vars_gt(n,2), {ins(X1),minmax(X1),...,ins(Xn),minmax(Xn)} => reduce domains of X1,..,Xn to achieve ic. 'A1*X1+...+An*Xn+C=0'(C,A1,A2,...,An,X1,X2,..,Xn) => nary_to_binary(NewC,B1,B2,Y1,Y2), call_binary_propagator(NewC,B1,Y1,B2,Y2). When the constraint has more than 2 variables, achieve interval consistency. When the constraint is binary archive arc consistency.

  15. Performance Evaluation Fast B-Prolog Ilog GNU-Prolog 1 2 CHIP Eclipse Sicstus Mozart Oz 4 Slow

  16. CGLIB --A Constraint-based Graphics Library • Features • Use constraints to specify the layouts of objects • Use action rules to specify interactions • Implementation • Implemented in B-Prolog, Java, and C • Applications • Drawing editors, interactive user interfaces, document authoring, animation, information visualization, intelligent agents, and games.

  17. An Illustrative Example go:- cgButton(B), (1) B^text #= “Hello World!”, (2) handleButtonClick(B), (3) cgShow(B). (4) handleButtonClick(B), (5) {actionPerformed(B)} (6) => (7) halt. (8)

  18. cgButton(X) Create a button X cgButton([X1,…,Xn]) Create a list of buttons Objects

  19. Base Derivative Attributes of Objects B is a button y B^window B^x B^y B^width B^height B^text B^color B^font B^rightX B^bottomY B^centerX B^centerY B^leftTopPoint B^leftBottomPoint B^rightTopPoint B^rightBottomPoint B^center x height width

  20. Constraints • Arithmetic constraints • O1^x +O1^width//2 #= O2^x • O1^centerX #= O2^x • Positioning constraints • cgLeft(O1,O2) • Same property constraints • cgSame([O1,O2],size) • cgSame([O1,O2],width,100)

  21. Constraints (Cont.) • Grid constraints cgGrid([[_, S1,_], [S2,S3,S4], [_,S5,_]]) cgGrid([[Bc,Bdiv,Bmul,Bsub], [B7,B8, B9, Badd], [B4,B5, B6, Badd], [B1,B2, B3, Beq], [B0,B0, Bdot,Beq]],1,1),

  22. Constraints (Cont.) • Table constraints cgTable([[Larc,Arc,Button,Lbutton], [Lcheckbox, Checkbox, Choice, Lchoice], [Lcircle,Circle,Image,Limage], [Llabel,Label,Line,Lline], [Llist,List,Oval,Loval], [Lrrectangle,Rrectangle,Rectangle,Lrectangle], [Lpolygon,Polygon,Square,Lsquare], [Lstar,Star,TextArea,Ltextarea], [Ltextfield,TextField,TextBox,Ltextbox], [Ltriangle,Triangle,_,_]],20,20),

  23. Constraints (Cont.) • Tree constraints T=node(C0,[node(C1,[node(C3,[] node(C4,[])]), node(C2,[node(C5,[]), node(C6,[])])]), cgTree(T,top_down,10,10,centered).

  24. Event Handling • Action rule • Examples Agent ConditionSeq {Event} => ActionSeq handleButtonClick(B),{actionPerformed(B)} => … handleMousePress(O),{mousePressed(O,E)} => E^x #= X, E^y #= Y, write(mouse_pressed_at(X,Y)),nl. handleKeyType(O),{keyTyped(O,E)} => E^char #= Char, write(Char).

  25. Other Primitives in CGLIB • Packing and showing objects • cgPack(O)& cgShow(O) • Altering and moving objects • O^attr #:= Value • cgScale(O,F)& cgResize(O,W,H) • cgMove(O,X,Y) • Animation • cgSleep(Time) • Generating Java applets • cgStartRecord(FileName) & cgStopRecord

  26. Demo of B-Prolog • B-Prolog (Version 6.0)(www.probp.com) • Graphical user interfaces • Animation • Information visualization • Constraint satisfaction problems • Games

  27. Related Work • Programming Constraint Propagators • Indexicals (GNU-Prolog & Sicstus) • Delay constructs • Attribute variables (Eclipse) • Constraint handling rules • Graphics programming • Postscript & Latex • Every detail must be specified • Java & Tcl/Tk • Layout managers are helpful for certain layouts • Constraints & Constraint programming • Sketchpad, ThinkLab, Amulet, SubArctic